1
Fork 0

Fix invalid bounds string generation in rustdoc

This commit is contained in:
Guillaume Gomez 2019-03-31 15:32:25 +02:00
parent 2002b4b39a
commit ddd034aa6f
6 changed files with 26 additions and 11 deletions

View file

@ -1918,7 +1918,15 @@ fn explicit_predicates_of<'a, 'tcx>(
} }
} }
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let hir_id = match tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => hir_id,
None => {
return Lrc::new(ty::GenericPredicates {
parent: None,
predicates: Vec::new(),
})
}
};
let node = tcx.hir().get_by_hir_id(hir_id); let node = tcx.hir().get_by_hir_id(hir_id);
let mut is_trait = None; let mut is_trait = None;

View file

@ -568,7 +568,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
(replaced.clone(), replaced.clean(self.cx)) (replaced.clone(), replaced.clean(self.cx))
}); });
let full_generics = (&type_generics, &tcx.predicates_of(did)); let full_generics = (&type_generics, &tcx.explicit_predicates_of(did));
let Generics { let Generics {
params: mut generic_params, params: mut generic_params,
.. ..

View file

@ -132,7 +132,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.collect(); .collect();
let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, generics); let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, generics);
let predicates = infcx.tcx.predicates_of(impl_def_id); let predicates = infcx.tcx.explicit_predicates_of(impl_def_id);
impls.push(Item { impls.push(Item {
source: infcx.tcx.def_span(impl_def_id).clean(self.cx), source: infcx.tcx.def_span(impl_def_id).clean(self.cx),

View file

@ -228,7 +228,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
} }
fn build_enum(cx: &DocContext<'_>, did: DefId) -> clean::Enum { fn build_enum(cx: &DocContext<'_>, did: DefId) -> clean::Enum {
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
clean::Enum { clean::Enum {
generics: (cx.tcx.generics_of(did), &predicates).clean(cx), generics: (cx.tcx.generics_of(did), &predicates).clean(cx),
@ -238,7 +238,7 @@ fn build_enum(cx: &DocContext<'_>, did: DefId) -> clean::Enum {
} }
fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct { fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
let variant = cx.tcx.adt_def(did).non_enum_variant(); let variant = cx.tcx.adt_def(did).non_enum_variant();
clean::Struct { clean::Struct {
@ -254,7 +254,7 @@ fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
} }
fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union { fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union {
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
let variant = cx.tcx.adt_def(did).non_enum_variant(); let variant = cx.tcx.adt_def(did).non_enum_variant();
clean::Union { clean::Union {
@ -266,7 +266,7 @@ fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union {
} }
fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef { fn build_type_alias(cx: &DocContext<'_>, did: DefId) -> clean::Typedef {
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
clean::Typedef { clean::Typedef {
type_: cx.tcx.type_of(did).clean(cx), 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>) {
} }
} }
let predicates = tcx.predicates_of(did); let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item_by_hir_id(hir_id).node { match tcx.hir().expect_item_by_hir_id(hir_id).node {
hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => { hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => {

View file

@ -2281,7 +2281,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
} }
ty::AssociatedKind::Method => { ty::AssociatedKind::Method => {
let generics = (cx.tcx.generics_of(self.def_id), let generics = (cx.tcx.generics_of(self.def_id),
&cx.tcx.predicates_of(self.def_id)).clean(cx); &cx.tcx.explicit_predicates_of(self.def_id)).clean(cx);
let sig = cx.tcx.fn_sig(self.def_id); let sig = cx.tcx.fn_sig(self.def_id);
let mut decl = (self.def_id, sig).clean(cx); let mut decl = (self.def_id, sig).clean(cx);
@ -2354,7 +2354,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
// are actually located on the trait/impl itself, so we need to load // are actually located on the trait/impl itself, so we need to load
// all of the generics from there and then look for bounds that are // all of the generics from there and then look for bounds that are
// applied to this associated type in question. // applied to this associated type in question.
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
let generics = (cx.tcx.generics_of(did), &predicates).clean(cx); let generics = (cx.tcx.generics_of(did), &predicates).clean(cx);
let mut bounds = generics.where_predicates.iter().filter_map(|pred| { let mut bounds = generics.where_predicates.iter().filter_map(|pred| {
let (name, self_type, trait_, bounds) = match *pred { let (name, self_type, trait_, bounds) = match *pred {
@ -3062,7 +3062,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
ty::Opaque(def_id, substs) => { ty::Opaque(def_id, substs) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the projections associated with the def_id. // by looking up the projections associated with the def_id.
let predicates_of = cx.tcx.predicates_of(def_id); let predicates_of = cx.tcx.explicit_predicates_of(def_id);
let substs = cx.tcx.lift(&substs).expect("Opaque lift failed"); let substs = cx.tcx.lift(&substs).expect("Opaque lift failed");
let bounds = predicates_of.instantiate(cx.tcx, substs); let bounds = predicates_of.instantiate(cx.tcx, substs);
let mut regions = vec![]; let mut regions = vec![];

View file

@ -0,0 +1,7 @@
use std::marker::PhantomData;
// @has useless_lifetime_bound/struct.Scope.html
// @!has - '//*[@class="rust struct"]' "'env: 'env"
pub struct Scope<'env> {
_marker: PhantomData<&'env mut &'env ()>,
}