From dde7bff5740134c98edfa38090dab1e7cbdc29a6 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 12 May 2022 20:12:35 +0200 Subject: [PATCH 1/4] Replace DefPathData::Misc by two appropriately-named variants. --- compiler/rustc_hir/src/definitions.rs | 14 ++++++++------ compiler/rustc_resolve/src/def_collector.rs | 8 ++++---- compiler/rustc_symbol_mangling/src/v0.rs | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index bce9ba12ac0c4..5c32dd372dde1 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -261,14 +261,16 @@ pub enum DefPathData { // they are treated specially by the `def_path` function. /// The crate root (marker). CrateRoot, - // Catch-all for random `DefId` things like `DUMMY_NODE_ID`. - Misc, // Different kinds of items and item-like things: /// An impl. Impl, /// An `extern` block. ForeignMod, + /// A `use` item. + Use, + /// A global asm item. + GlobalAsm, /// Something in the type namespace. TypeNs(Symbol), /// Something in the value namespace. @@ -443,9 +445,8 @@ impl DefPathData { match *self { TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name), - Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => { - None - } + Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst + | ImplTrait => None, } } @@ -459,7 +460,8 @@ impl DefPathData { CrateRoot => DefPathDataName::Anon { namespace: kw::Crate }, Impl => DefPathDataName::Anon { namespace: kw::Impl }, ForeignMod => DefPathDataName::Anon { namespace: kw::Extern }, - Misc => DefPathDataName::Anon { namespace: sym::misc }, + Use => DefPathDataName::Anon { namespace: kw::Use }, + GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm }, ClosureExpr => DefPathDataName::Anon { namespace: sym::closure }, Ctor => DefPathDataName::Anon { namespace: sym::constructor }, AnonConst => DefPathDataName::Anon { namespace: sym::constant }, diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 1e8cca6122c4c..f0861103098d2 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -109,7 +109,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { visit::walk_item(self, i); return self.visit_macro_invoc(i.id); } - ItemKind::GlobalAsm(..) => DefPathData::Misc, + ItemKind::GlobalAsm(..) => DefPathData::GlobalAsm, ItemKind::Use(..) => { return visit::walk_item(self, i); } @@ -160,11 +160,11 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { } fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) { - self.create_def(id, DefPathData::Misc, use_tree.span); + self.create_def(id, DefPathData::Use, use_tree.span); match use_tree.kind { UseTreeKind::Simple(_, id1, id2) => { - self.create_def(id1, DefPathData::Misc, use_tree.prefix.span); - self.create_def(id2, DefPathData::Misc, use_tree.prefix.span); + self.create_def(id1, DefPathData::Use, use_tree.prefix.span); + self.create_def(id2, DefPathData::Use, use_tree.prefix.span); } UseTreeKind::Glob => (), UseTreeKind::Nested(..) => {} diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index c8fdf363f053e..e1e14011e52b4 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -788,7 +788,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { // These should never show up as `path_append` arguments. DefPathData::CrateRoot - | DefPathData::Misc + | DefPathData::Use + | DefPathData::GlobalAsm | DefPathData::Impl | DefPathData::MacroNs(_) | DefPathData::LifetimeNs(_) => { From ecbda428ec4e0d2744e26268129f0ded42cbc865 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 12 May 2022 20:13:54 +0200 Subject: [PATCH 2/4] Correct comment. --- compiler/rustc_middle/src/ty/mod.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d847068b5bfb3..f4318044c00f3 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1996,6 +1996,7 @@ impl<'tcx> TyCtxt<'tcx> { .filter(|item| item.kind == AssocKind::Fn && item.defaultness.has_value()) } + /// Look up the name of a definition across crates. This does not look at HIR. fn opt_item_name(self, def_id: DefId) -> Option { if let Some(cnum) = def_id.as_crate_root() { Some(self.crate_name(cnum)) @@ -2016,16 +2017,11 @@ impl<'tcx> TyCtxt<'tcx> { /// Look up the name of a definition across crates. This does not look at HIR. /// - /// When possible, this function should be used for cross-crate lookups over - /// [`opt_item_name`] to avoid invalidating the incremental cache. If you - /// need to handle items without a name, or HIR items that will not be - /// serialized cross-crate, or if you need the span of the item, use + /// This method will ICE if the corresponding item does not have a name. In these cases, use /// [`opt_item_name`] instead. /// /// [`opt_item_name`]: Self::opt_item_name pub fn item_name(self, id: DefId) -> Symbol { - // Look at cross-crate items first to avoid invalidating the incremental cache - // unless we have to. self.opt_item_name(id).unwrap_or_else(|| { bug!("item_name: no name for {:?}", self.def_path(id)); }) From 2b2dc5c035d2ae59628b1a215f5cbed1dbfdce15 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 12 May 2022 20:29:11 +0200 Subject: [PATCH 3/4] Bless tests. --- src/test/ui/symbol-names/basic.legacy.stderr | 4 ++-- src/test/ui/symbol-names/issue-60925.legacy.stderr | 4 ++-- src/test/ui/traits/object/enforce-supertrait-projection.rs | 2 +- .../ui/traits/object/enforce-supertrait-projection.stderr | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/ui/symbol-names/basic.legacy.stderr b/src/test/ui/symbol-names/basic.legacy.stderr index e4d58d3ccdb29..3ad4ed24cf7fc 100644 --- a/src/test/ui/symbol-names/basic.legacy.stderr +++ b/src/test/ui/symbol-names/basic.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN5basic4main17h87acd86b3a6f1754E) +error: symbol-name(_ZN5basic4main17hcbad207c0eeb0b3bE) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(basic::main::h87acd86b3a6f1754) +error: demangling(basic::main::hcbad207c0eeb0b3b) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/symbol-names/issue-60925.legacy.stderr b/src/test/ui/symbol-names/issue-60925.legacy.stderr index c987ebc534302..21bf21ee71c6f 100644 --- a/src/test/ui/symbol-names/issue-60925.legacy.stderr +++ b/src/test/ui/symbol-names/issue-60925.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h8d22952c45e20d65E) +error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h2f2efcf580c9b1eeE) --> $DIR/issue-60925.rs:21:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(issue_60925::foo::Foo::foo::h8d22952c45e20d65) +error: demangling(issue_60925::foo::Foo::foo::h2f2efcf580c9b1ee) --> $DIR/issue-60925.rs:21:9 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/traits/object/enforce-supertrait-projection.rs b/src/test/ui/traits/object/enforce-supertrait-projection.rs index 0ea944ec2df55..2c9b41eea2abe 100644 --- a/src/test/ui/traits/object/enforce-supertrait-projection.rs +++ b/src/test/ui/traits/object/enforce-supertrait-projection.rs @@ -7,7 +7,7 @@ trait Trait: SuperTrait::B> {} fn transmute(x: A) -> B { foo::>(x) - //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B` + //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B` } fn foo(x: T::A) -> B diff --git a/src/test/ui/traits/object/enforce-supertrait-projection.stderr b/src/test/ui/traits/object/enforce-supertrait-projection.stderr index a3d17fabbe47f..eab42ca568a04 100644 --- a/src/test/ui/traits/object/enforce-supertrait-projection.stderr +++ b/src/test/ui/traits/object/enforce-supertrait-projection.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` +error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` --> $DIR/enforce-supertrait-projection.rs:9:5 | LL | fn transmute(x: A) -> B { From b7f050958844dbb677411bbee5bf74b0f7b6fcdf Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 12 May 2022 21:37:57 +0200 Subject: [PATCH 4/4] Bless mir-opt tests. --- src/test/mir-opt/inline/cycle.g.Inline.diff | 41 +++++++++++-- .../mir-opt/inline/cycle.main.Inline.diff | 58 +++++++++++++++++-- .../inline_cycle_generic.main.Inline.diff | 13 +---- 3 files changed, 94 insertions(+), 18 deletions(-) diff --git a/src/test/mir-opt/inline/cycle.g.Inline.diff b/src/test/mir-opt/inline/cycle.g.Inline.diff index 46f5e5e20655b..450157e64284f 100644 --- a/src/test/mir-opt/inline/cycle.g.Inline.diff +++ b/src/test/mir-opt/inline/cycle.g.Inline.diff @@ -4,22 +4,55 @@ fn g() -> () { let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:11:8: 11:8 let _1: (); // in scope 0 at $DIR/cycle.rs:12:5: 12:12 ++ let mut _2: fn() {main}; // in scope 0 at $DIR/cycle.rs:12:5: 12:12 ++ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8 ++ scope 1 (inlined f::) { // at $DIR/cycle.rs:12:5: 12:12 ++ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7 ++ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ let mut _4: &fn() {main}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ scope 2 (inlined >::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8 ++ } ++ } bb0: { StorageLive(_1); // scope 0 at $DIR/cycle.rs:12:5: 12:12 - _1 = f::(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12 - // mir::Constant - // + span: $DIR/cycle.rs:12:5: 12:6 - // + literal: Const { ty: fn(fn() {main}) {f::}, val: Value(Scalar()) } +- _1 = f::(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12 ++ StorageLive(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12 ++ _2 = main; // scope 0 at $DIR/cycle.rs:12:5: 12:12 // mir::Constant +- // + span: $DIR/cycle.rs:12:5: 12:6 +- // + literal: Const { ty: fn(fn() {main}) {f::}, val: Value(Scalar()) } +- // mir::Constant // + span: $DIR/cycle.rs:12:7: 12:11 // + literal: Const { ty: fn() {main}, val: Value(Scalar()) } ++ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ _3 = move (*_4)() -> [return: bb4, unwind: bb2]; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL } bb1: { ++ StorageDead(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12 StorageDead(_1); // scope 0 at $DIR/cycle.rs:12:12: 12:13 _0 = const (); // scope 0 at $DIR/cycle.rs:11:8: 13:2 return; // scope 0 at $DIR/cycle.rs:13:2: 13:2 ++ } ++ ++ bb2 (cleanup): { ++ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2 ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2 ++ } ++ ++ bb4: { ++ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8 ++ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9 ++ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2 } } diff --git a/src/test/mir-opt/inline/cycle.main.Inline.diff b/src/test/mir-opt/inline/cycle.main.Inline.diff index c8d1448d949d4..5e2f70799e41e 100644 --- a/src/test/mir-opt/inline/cycle.main.Inline.diff +++ b/src/test/mir-opt/inline/cycle.main.Inline.diff @@ -4,22 +4,72 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:16:11: 16:11 let _1: (); // in scope 0 at $DIR/cycle.rs:17:5: 17:9 ++ let mut _2: fn() {g}; // in scope 0 at $DIR/cycle.rs:17:5: 17:9 ++ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8 ++ scope 1 (inlined f::) { // at $DIR/cycle.rs:17:5: 17:9 ++ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7 ++ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ let mut _4: &fn() {g}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ scope 2 (inlined >::call - shim(fn() {g})) { // at $DIR/cycle.rs:6:5: 6:8 ++ scope 3 (inlined g) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL ++ let mut _6: fn() {main}; // in scope 3 at $DIR/cycle.rs:12:5: 12:12 ++ scope 4 (inlined f::) { // at $DIR/cycle.rs:12:5: 12:12 ++ debug g => _6; // in scope 4 at $DIR/cycle.rs:5:6: 5:7 ++ let _7: (); // in scope 4 at $DIR/cycle.rs:6:5: 6:8 ++ let mut _8: &fn() {main}; // in scope 4 at $DIR/cycle.rs:6:5: 6:6 ++ scope 5 (inlined >::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8 ++ } ++ } ++ } ++ } ++ } bb0: { StorageLive(_1); // scope 0 at $DIR/cycle.rs:17:5: 17:9 - _1 = f::(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9 - // mir::Constant - // + span: $DIR/cycle.rs:17:5: 17:6 - // + literal: Const { ty: fn(fn() {g}) {f::}, val: Value(Scalar()) } +- _1 = f::(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9 ++ StorageLive(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9 ++ _2 = g; // scope 0 at $DIR/cycle.rs:17:5: 17:9 // mir::Constant +- // + span: $DIR/cycle.rs:17:5: 17:6 +- // + literal: Const { ty: fn(fn() {g}) {f::}, val: Value(Scalar()) } +- // mir::Constant // + span: $DIR/cycle.rs:17:7: 17:8 // + literal: Const { ty: fn() {g}, val: Value(Scalar()) } ++ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6 ++ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ StorageLive(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12 ++ StorageLive(_7); // scope 4 at $DIR/cycle.rs:6:5: 6:8 ++ StorageLive(_8); // scope 4 at $DIR/cycle.rs:6:5: 6:6 ++ _8 = &_6; // scope 4 at $DIR/cycle.rs:6:5: 6:6 ++ _7 = move (*_8)() -> [return: bb4, unwind: bb2]; // scope 5 at $SRC_DIR/core/src/ops/function.rs:LL:COL } bb1: { ++ StorageDead(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9 StorageDead(_1); // scope 0 at $DIR/cycle.rs:17:9: 17:10 _0 = const (); // scope 0 at $DIR/cycle.rs:16:11: 18:2 return; // scope 0 at $DIR/cycle.rs:18:2: 18:2 ++ } ++ ++ bb2 (cleanup): { ++ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2 ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2 ++ } ++ ++ bb4: { ++ StorageDead(_8); // scope 4 at $DIR/cycle.rs:6:7: 6:8 ++ StorageDead(_7); // scope 4 at $DIR/cycle.rs:6:8: 6:9 ++ StorageDead(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12 ++ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8 ++ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8 ++ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9 ++ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2 } } diff --git a/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff b/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff index fddf7e6e1f0a7..267f53a8dfe7b 100644 --- a/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff +++ b/src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff @@ -4,20 +4,13 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/inline-cycle-generic.rs:8:11: 8:11 let _1: (); // in scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24 -+ scope 1 (inlined ::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24 -+ scope 2 (inlined as Call>::call) { // at $DIR/inline-cycle-generic.rs:38:9: 38:31 -+ } -+ } bb0: { StorageLive(_1); // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24 -- _1 = ::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24 -+ _1 = ::call() -> bb1; // scope 2 at $DIR/inline-cycle-generic.rs:31:9: 31:28 + _1 = ::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24 // mir::Constant -- // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22 -- // + literal: Const { ty: fn() {::call}, val: Value(Scalar()) } -+ // + span: $DIR/inline-cycle-generic.rs:31:9: 31:26 -+ // + literal: Const { ty: fn() {::call}, val: Value(Scalar()) } + // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22 + // + literal: Const { ty: fn() {::call}, val: Value(Scalar()) } } bb1: {