Skip to content

Commit 6bf34d9

Browse files
authored
Rollup merge of rust-lang#149401 - celinval:smir-109-name, r=scottmcm
Fix `name()` functions for local defs in rustc_public This change fixes the behavior of the `name()` function for `CrateDef` and `Instance` which should return absolute path of items. For local items, the crate name was missing. This resolves: rust-lang/project-stable-mir#109
2 parents 6d131ca + 98e1ff5 commit 6bf34d9

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

compiler/rustc_public/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl CrateItem {
178178
pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
179179
self.body()
180180
.ok_or_else(|| io::Error::other(format!("No body found for `{}`", self.name())))?
181-
.dump(w, &self.name())
181+
.dump(w, &self.trimmed_name())
182182
}
183183
}
184184

compiler/rustc_public/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn pretty_aggregate<W: Write>(
412412
}
413413
AggregateKind::Adt(def, var, _, _, _) => {
414414
if def.kind() == AdtKind::Enum {
415-
write!(writer, "{}::{}", def.name(), def.variant(*var).unwrap().name())?;
415+
write!(writer, "{}::{}", def.trimmed_name(), def.variant(*var).unwrap().name())?;
416416
} else {
417417
write!(writer, "{}", def.variant(*var).unwrap().name())?;
418418
}

compiler/rustc_public/src/ty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ pub struct VariantDef {
876876
}
877877

878878
impl VariantDef {
879+
/// The name of the variant, struct or union.
880+
///
881+
/// This will not include the name of the enum or qualified path.
879882
pub fn name(&self) -> Symbol {
880883
with(|cx| cx.variant_name(*self))
881884
}

0 commit comments

Comments
 (0)