MIR printing: print the path of uneval'd const; refer to promoteds in a consistent way
This commit is contained in:
parent
3521a2f2f3
commit
7d99e80c55
79 changed files with 114 additions and 101 deletions
|
@ -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(())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, "(")?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue