Skip to content

Commit 15a727b

Browse files
committed
rustdoc: Fix inlining type parameters
I'm not entirely sure if the correct space can be inferred when cleaning Generics, so the impl has been switched to take the space explicitly. Closes #15099
1 parent 80efb22 commit 15a727b

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc::metadata::csearch;
1818
use rustc::metadata::decoder;
1919
use rustc::middle::def;
2020
use rustc::middle::ty;
21+
use rustc::middle::subst;
2122
use rustc::middle::stability;
2223

2324
use core;
@@ -163,7 +164,7 @@ pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
163164
});
164165

165166
clean::Trait {
166-
generics: def.generics.clean(),
167+
generics: (&def.generics, subst::TypeSpace).clean(),
167168
methods: methods.collect(),
168169
parents: parents.collect()
169170
}
@@ -178,7 +179,7 @@ fn build_external_function(tcx: &ty::ctxt,
178179
ty::ty_bare_fn(ref f) => (did, &f.sig).clean(),
179180
_ => fail!("bad function"),
180181
},
181-
generics: t.generics.clean(),
182+
generics: (&t.generics, subst::FnSpace).clean(),
182183
fn_style: style,
183184
}
184185
}
@@ -196,7 +197,7 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct {
196197
[ref f, ..] if f.name == unnamed_field.name => doctree::Tuple,
197198
_ => doctree::Plain,
198199
},
199-
generics: t.generics.clean(),
200+
generics: (&t.generics, subst::TypeSpace).clean(),
200201
fields: fields.iter().map(|f| f.clean()).collect(),
201202
fields_stripped: false,
202203
}
@@ -207,7 +208,7 @@ fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum {
207208
match ty::get(t.ty).sty {
208209
ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
209210
return clean::EnumItem(clean::Enum {
210-
generics: t.generics.clean(),
211+
generics: (&t.generics, subst::TypeSpace).clean(),
211212
variants_stripped: false,
212213
variants: ty::enum_variants(tcx, edid).clean(),
213214
})
@@ -217,7 +218,7 @@ fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum {
217218

218219
clean::TypedefItem(clean::Typedef {
219220
type_: t.ty.clean(),
220-
generics: t.generics.clean(),
221+
generics: (&t.generics, subst::TypeSpace).clean(),
221222
})
222223
}
223224

@@ -323,7 +324,7 @@ fn build_impl(cx: &core::DocContext,
323324
}
324325
}),
325326
for_: ty.ty.clean(),
326-
generics: ty.generics.clean(),
327+
generics: (&ty.generics, subst::TypeSpace).clean(),
327328
methods: methods,
328329
}),
329330
source: clean::Span::empty(),

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -653,35 +653,12 @@ impl Clean<Generics> for ast::Generics {
653653
}
654654
}
655655

656-
impl Clean<Generics> for ty::Generics {
656+
impl<'a> Clean<Generics> for (&'a ty::Generics, subst::ParamSpace) {
657657
fn clean(&self) -> Generics {
658-
// In the type space, generics can come in one of multiple
659-
// namespaces. This means that e.g. for fn items the type
660-
// parameters will live in FnSpace, but for types the
661-
// parameters will live in TypeSpace (trait definitions also
662-
// define a parameter in SelfSpace). *Method* definitions are
663-
// the one exception: they combine the TypeSpace parameters
664-
// from the enclosing impl/trait with their own FnSpace
665-
// parameters.
666-
//
667-
// In general, when we clean, we are trying to produce the
668-
// "user-facing" generics. Hence we select the most specific
669-
// namespace that is occupied, ignoring SelfSpace because it
670-
// is implicit.
671-
672-
let space = {
673-
if !self.types.is_empty_in(subst::FnSpace) ||
674-
!self.regions.is_empty_in(subst::FnSpace)
675-
{
676-
subst::FnSpace
677-
} else {
678-
subst::TypeSpace
679-
}
680-
};
681-
658+
let (me, space) = *self;
682659
Generics {
683-
type_params: Vec::from_slice(self.types.get_slice(space)).clean(),
684-
lifetimes: Vec::from_slice(self.regions.get_slice(space)).clean(),
660+
type_params: Vec::from_slice(me.types.get_slice(space)).clean(),
661+
lifetimes: Vec::from_slice(me.regions.get_slice(space)).clean(),
685662
}
686663
}
687664
}
@@ -1030,7 +1007,7 @@ impl Clean<Item> for ty::Method {
10301007
source: Span::empty(),
10311008
inner: TyMethodItem(TyMethod {
10321009
fn_style: self.fty.fn_style,
1033-
generics: self.generics.clean(),
1010+
generics: (&self.generics, subst::FnSpace).clean(),
10341011
self_: self_,
10351012
decl: (self.def_id, &sig).clean(),
10361013
})

0 commit comments

Comments
 (0)