Pretty-print impl trait to name it.

This commit is contained in:
Camille GILLOT 2022-04-08 23:29:07 +02:00
parent 26089ba0a2
commit 3907072af4
3 changed files with 8 additions and 11 deletions

View File

@ -1421,12 +1421,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
),
ImplTraitContext::Universal => {
let span = t.span;
self.create_def(
self.current_hir_id_owner.def_id,
*def_node_id,
DefPathData::ImplTrait,
span,
);
// HACK: pprust breaks strings with newlines when the type
// gets too long. We don't want these to show up in compiler
@ -1437,6 +1431,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span,
);
self.create_def(
self.current_hir_id_owner.def_id,
*def_node_id,
DefPathData::TypeNs(ident.name),
span,
);
let (param, bounds, path) = self.lower_universal_param_and_bounds(
*def_node_id,
span,

View File

@ -278,7 +278,8 @@ pub enum DefPathData {
Ctor,
/// A constant expression (see `{ast,hir}::AnonConst`).
AnonConst,
/// An `impl Trait` type node.
/// An existential `impl Trait` type node.
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
ImplTrait,
/// `impl Trait` generated associated type node.
ImplTraitAssocTy,

View File

@ -2216,10 +2216,6 @@ impl<'tcx> TyCtxt<'tcx> {
// The name of a constructor is that of its parent.
rustc_hir::definitions::DefPathData::Ctor => self
.opt_item_name(DefId { krate: def_id.krate, index: def_key.parent.unwrap() }),
// The name of opaque types only exists in HIR.
rustc_hir::definitions::DefPathData::ImplTrait
if let Some(def_id) = def_id.as_local() =>
self.hir().opt_name(self.hir().local_def_id_to_hir_id(def_id)),
_ => def_key.get_opt_name(),
}
}