Skip to content

Commit 2b54f9b

Browse files
authored
Rollup merge of rust-lang#139662 - nnethercote:tweak-DefPathData, r=compiler-errors
Tweak `DefPathData` Some improvements in and around `DefPathData`, following on from rust-lang#137977. r? `@spastorino`
2 parents 2f873f9 + cdf5b8d commit 2b54f9b

File tree

17 files changed

+49
-45
lines changed

17 files changed

+49
-45
lines changed

Diff for: compiler/rustc_hir/src/def.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ impl DefKind {
267267
| DefKind::ForeignTy
268268
| DefKind::TraitAlias
269269
| DefKind::TyParam
270-
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),
271-
272-
// An associated type names will be missing for an RPITIT. It will
273-
// later be given a name with `synthetic` in it, if necessary.
274-
DefKind::AssocTy => DefPathData::TypeNs(name),
270+
| DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),
271+
272+
// An associated type name will be missing for an RPITIT.
273+
DefKind::AssocTy => {
274+
if let Some(name) = name {
275+
DefPathData::TypeNs(name)
276+
} else {
277+
DefPathData::AnonAssocTy
278+
}
279+
}
275280

276281
// It's not exactly an anon const, but wrt DefPathData, there
277282
// is no difference.

Diff for: compiler/rustc_hir/src/definitions.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,8 @@ pub enum DefPathData {
271271
Use,
272272
/// A global asm item.
273273
GlobalAsm,
274-
/// Something in the type namespace. Will be empty for RPITIT associated
275-
/// types, which are given a synthetic name later, if necessary.
276-
TypeNs(Option<Symbol>),
274+
/// Something in the type namespace.
275+
TypeNs(Symbol),
277276
/// Something in the value namespace.
278277
ValueNs(Symbol),
279278
/// Something in the macro namespace.
@@ -291,6 +290,8 @@ pub enum DefPathData {
291290
/// An existential `impl Trait` type node.
292291
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
293292
OpaqueTy,
293+
/// An anonymous associated type from an RPITIT.
294+
AnonAssocTy,
294295
/// A synthetic body for a coroutine's by-move body.
295296
SyntheticCoroutineBody,
296297
}
@@ -413,9 +414,7 @@ impl DefPathData {
413414
pub fn get_opt_name(&self) -> Option<Symbol> {
414415
use self::DefPathData::*;
415416
match *self {
416-
TypeNs(name) => name,
417-
418-
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
417+
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
419418

420419
Impl
421420
| ForeignMod
@@ -426,21 +425,17 @@ impl DefPathData {
426425
| Ctor
427426
| AnonConst
428427
| OpaqueTy
428+
| AnonAssocTy
429429
| SyntheticCoroutineBody => None,
430430
}
431431
}
432432

433433
pub fn name(&self) -> DefPathDataName {
434434
use self::DefPathData::*;
435435
match *self {
436-
TypeNs(name) => {
437-
if let Some(name) = name {
438-
DefPathDataName::Named(name)
439-
} else {
440-
DefPathDataName::Anon { namespace: sym::synthetic }
441-
}
436+
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
437+
DefPathDataName::Named(name)
442438
}
443-
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
444439
// Note that this does not show up in user print-outs.
445440
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
446441
Impl => DefPathDataName::Anon { namespace: kw::Impl },
@@ -451,6 +446,7 @@ impl DefPathData {
451446
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
452447
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
453448
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
449+
AnonAssocTy => DefPathDataName::Anon { namespace: sym::anon_assoc },
454450
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
455451
}
456452
}

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
620620
// the children of the visible parent (as was done when computing
621621
// `visible_parent_map`), looking for the specific child we currently have and then
622622
// have access to the re-exported name.
623-
DefPathData::TypeNs(Some(ref mut name)) if Some(visible_parent) != actual_parent => {
623+
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
624624
// Item might be re-exported several times, but filter for the one
625625
// that's public and whose identifier isn't `_`.
626626
let reexport = self
@@ -641,7 +641,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
641641
}
642642
// Re-exported `extern crate` (#43189).
643643
DefPathData::CrateRoot => {
644-
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
644+
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
645645
}
646646
_ => {}
647647
}

Diff for: compiler/rustc_middle/src/ty/significant_drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn true_significant_drop_ty<'tcx>(
2626
name_rev.push(tcx.crate_name(did.krate));
2727
}
2828
rustc_hir::definitions::DefPathData::TypeNs(symbol) => {
29-
name_rev.push(symbol.unwrap());
29+
name_rev.push(symbol);
3030
}
3131
_ => return None,
3232
}

Diff for: compiler/rustc_resolve/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1337,12 +1337,12 @@ impl<'tcx> Resolver<'_, 'tcx> {
13371337
expn_id: ExpnId,
13381338
span: Span,
13391339
) -> TyCtxtFeed<'tcx, LocalDefId> {
1340-
let data = def_kind.def_path_data(name);
13411340
assert!(
13421341
!self.node_id_to_def_id.contains_key(&node_id),
1343-
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
1342+
"adding a def for node-id {:?}, name {:?}, data {:?} but a previous def exists: {:?}",
13441343
node_id,
1345-
data,
1344+
name,
1345+
def_kind,
13461346
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id].key()),
13471347
);
13481348

Diff for: compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,8 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
721721
| hir::definitions::DefPathData::Use
722722
| hir::definitions::DefPathData::GlobalAsm
723723
| hir::definitions::DefPathData::MacroNs(..)
724-
| hir::definitions::DefPathData::LifetimeNs(..) => {
724+
| hir::definitions::DefPathData::LifetimeNs(..)
725+
| hir::definitions::DefPathData::AnonAssocTy => {
725726
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
726727
}
727728
});

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ symbols! {
454454
and_then,
455455
anon,
456456
anon_adt,
457+
anon_assoc,
457458
anonymous_lifetime_in_impl_trait,
458459
any,
459460
append_const_msg,

Diff for: compiler/rustc_symbol_mangling/src/v0.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,8 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
858858
| DefPathData::GlobalAsm
859859
| DefPathData::Impl
860860
| DefPathData::MacroNs(_)
861-
| DefPathData::LifetimeNs(_) => {
861+
| DefPathData::LifetimeNs(_)
862+
| DefPathData::AnonAssocTy => {
862863
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
863864
}
864865
};

Diff for: compiler/rustc_ty_utils/src/assoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn associated_type_for_impl_trait_in_trait(
252252
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
253253

254254
let span = tcx.def_span(opaque_ty_def_id);
255-
// No name because this is a synthetic associated type.
255+
// No name because this is an anonymous associated type.
256256
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, None, DefKind::AssocTy);
257257

258258
let local_def_id = trait_assoc_ty.def_id();
@@ -305,7 +305,7 @@ fn associated_type_for_impl_trait_in_impl(
305305
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
306306
hir::FnRetTy::Return(ty) => ty.span,
307307
};
308-
// No name because this is a synthetic associated type.
308+
// No name because this is an anonymous associated type.
309309
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, None, DefKind::AssocTy);
310310

311311
let local_def_id = impl_assoc_ty.def_id();

