Skip to content

Commit bdb0fa3

Browse files
committed
Auto merge of rust-lang#113955 - cjgillot:name-apit, r=WaffleLapkin
Pretty-print argument-position impl trait to name it. This removes a corner case. RPIT and TAIT keep having no name, and it would be wrong to use the one in HIR (Ident::empty), so I make this case ICE.
2 parents ac5ac47 + 832a2a1 commit bdb0fa3

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1431,12 +1431,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14311431
),
14321432
ImplTraitContext::Universal => {
14331433
let span = t.span;
1434-
self.create_def(
1435-
self.current_hir_id_owner.def_id,
1436-
*def_node_id,
1437-
DefPathData::ImplTrait,
1438-
span,
1439-
);
14401434

14411435
// HACK: pprust breaks strings with newlines when the type
14421436
// gets too long. We don't want these to show up in compiler
@@ -1447,6 +1441,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14471441
span,
14481442
);
14491443

1444+
self.create_def(
1445+
self.current_hir_id_owner.def_id,
1446+
*def_node_id,
1447+
DefPathData::TypeNs(ident.name),
1448+
span,
1449+
);
14501450
let (param, bounds, path) = self.lower_universal_param_and_bounds(
14511451
*def_node_id,
14521452
span,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ pub enum DefPathData {
278278
Ctor,
279279
/// A constant expression (see `{ast,hir}::AnonConst`).
280280
AnonConst,
281-
/// An `impl Trait` type node.
281+
/// An existential `impl Trait` type node.
282+
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
282283
ImplTrait,
283284
/// `impl Trait` generated associated type node.
284285
ImplTraitAssocTy,

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

-4
Original file line numberDiff line numberDiff line change
@@ -2214,10 +2214,6 @@ impl<'tcx> TyCtxt<'tcx> {
22142214
// The name of a constructor is that of its parent.
22152215
rustc_hir::definitions::DefPathData::Ctor => self
22162216
.opt_item_name(DefId { krate: def_id.krate, index: def_key.parent.unwrap() }),
2217-
// The name of opaque types only exists in HIR.
2218-
rustc_hir::definitions::DefPathData::ImplTrait
2219-
if let Some(def_id) = def_id.as_local() =>
2220-
self.hir().opt_name(self.hir().local_def_id_to_hir_id(def_id)),
22212217
_ => def_key.get_opt_name(),
22222218
}
22232219
}

Diff for: src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(super) fn external_path<'tcx>(
153153
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
154154
) -> Path {
155155
let def_kind = cx.tcx.def_kind(did);
156-
let name = cx.tcx.item_name(did);
156+
let name = cx.tcx.opt_item_name(did).unwrap_or(kw::Empty);
157157
Path {
158158
res: Res::Def(def_kind, did),
159159
segments: thin_vec![PathSegment {

0 commit comments

Comments
 (0)