Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more precise than DefPathData::Misc. #96989

Merged
merged 4 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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 },
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol> {
if let Some(cnum) = def_id.as_crate_root() {
Some(self.crate_name(cnum))
Expand All @@ -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));
})
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(..) => {}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand Down
41 changes: 37 additions & 4 deletions src/test/mir-opt/inline/cycle.g.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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::<fn() {main}>) { // 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 <fn() {main} as Fn<()>>::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::<fn() {main}>(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::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
- _1 = f::<fn() {main}>(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::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
- // mir::Constant
// + span: $DIR/cycle.rs:12:7: 12:11
// + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) }
+ 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
}
}

58 changes: 54 additions & 4 deletions src/test/mir-opt/inline/cycle.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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::<fn() {g}>) { // 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 <fn() {g} as Fn<()>>::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::<fn() {main}>) { // 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 <fn() {main} as Fn<()>>::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::<fn() {g}>(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::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
- _1 = f::<fn() {g}>(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::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
- // mir::Constant
// + span: $DIR/cycle.rs:17:7: 17:8
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) }
+ 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
}
}

13 changes: 3 additions & 10 deletions src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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 <C as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
+ scope 2 (inlined <B<A> 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 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
+ _1 = <A as Call>::call() -> bb1; // scope 2 at $DIR/inline-cycle-generic.rs:31:9: 31:28
_1 = <C as Call>::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() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
+ // + span: $DIR/inline-cycle-generic.rs:31:9: 31:26
+ // + literal: Const { ty: fn() {<A as Call>::call}, val: Value(Scalar(<ZST>)) }
// + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
// + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
}

bb1: {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/symbol-names/basic.legacy.stderr
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/symbol-names/issue-60925.legacy.stderr
Original file line number Diff line number Diff line change
@@ -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<issue_60925::llvm::Foo>::foo::h8d22952c45e20d65)
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h2f2efcf580c9b1ee)
--> $DIR/issue-60925.rs:21:9
|
LL | #[rustc_symbol_name]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/traits/object/enforce-supertrait-projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {}

fn transmute<A, B>(x: A) -> B {
foo::<A, B, dyn Trait<A = A, B = B>>(x)
//~^ ERROR type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
//~^ ERROR type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
}

fn foo<A, B, T: ?Sized>(x: T::A) -> B
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
--> $DIR/enforce-supertrait-projection.rs:9:5
|
LL | fn transmute<A, B>(x: A) -> B {
Expand Down