Skip to content

Commit 3907072

Browse files
committed
Pretty-print impl trait to name it.
1 parent 26089ba commit 3907072

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1421,12 +1421,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14211421
),
14221422
ImplTraitContext::Universal => {
14231423
let span = t.span;
1424-
self.create_def(
1425-
self.current_hir_id_owner.def_id,
1426-
*def_node_id,
1427-
DefPathData::ImplTrait,
1428-
span,
1429-
);
14301424

14311425
// HACK: pprust breaks strings with newlines when the type
14321426
// gets too long. We don't want these to show up in compiler
@@ -1437,6 +1431,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14371431
span,
14381432
);
14391433

1434+
self.create_def(
1435+
self.current_hir_id_owner.def_id,
1436+
*def_node_id,
1437+
DefPathData::TypeNs(ident.name),
1438+
span,
1439+
);
14401440
let (param, bounds, path) = self.lower_universal_param_and_bounds(
14411441
*def_node_id,
14421442
span,

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,

compiler/rustc_middle/src/ty/mod.rs

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

0 commit comments

Comments
 (0)