From 3907072af4dcb6a11a498817fa5fd1e7e3b4070a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 8 Apr 2022 23:29:07 +0200 Subject: [PATCH 1/2] Pretty-print impl trait to name it. --- compiler/rustc_ast_lowering/src/lib.rs | 12 ++++++------ compiler/rustc_hir/src/definitions.rs | 3 ++- compiler/rustc_middle/src/ty/mod.rs | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a4ba1a5c9bf..965acae62a9 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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, diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 66b153d8931..168b336e374 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -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, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 8fedf4dca95..70f75ebe0f1 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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(), } } From 832a2a18e722f13141898a7c3918c5cb45a8c043 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 22 Jul 2023 12:32:03 +0000 Subject: [PATCH 2/2] Do not ICE in rustdoc. --- src/librustdoc/clean/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 80a7a33d2bd..7e2aad83003 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -151,7 +151,7 @@ pub(super) fn external_path<'tcx>( args: ty::Binder<'tcx, GenericArgsRef<'tcx>>, ) -> Path { let def_kind = cx.tcx.def_kind(did); - let name = cx.tcx.item_name(did); + let name = cx.tcx.opt_item_name(did).unwrap_or(kw::Empty); Path { res: Res::Def(def_kind, did), segments: thin_vec![PathSegment {