Skip to content

Commit f2100da

Browse files
authored
Rollup merge of #96989 - cjgillot:defpath-use, r=davidtwco
Be more precise than DefPathData::Misc. This variant was used for two unrelated things. Let's make this cleaner.
2 parents ececa7f + b7f0509 commit f2100da

File tree

11 files changed

+116
-41
lines changed

11 files changed

+116
-41
lines changed

compiler/rustc_hir/src/definitions.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,16 @@ pub enum DefPathData {
261261
// they are treated specially by the `def_path` function.
262262
/// The crate root (marker).
263263
CrateRoot,
264-
// Catch-all for random `DefId` things like `DUMMY_NODE_ID`.
265-
Misc,
266264

267265
// Different kinds of items and item-like things:
268266
/// An impl.
269267
Impl,
270268
/// An `extern` block.
271269
ForeignMod,
270+
/// A `use` item.
271+
Use,
272+
/// A global asm item.
273+
GlobalAsm,
272274
/// Something in the type namespace.
273275
TypeNs(Symbol),
274276
/// Something in the value namespace.
@@ -443,9 +445,8 @@ impl DefPathData {
443445
match *self {
444446
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
445447

446-
Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => {
447-
None
448-
}
448+
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
449+
| ImplTrait => None,
449450
}
450451
}
451452

@@ -459,7 +460,8 @@ impl DefPathData {
459460
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
460461
Impl => DefPathDataName::Anon { namespace: kw::Impl },
461462
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
462-
Misc => DefPathDataName::Anon { namespace: sym::misc },
463+
Use => DefPathDataName::Anon { namespace: kw::Use },
464+
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
463465
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
464466
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
465467
AnonConst => DefPathDataName::Anon { namespace: sym::constant },

compiler/rustc_middle/src/ty/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@ impl<'tcx> TyCtxt<'tcx> {
19941994
.filter(|item| item.kind == AssocKind::Fn && item.defaultness.has_value())
19951995
}
19961996

1997+
/// Look up the name of a definition across crates. This does not look at HIR.
19971998
fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
19981999
if let Some(cnum) = def_id.as_crate_root() {
19992000
Some(self.crate_name(cnum))
@@ -2014,16 +2015,11 @@ impl<'tcx> TyCtxt<'tcx> {
20142015

20152016
/// Look up the name of a definition across crates. This does not look at HIR.
20162017
///
2017-
/// When possible, this function should be used for cross-crate lookups over
2018-
/// [`opt_item_name`] to avoid invalidating the incremental cache. If you
2019-
/// need to handle items without a name, or HIR items that will not be
2020-
/// serialized cross-crate, or if you need the span of the item, use
2018+
/// This method will ICE if the corresponding item does not have a name. In these cases, use
20212019
/// [`opt_item_name`] instead.
20222020
///
20232021
/// [`opt_item_name`]: Self::opt_item_name
20242022
pub fn item_name(self, id: DefId) -> Symbol {
2025-
// Look at cross-crate items first to avoid invalidating the incremental cache
2026-
// unless we have to.
20272023
self.opt_item_name(id).unwrap_or_else(|| {
20282024
bug!("item_name: no name for {:?}", self.def_path(id));
20292025
})

compiler/rustc_resolve/src/def_collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
109109
visit::walk_item(self, i);
110110
return self.visit_macro_invoc(i.id);
111111
}
112-
ItemKind::GlobalAsm(..) => DefPathData::Misc,
112+
ItemKind::GlobalAsm(..) => DefPathData::GlobalAsm,
113113
ItemKind::Use(..) => {
114114
return visit::walk_item(self, i);
115115
}
@@ -160,11 +160,11 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
160160
}
161161

162162
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
163-
self.create_def(id, DefPathData::Misc, use_tree.span);
163+
self.create_def(id, DefPathData::Use, use_tree.span);
164164
match use_tree.kind {
165165
UseTreeKind::Simple(_, id1, id2) => {
166-
self.create_def(id1, DefPathData::Misc, use_tree.prefix.span);
167-
self.create_def(id2, DefPathData::Misc, use_tree.prefix.span);
166+
self.create_def(id1, DefPathData::Use, use_tree.prefix.span);
167+
self.create_def(id2, DefPathData::Use, use_tree.prefix.span);
168168
}
169169
UseTreeKind::Glob => (),
170170
UseTreeKind::Nested(..) => {}

compiler/rustc_symbol_mangling/src/v0.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
788788

789789
// These should never show up as `path_append` arguments.
790790
DefPathData::CrateRoot
791-
| DefPathData::Misc
791+
| DefPathData::Use
792+
| DefPathData::GlobalAsm
792793
| DefPathData::Impl
793794
| DefPathData::MacroNs(_)
794795
| DefPathData::LifetimeNs(_) => {

src/test/mir-opt/inline/cycle.g.Inline.diff

+37-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,55 @@
44
fn g() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:11:8: 11:8
66
let _1: (); // in scope 0 at $DIR/cycle.rs:12:5: 12:12
7+
+ let mut _2: fn() {main}; // in scope 0 at $DIR/cycle.rs:12:5: 12:12
8+
+ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8
9+
+ scope 1 (inlined f::<fn() {main}>) { // at $DIR/cycle.rs:12:5: 12:12
10+
+ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7
11+
+ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8
12+
+ let mut _4: &fn() {main}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6
13+
+ scope 2 (inlined <fn() {main} as Fn<()>>::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8
14+
+ }
15+
+ }
716

817
bb0: {
918
StorageLive(_1); // scope 0 at $DIR/cycle.rs:12:5: 12:12
10-
_1 = f::<fn() {main}>(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12
11-
// mir::Constant
12-
// + span: $DIR/cycle.rs:12:5: 12:6
13-
// + literal: Const { ty: fn(fn() {main}) {f::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
19+
- _1 = f::<fn() {main}>(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12
20+
+ StorageLive(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12
21+
+ _2 = main; // scope 0 at $DIR/cycle.rs:12:5: 12:12
1422
// mir::Constant
23+
- // + span: $DIR/cycle.rs:12:5: 12:6
24+
- // + literal: Const { ty: fn(fn() {main}) {f::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
25+
- // mir::Constant
1526
// + span: $DIR/cycle.rs:12:7: 12:11
1627
// + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) }
28+
+ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8
29+
+ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6
30+
+ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6
31+
+ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
32+
+ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8
33+
+ _3 = move (*_4)() -> [return: bb4, unwind: bb2]; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
1734
}
1835

1936
bb1: {
37+
+ StorageDead(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12
2038
StorageDead(_1); // scope 0 at $DIR/cycle.rs:12:12: 12:13
2139
_0 = const (); // scope 0 at $DIR/cycle.rs:11:8: 13:2
2240
return; // scope 0 at $DIR/cycle.rs:13:2: 13:2
41+
+ }
42+
+
43+
+ bb2 (cleanup): {
44+
+ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2
45+
+ }
46+
+
47+
+ bb3 (cleanup): {
48+
+ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2
49+
+ }
50+
+
51+
+ bb4: {
52+
+ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
53+
+ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8
54+
+ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9
55+
+ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2
2356
}
2457
}
2558

src/test/mir-opt/inline/cycle.main.Inline.diff

+54-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,72 @@
44
fn main() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:16:11: 16:11
66
let _1: (); // in scope 0 at $DIR/cycle.rs:17:5: 17:9
7+
+ let mut _2: fn() {g}; // in scope 0 at $DIR/cycle.rs:17:5: 17:9
8+
+ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8
9+
+ scope 1 (inlined f::<fn() {g}>) { // at $DIR/cycle.rs:17:5: 17:9
10+
+ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7
11+
+ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8
12+
+ let mut _4: &fn() {g}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6
13+
+ scope 2 (inlined <fn() {g} as Fn<()>>::call - shim(fn() {g})) { // at $DIR/cycle.rs:6:5: 6:8
14+
+ scope 3 (inlined g) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
15+
+ let mut _6: fn() {main}; // in scope 3 at $DIR/cycle.rs:12:5: 12:12
16+
+ scope 4 (inlined f::<fn() {main}>) { // at $DIR/cycle.rs:12:5: 12:12
17+
+ debug g => _6; // in scope 4 at $DIR/cycle.rs:5:6: 5:7
18+
+ let _7: (); // in scope 4 at $DIR/cycle.rs:6:5: 6:8
19+
+ let mut _8: &fn() {main}; // in scope 4 at $DIR/cycle.rs:6:5: 6:6
20+
+ scope 5 (inlined <fn() {main} as Fn<()>>::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8
21+
+ }
22+
+ }
23+
+ }
24+
+ }
25+
+ }
726

827
bb0: {
928
StorageLive(_1); // scope 0 at $DIR/cycle.rs:17:5: 17:9
10-
_1 = f::<fn() {g}>(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9
11-
// mir::Constant
12-
// + span: $DIR/cycle.rs:17:5: 17:6
13-
// + literal: Const { ty: fn(fn() {g}) {f::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
29+
- _1 = f::<fn() {g}>(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9
30+
+ StorageLive(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9
31+
+ _2 = g; // scope 0 at $DIR/cycle.rs:17:5: 17:9
1432
// mir::Constant
33+
- // + span: $DIR/cycle.rs:17:5: 17:6
34+
- // + literal: Const { ty: fn(fn() {g}) {f::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
35+
- // mir::Constant
1536
// + span: $DIR/cycle.rs:17:7: 17:8
1637
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) }
38+
+ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8
39+
+ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6
40+
+ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6
41+
+ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
42+
+ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8
43+
+ StorageLive(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12
44+
+ StorageLive(_7); // scope 4 at $DIR/cycle.rs:6:5: 6:8
45+
+ StorageLive(_8); // scope 4 at $DIR/cycle.rs:6:5: 6:6
46+
+ _8 = &_6; // scope 4 at $DIR/cycle.rs:6:5: 6:6
47+
+ _7 = move (*_8)() -> [return: bb4, unwind: bb2]; // scope 5 at $SRC_DIR/core/src/ops/function.rs:LL:COL
1748
}
1849

1950
bb1: {
51+
+ StorageDead(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9
2052
StorageDead(_1); // scope 0 at $DIR/cycle.rs:17:9: 17:10
2153
_0 = const (); // scope 0 at $DIR/cycle.rs:16:11: 18:2
2254
return; // scope 0 at $DIR/cycle.rs:18:2: 18:2
55+
+ }
56+
+
57+
+ bb2 (cleanup): {
58+
+ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2
59+
+ }
60+
+
61+
+ bb3 (cleanup): {
62+
+ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2
63+
+ }
64+
+
65+
+ bb4: {
66+
+ StorageDead(_8); // scope 4 at $DIR/cycle.rs:6:7: 6:8
67+
+ StorageDead(_7); // scope 4 at $DIR/cycle.rs:6:8: 6:9
68+
+ StorageDead(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12
69+
+ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
70+
+ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8
71+
+ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9
72+
+ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2
2373
}
2474
}
2575

src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@
44
fn main() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/inline-cycle-generic.rs:8:11: 8:11
66
let _1: (); // in scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
7-
+ scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
8-
+ scope 2 (inlined <B<A> as Call>::call) { // at $DIR/inline-cycle-generic.rs:38:9: 38:31
9-
+ }
10-
+ }
117

128
bb0: {
139
StorageLive(_1); // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
14-
- _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
15-
+ _1 = <A as Call>::call() -> bb1; // scope 2 at $DIR/inline-cycle-generic.rs:31:9: 31:28
10+
_1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
1611
// mir::Constant
17-
- // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
18-
- // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
19-
+ // + span: $DIR/inline-cycle-generic.rs:31:9: 31:26
20-
+ // + literal: Const { ty: fn() {<A as Call>::call}, val: Value(Scalar(<ZST>)) }
12+
// + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
13+
// + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
2114
}
2215

2316
bb1: {

src/test/ui/symbol-names/basic.legacy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN5basic4main17h87acd86b3a6f1754E)
1+
error: symbol-name(_ZN5basic4main17hcbad207c0eeb0b3bE)
22
--> $DIR/basic.rs:8:1
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(basic::main::h87acd86b3a6f1754)
7+
error: demangling(basic::main::hcbad207c0eeb0b3b)
88
--> $DIR/basic.rs:8:1
99
|
1010
LL | #[rustc_symbol_name]

src/test/ui/symbol-names/issue-60925.legacy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h8d22952c45e20d65E)
1+
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h2f2efcf580c9b1eeE)
22
--> $DIR/issue-60925.rs:21:9
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h8d22952c45e20d65)
7+
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h2f2efcf580c9b1ee)
88
--> $DIR/issue-60925.rs:21:9
99
|
1010
LL | #[rustc_symbol_name]

src/test/ui/traits/object/enforce-supertrait-projection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {}
77

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

1313
fn foo<A, B, T: ?Sized>(x: T::A) -> B

src/test/ui/traits/object/enforce-supertrait-projection.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
1+
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
22
--> $DIR/enforce-supertrait-projection.rs:9:5
33
|
44
LL | fn transmute<A, B>(x: A) -> B {

0 commit comments

Comments
 (0)