Skip to content

Commit b816ec1

Browse files
committed
Print unevaluted constants as _ or as their source representation
1 parent ecee75d commit b816ec1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,19 @@ define_print_and_forward_display! {
15451545
}
15461546
if let ConstValue::Unevaluated(did, substs) = self.val {
15471547
match cx.tcx().describe_def(did) {
1548-
| Some(Def::Static(_, _))
1549-
| Some(Def::Const(_, false))
1550-
| Some(Def::AssociatedConst(_)) => p!(write("{}", cx.tcx().def_path_str(did))),
1551-
_ => p!(write("_")),
1548+
| Some(Def::Static(_))
1549+
| Some(Def::Const(_))
1550+
| Some(Def::AssociatedConst(_)) => p!(print_value_path(did, substs)),
1551+
_ => if did.is_local() {
1552+
let span = cx.tcx().def_span(did);
1553+
if let Ok(snip) = cx.tcx().sess.source_map().span_to_snippet(span) {
1554+
p!(write("{}", snip))
1555+
} else {
1556+
p!(write("_"))
1557+
}
1558+
} else {
1559+
p!(write("_"))
1560+
},
15521561
}
15531562
return Ok(cx);
15541563
}

0 commit comments

Comments
 (0)