Skip to content

Commit 7820972

Browse files
committed
Auto merge of rust-lang#107637 - fmease:rustdoc-reelide-x-crate-def-tr-obj-lt-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 rust-lang#44306. Follow-up to rust-lang#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, rust-lang#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
2 parents ef8ee73 + 5b5d84f commit 7820972

File tree

8 files changed

+402
-68
lines changed

8 files changed

+402
-68
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ where
124124
unsafety: hir::Unsafety::Normal,
125125
generics: new_generics,
126126
trait_: Some(clean_trait_ref_with_bindings(self.cx, trait_ref, ThinVec::new())),
127-
for_: clean_middle_ty(ty::Binder::dummy(ty), self.cx, None),
127+
for_: clean_middle_ty(ty::Binder::dummy(ty), self.cx, None, None),
128128
items: Vec::new(),
129129
polarity,
130130
kind: ImplKind::Auto,

src/librustdoc/clean/blanket_impl.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
107107
ty::Binder::dummy(trait_ref.subst_identity()),
108108
ThinVec::new(),
109109
)),
110-
for_: clean_middle_ty(ty::Binder::dummy(ty.subst_identity()), cx, None),
110+
for_: clean_middle_ty(
111+
ty::Binder::dummy(ty.subst_identity()),
112+
cx,
113+
None,
114+
None,
115+
),
111116
items: cx
112117
.tcx
113118
.associated_items(impl_def_id)
@@ -119,6 +124,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
119124
ty::Binder::dummy(trait_ref.subst_identity().self_ty()),
120125
cx,
121126
None,
127+
None,
122128
))),
123129
}))),
124130
cfg: None,

src/librustdoc/clean/inline.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,12 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
278278

279279
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
280280
let predicates = cx.tcx.explicit_predicates_of(did);
281-
let type_ =
282-
clean_middle_ty(ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()), cx, Some(did));
281+
let type_ = clean_middle_ty(
282+
ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()),
283+
cx,
284+
Some(did),
285+
None,
286+
);
283287

284288
Box::new(clean::Typedef {
285289
type_,
@@ -386,9 +390,12 @@ pub(crate) fn build_impl(
386390

387391
let for_ = match &impl_item {
388392
Some(impl_) => clean_ty(impl_.self_ty, cx),
389-
None => {
390-
clean_middle_ty(ty::Binder::dummy(tcx.type_of(did).subst_identity()), cx, Some(did))
391-
}
393+
None => clean_middle_ty(
394+
ty::Binder::dummy(tcx.type_of(did).subst_identity()),
395+
cx,
396+
Some(did),
397+
None,
398+
),
392399
};
393400

394401
// Only inline impl if the implementing type is
@@ -630,6 +637,7 @@ fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
630637
ty::Binder::dummy(cx.tcx.type_of(def_id).subst_identity()),
631638
cx,
632639
Some(def_id),
640+
None,
633641
),
634642
kind: clean::ConstantKind::Extern { def_id },
635643
}
@@ -641,6 +649,7 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
641649
ty::Binder::dummy(cx.tcx.type_of(did).subst_identity()),
642650
cx,
643651
Some(did),
652+
None,
644653
),
645654
mutability: if mutable { Mutability::Mut } else { Mutability::Not },
646655
expr: None,

0 commit comments

Comments
 (0)