Skip to content

Commit 318d6c2

Browse files
authored
Rollup merge of rust-lang#67909 - varkor:obsolete-const-print, r=davidtwco
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. This resolves an ICE in rust-lang#61936, though it hits more ICEs afterwards. I couldn't find a test case that was resolved by this that didn't hit errors later on.
2 parents c07204b + 8f94d9b commit 318d6c2

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
@@ -166,19 +166,12 @@ impl DefPathBasedNames<'tcx> {
166166
}
167167

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

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

0 commit comments

Comments
 (0)