Diff for: src/tools/clippy/clippy_utils/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
35043504
// a::b::c ::d::sym refers to
35053505
// e::f::sym:: ::
35063506
// result should be super::super::super::super::e::f
3507-
if let DefPathData::TypeNs(Some(s)) = l {
3507+
if let DefPathData::TypeNs(s) = l {
35083508
path.push(s.to_string());
35093509
}
35103510
if let DefPathData::TypeNs(_) = r {
@@ -3515,7 +3515,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
35153515
// a::b::sym:: :: refers to
35163516
// c::d::e ::f::sym
35173517
// when looking at `f`
3518-
Left(DefPathData::TypeNs(Some(sym))) => path.push(sym.to_string()),
3518+
Left(DefPathData::TypeNs(sym)) => path.push(sym.to_string()),
35193519
// consider:
35203520
// a::b::c ::d::sym refers to
35213521
// e::f::sym:: ::
@@ -3529,7 +3529,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
35293529
// `super` chain would be too long, just use the absolute path instead
35303530
once(String::from("crate"))
35313531
.chain(to.data.iter().filter_map(|el| {
3532-
if let DefPathData::TypeNs(Some(sym)) = el.data {
3532+
if let DefPathData::TypeNs(sym) = el.data {
35333533
Some(sym.to_string())
35343534
} else {
35353535
None

Diff for: tests/ui-fulldeps/stable-mir/check_assoc_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn test_assoc_items() -> ControlFlow<()> {
5151
check_items(
5252
&trait_assoc_item_defs,
5353
&[
54-
"ATrait::{synthetic#0}",
54+
"ATrait::{anon_assoc#0}",
5555
"ATrait::rpitit",
5656
"ATrait::Assoc",
5757
"ATrait::assoc_fn_no_self",
@@ -64,7 +64,7 @@ fn test_assoc_items() -> ControlFlow<()> {
6464
check_items(
6565
&impl_assoc_item_defs,
6666
&[
67-
"<AStruct as ATrait>::{synthetic#0}",
67+
"<AStruct as ATrait>::{anon_assoc#0}",
6868
"<AStruct as ATrait>::rpitit",
6969
"<AStruct as ATrait>::Assoc",
7070
"<AStruct as ATrait>::assoc_fn_no_self",

Diff for: tests/ui/delegation/unsupported.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`
1+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{anon_assoc#0}`
22
--> $DIR/unsupported.rs:22:25
33
|
44
LL | reuse to_reuse::opaque_ret;
@@ -9,15 +9,15 @@ note: ...which requires comparing an impl and trait method signature, inferring
99
|
1010
LL | reuse to_reuse::opaque_ret;
1111
| ^^^^^^^^^^
12-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`, completing the cycle
12+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{anon_assoc#0}`, completing the cycle
1313
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>` is well-formed
1414
--> $DIR/unsupported.rs:21:5
1515
|
1616
LL | impl ToReuse for u8 {
1717
| ^^^^^^^^^^^^^^^^^^^
1818
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1919

20-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`
20+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{anon_assoc#0}`
2121
--> $DIR/unsupported.rs:25:24
2222
|
2323
LL | reuse ToReuse::opaque_ret;
@@ -28,7 +28,7 @@ note: ...which requires comparing an impl and trait method signature, inferring
2828
|
2929
LL | reuse ToReuse::opaque_ret;
3030
| ^^^^^^^^^^
31-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`, completing the cycle
31+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{anon_assoc#0}`, completing the cycle
3232
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>` is well-formed
3333
--> $DIR/unsupported.rs:24:5
3434
|

Diff for: tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | fn bar() -> () {}
66
|
77
= help: the trait `std::fmt::Display` is not implemented for `()`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9-
note: required by a bound in `Foo::{synthetic#0}`
9+
note: required by a bound in `Foo::{anon_assoc#0}`
1010
--> $DIR/doesnt-satisfy.rs:2:22
1111
|
1212
LL | fn bar() -> impl std::fmt::Display;
13-
| ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{synthetic#0}`
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{anon_assoc#0}`
1414

1515
error: aborting due to 1 previous error
1616

Diff for: tests/ui/impl-trait/in-trait/dump.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait Foo {
88
}
99

1010
fn hello<'s, T: Foo>(x: &'s T) -> impl Sized + use<'s, T> {
11-
//~^ ERROR <T as Foo>::{synthetic#0}<'s/#1>
11+
//~^ ERROR <T as Foo>::{anon_assoc#0}<'s/#1>
1212
x.hello()
1313
}
1414

Diff for: tests/ui/impl-trait/in-trait/dump.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: <T as Foo>::{synthetic#0}<'s/#1>
1+
error: <T as Foo>::{anon_assoc#0}<'s/#1>
22
--> $DIR/dump.rs:10:35
33
|
44
LL | fn hello<'s, T: Foo>(x: &'s T) -> impl Sized + use<'s, T> {

Diff for: tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ LL | fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
1414
| ^^^^^^^^^^^^ the trait `Foo<char>` is not implemented for `impl Foo<u8>`
1515
|
1616
= help: the trait `Foo<char>` is implemented for `Bar`
17-
note: required by a bound in `Foo::{synthetic#0}`
17+
note: required by a bound in `Foo::{anon_assoc#0}`
1818
--> $DIR/return-dont-satisfy-bounds.rs:2:30
1919
|
2020
LL | fn foo<F2>(self) -> impl Foo<T>;
21-
| ^^^^^^ required by this bound in `Foo::{synthetic#0}`
21+
| ^^^^^^ required by this bound in `Foo::{anon_assoc#0}`
2222

2323
error[E0277]: the trait bound `Bar: Foo<u8>` is not satisfied
2424
--> $DIR/return-dont-satisfy-bounds.rs:8:34

Diff for: tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error[E0277]: the trait bound `Something: Termination` is not satisfied
44
LL | fn main() -> Something {
55
| ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
66
|
7-
note: required by a bound in `Main::{synthetic#0}`
7+
note: required by a bound in `Main::{anon_assoc#0}`
88
--> $DIR/issue-103052-2.rs:3:27
99
|
1010
LL | fn main() -> impl std::process::Termination;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{synthetic#0}`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{anon_assoc#0}`
1212

1313
error: aborting due to 1 previous error
1414

0 commit comments

Comments
 (0)