diff options
| author | Ralf Jung <post@ralfj.de> | 2024-03-10 14:05:11 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-03-10 14:59:41 +0100 |
| commit | 7d99e80c55486780b59c3b947b20e72344a3bdb2 (patch) | |
| tree | 99519605d4e37af25e9a5ac2e1cc7b67262d036c /compiler/rustc_middle/src | |
| parent | 3521a2f2f317cb978063842485c7d1bc86ec82b6 (diff) | |
MIR printing: print the path of uneval'd const; refer to promoteds in a consistent way
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/mir/consts.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/pretty.rs | 5 |
2 files changed, 17 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 9731d86fb17..5feee3c3ba1 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -7,6 +7,7 @@ use rustc_target::abi::{HasDataLayout, Size}; use crate::mir::interpret::{alloc_range, AllocId, ConstAllocation, ErrorHandled, Scalar}; use crate::mir::{pretty_print_const_value, Promoted}; +use crate::ty::print::with_no_trimmed_paths; use crate::ty::GenericArgsRef; use crate::ty::ScalarInt; use crate::ty::{self, print::pretty_print_const, Ty, TyCtxt}; @@ -489,9 +490,18 @@ impl<'tcx> Display for Const<'tcx> { Const::Ty(c) => pretty_print_const(c, fmt, true), Const::Val(val, ty) => pretty_print_const_value(val, ty, fmt), // FIXME(valtrees): Correctly print mir constants. - Const::Unevaluated(..) => { - fmt.write_str("_")?; - Ok(()) + Const::Unevaluated(c, _ty) => { + ty::tls::with(move |tcx| { + let c = tcx.lift(c).unwrap(); + // Matches `GlobalId` printing. + let instance = + with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args)); + write!(fmt, "{instance}")?; + if let Some(promoted) = c.promoted { + write!(fmt, "::{promoted:?}")?; + } + Ok(()) + }) } } } diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 18069547a7e..090b84ff08f 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -496,7 +496,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: _ => tcx.is_closure_like(def_id), }; match (kind, body.source.promoted) { - (_, Some(i)) => write!(w, "{i:?} in ")?, + (_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts (DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?, (DefKind::Static(hir::Mutability::Not), _) => write!(w, "static ")?, (DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?, @@ -509,6 +509,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: // see notes on #41697 elsewhere write!(w, "{}", tcx.def_path_str(def_id))? } + if let Some(p) = body.source.promoted { + write!(w, "::{p:?}")?; + } if body.source.promoted.is_none() && is_function { write!(w, "(")?; |
