Skip to content

Commit

Permalink
Auto merge of #107637 - fmease:rustdoc-reelide-x-crate-def-tr-obj-lt-…
Browse files Browse the repository at this point in the history
…bnds, r=notriddle,cgillot,GuillaumeGomez

rustdoc: re-elide cross-crate default trait-object lifetime bounds

Hide trait-object lifetime bounds (re-exported from an external crate) if they coincide with [their default](https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes).
Partially addresses #44306. Follow-up to #103885. [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/clean_middle_ty.3A.20I.20need.20to.20add.20a.20parameter/near/307143097).

Most notably, if `std` exported something from `core` containing a type like `Box<dyn Fn()>`, then it would now be rendered as `Box<dyn Fn(), Global>` instead of `Box<dyn Fn() + 'static, Global>` (hiding `+ 'static` as it is the default in this case). Showing `Global` here is a separate issue, #80379, which is on my agenda.

Note that I am not really fond of the fact that I had to add a parameter to such a widely used function (30+ call sites) to address such a niche bug.

CC `@GuillaumeGomez`
Requesting a review from a compiler contributor or team member as recommended on Zulip.
r? compiler

---

`@rustbot` label T-compiler T-rustdoc A-cross-crate-reexports
  • Loading branch information
bors committed Jun 10, 2023
2 parents ef8ee73 + 5b5d84f commit 7820972
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
unsafety: hir::Unsafety::Normal,
generics: new_generics,
trait_: Some(clean_trait_ref_with_bindings(self.cx, trait_ref, ThinVec::new())),
for_: clean_middle_ty(ty::Binder::dummy(ty), self.cx, None),
for_: clean_middle_ty(ty::Binder::dummy(ty), self.cx, None, None),
items: Vec::new(),
polarity,
kind: ImplKind::Auto,
Expand Down
8 changes: 7 additions & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
ty::Binder::dummy(trait_ref.subst_identity()),
ThinVec::new(),
)),
for_: clean_middle_ty(ty::Binder::dummy(ty.subst_identity()), cx, None),
for_: clean_middle_ty(
ty::Binder::dummy(ty.subst_identity()),
cx,
None,
None,
),
items: cx
.tcx
.associated_items(impl_def_id)
Expand All @@ -119,6 +124,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
ty::Binder::dummy(trait_ref.subst_identity().self_ty()),
cx,
None,
None,
))),
}))),
cfg: None,
Expand Down
19 changes: 14 additions & 5 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,12 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {

fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
let predicates = cx.tcx.explicit_predicates_of(did);
let type_ =
clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()), cx, Some(did));
let type_ = clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()),
cx,
Some(did),
None,
);

Box::new(clean::Typedef {
type_,
Expand Down Expand Up @@ -386,9 +390,12 @@ pub(crate) fn build_impl(

let for_ = match &impl_item {
Some(impl_) => clean_ty(impl_.self_ty, cx),
None => {
clean_middle_ty(ty::Binder::dummy(tcx.type_of(did).subst_identity()), cx, Some(did))
}
None => clean_middle_ty(
ty::Binder::dummy(tcx.type_of(did).subst_identity()),
cx,
Some(did),
None,
),
};

// Only inline impl if the implementing type is
Expand Down Expand Up @@ -630,6 +637,7 @@ fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
ty::Binder::dummy(cx.tcx.type_of(def_id).subst_identity()),
cx,
Some(def_id),
None,
),
kind: clean::ConstantKind::Extern { def_id },
}
Expand All @@ -641,6 +649,7 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()),
cx,
Some(did),
None,
),
mutability: if mutable { Mutability::Mut } else { Mutability::Not },
expr: None,
Expand Down
Loading

0 comments on commit 7820972

Please sign in to comment.