Skip to content

Commit 8f94d9b

Browse files
committed
Fix ICE in const pretty printing and resolve FIXME
Consts now have a `fmt::Display` impl, so we can just use that to pretty-print.
1 parent 760ce94 commit 8f94d9b

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/librustc/ty/print/obsolete.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,12 @@ impl DefPathBasedNames<'tcx> {
165165
}
166166

167167
// Pushes the the name of the specified const to the provided string.
168-
// If `debug` is true, usually-unprintable consts (such as `Infer`) will be printed,
169-
// as well as the unprintable types of constants (see `push_type_name` for more details).
170-
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
171-
if let ty::ConstKind::Value(_) = c.val {
172-
// FIXME(const_generics): we could probably do a better job here.
173-
write!(output, "{:?}", c).unwrap()
174-
} else if debug {
175-
write!(output, "{:?}", c).unwrap()
176-
} else {
177-
bug!("DefPathBasedNames: trying to create const name for unexpected const: {:?}", c,);
178-
}
168+
// If `debug` is true, the unprintable types of constants will be printed with `fmt::Debug`
169+
// (see `push_type_name` for more details).
170+
pub fn push_const_name(&self, ct: &Const<'tcx>, output: &mut String, debug: bool) {
171+
write!(output, "{}", ct).unwrap();
179172
output.push_str(": ");
180-
self.push_type_name(c.ty, output, debug);
173+
self.push_type_name(ct.ty, output, debug);
181174
}
182175

183176
pub fn push_def_path(&self, def_id: DefId, output: &mut String) {

0 commit comments

Comments
 (0)