Skip to content

Pretty-print argument-position impl trait to name it. #113955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down