Skip to content

Commit e5435d9

Browse files
authored
Rollup merge of rust-lang#58894 - GuillaumeGomez:invalid-lifetime-bounds, r=estebank
Fix invalid bounds string generation in rustdoc Fixes rust-lang#58737. Very weird and I'm not sure this is the best fix around. However, trying to fix it beforehand seems overly complicated compared to the gain (in `clean`, it wouldn't change anything since we **have to** return something so that wouldn't work, and in `hir`, I'm afraid I'd break something else for very little gain). Also, I wasn't able to make a small code to reproduce the issue. The only way to test is to document `crossbeam` directly and check the `Scope` struct... r? @QuietMisdreavus
2 parents acd8dd6 + c966c45 commit e5435d9

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

src/librustc_typeck/collect.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,10 @@ fn explicit_predicates_of<'a, 'tcx>(
19181918
}
19191919
}
19201920

1921-
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
1921+
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
1922+
Some(hir_id) => hir_id,
1923+
None => return tcx.predicates_of(def_id),
1924+
};
19221925
let node = tcx.hir().get_by_hir_id(hir_id);
19231926

19241927
let mut is_trait = None;

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
568568
(replaced.clone(), replaced.clean(self.cx))
569569
});
570570

571-
let full_generics = (&type_generics, &tcx.predicates_of(did));
571+
let full_generics = (&type_generics, &tcx.explicit_predicates_of(did));
572572
let Generics {
573573
params: mut generic_params,
574574
..

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
132132
.collect();
133133

134134
let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, generics);
135-
let predicates = infcx.tcx.predicates_of(impl_def_id);
135+
let predicates = infcx.tcx.explicit_predicates_of(impl_def_id);
136136

137137
impls.push(Item {
138138
source: infcx.tcx.def_span(impl_def_id).clean(self.cx),

src/librustdoc/clean/inline.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
228228
}
229229

230230
fn build_enum(cx: &DocContext<'_>, did: DefId) -> clean::Enum {
231-
let predicates = cx.tcx.predicates_of(did);
231+
let predicates = cx.tcx.explicit_predicates_of(did);
232232

233233
clean::Enum {
234234
generics: (cx.tcx.generics_of(did), &predicates).clean(cx),
@@ -238,7 +238,7 @@ fn build_enum(cx: &DocContext<'_>, did: DefId) -> clean::Enum {
238238
}
239239

240240
fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
241-
let predicates = cx.tcx.predicates_of(did);
241+
let predicates = cx.tcx.explicit_predicates_of(did);
242242
let variant = cx.tcx.adt_def(did).non_enum_variant();
243243

244244
clean::Struct {
@@ -254,7 +254,7 @@ fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
254254
}
255255

256256
fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union {
257-
let predicates = cx.tcx.predicates_of(did);
257+
let predicates = cx.tcx.explicit_predicates_of(did);
258258
let variant = cx.tcx.adt_def(did).non_enum_variant();
259259

260260
clean::Union {
@@ -266,7 +266,7 @@ fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union {
266266
}
267267

268268
fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef {
269-
let predicates = cx.tcx.predicates_of(did);
269+
let predicates = cx.tcx.explicit_predicates_of(did);
270270

271271
clean::Typedef {
272272
type_: cx.tcx.type_of(did).clean(cx),
@@ -325,7 +325,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec<clean::Item>) {
325325
}
326326
}
327327

328-
let predicates = tcx.predicates_of(did);
328+
let predicates = tcx.explicit_predicates_of(did);
329329
let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
330330
match tcx.hir().expect_item_by_hir_id(hir_id).node {
331331
hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => {

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
22882288
}
22892289
ty::AssociatedKind::Method => {
22902290
let generics = (cx.tcx.generics_of(self.def_id),
2291-
&cx.tcx.predicates_of(self.def_id)).clean(cx);
2291+
&cx.tcx.explicit_predicates_of(self.def_id)).clean(cx);
22922292
let sig = cx.tcx.fn_sig(self.def_id);
22932293
let mut decl = (self.def_id, sig).clean(cx);
22942294

@@ -2361,7 +2361,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
23612361
// are actually located on the trait/impl itself, so we need to load
23622362
// all of the generics from there and then look for bounds that are
23632363
// applied to this associated type in question.
2364-
let predicates = cx.tcx.predicates_of(did);
2364+
let predicates = cx.tcx.explicit_predicates_of(did);
23652365
let generics = (cx.tcx.generics_of(did), &predicates).clean(cx);
23662366
let mut bounds = generics.where_predicates.iter().filter_map(|pred| {
23672367
let (name, self_type, trait_, bounds) = match *pred {
@@ -3069,7 +3069,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
30693069
ty::Opaque(def_id, substs) => {
30703070
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
30713071
// by looking up the projections associated with the def_id.
3072-
let predicates_of = cx.tcx.predicates_of(def_id);
3072+
let predicates_of = cx.tcx.explicit_predicates_of(def_id);
30733073
let substs = cx.tcx.lift(&substs).expect("Opaque lift failed");
30743074
let bounds = predicates_of.instantiate(cx.tcx, substs);
30753075
let mut regions = vec![];
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::marker::PhantomData;
2+
3+
// @has useless_lifetime_bound/struct.Scope.html
4+
// @!has - '//*[@class="rust struct"]' "'env: 'env"
5+
pub struct Scope<'env> {
6+
_marker: PhantomData<&'env mut &'env ()>,
7+
}
8+
9+
// @has useless_lifetime_bound/struct.Scope.html
10+
// @!has - '//*[@class="rust struct"]' "T: 'a + 'a"
11+
pub struct SomeStruct<'a, T: 'a> {
12+
_marker: PhantomData<&'a T>,
13+
}

0 commit comments

Comments
 (0)