fix rustdoc generic param order
This commit is contained in:
parent
1799d31847
commit
b90bc8d70b
4 changed files with 15 additions and 30 deletions
|
@ -480,6 +480,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
.clean(self.cx)
|
.clean(self.cx)
|
||||||
.params;
|
.params;
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"param_env_to_generics({:?}): generic_params={:?}",
|
||||||
|
param_env_def_id, generic_params
|
||||||
|
);
|
||||||
|
|
||||||
let mut has_sized = FxHashSet::default();
|
let mut has_sized = FxHashSet::default();
|
||||||
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
|
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
|
||||||
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
|
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
|
||||||
|
|
|
@ -716,11 +716,11 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
|
||||||
// Bounds in the type_params and lifetimes fields are repeated in the
|
// Bounds in the type_params and lifetimes fields are repeated in the
|
||||||
// predicates field (see rustc_typeck::collect::ty_generics), so remove
|
// predicates field (see rustc_typeck::collect::ty_generics), so remove
|
||||||
// them.
|
// them.
|
||||||
let stripped_typarams = gens
|
let stripped_params = gens
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|param| match param.kind {
|
.filter_map(|param| match param.kind {
|
||||||
ty::GenericParamDefKind::Lifetime => None,
|
ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
|
||||||
ty::GenericParamDefKind::Type { synthetic, .. } => {
|
ty::GenericParamDefKind::Type { synthetic, .. } => {
|
||||||
if param.name == kw::SelfUpper {
|
if param.name == kw::SelfUpper {
|
||||||
assert_eq!(param.index, 0);
|
assert_eq!(param.index, 0);
|
||||||
|
@ -732,7 +732,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
|
||||||
}
|
}
|
||||||
Some(param.clean(cx))
|
Some(param.clean(cx))
|
||||||
}
|
}
|
||||||
ty::GenericParamDefKind::Const { .. } => None,
|
ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
|
||||||
})
|
})
|
||||||
.collect::<Vec<GenericParamDef>>();
|
.collect::<Vec<GenericParamDef>>();
|
||||||
|
|
||||||
|
@ -844,8 +844,10 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
|
||||||
|
|
||||||
// Run through the type parameters again and insert a ?Sized
|
// Run through the type parameters again and insert a ?Sized
|
||||||
// unbound for any we didn't find to be Sized.
|
// unbound for any we didn't find to be Sized.
|
||||||
for tp in &stripped_typarams {
|
for tp in &stripped_params {
|
||||||
if !sized_params.contains(&tp.name) {
|
if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
|
||||||
|
&& !sized_params.contains(&tp.name)
|
||||||
|
{
|
||||||
where_predicates.push(WP::BoundPredicate {
|
where_predicates.push(WP::BoundPredicate {
|
||||||
ty: Type::Generic(tp.name.clone()),
|
ty: Type::Generic(tp.name.clone()),
|
||||||
bounds: vec![GenericBound::maybe_sized(cx)],
|
bounds: vec![GenericBound::maybe_sized(cx)],
|
||||||
|
@ -858,16 +860,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
|
||||||
// and instead see `where T: Foo + Bar + Sized + 'a`
|
// and instead see `where T: Foo + Bar + Sized + 'a`
|
||||||
|
|
||||||
Generics {
|
Generics {
|
||||||
params: gens
|
params: stripped_params,
|
||||||
.params
|
|
||||||
.iter()
|
|
||||||
.flat_map(|param| match param.kind {
|
|
||||||
ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
|
|
||||||
ty::GenericParamDefKind::Type { .. } => None,
|
|
||||||
ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
|
|
||||||
})
|
|
||||||
.chain(simplify::ty_params(stripped_typarams).into_iter())
|
|
||||||
.collect(),
|
|
||||||
where_predicates: simplify::where_clauses(cx, where_predicates),
|
where_predicates: simplify::where_clauses(cx, where_predicates),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
//! bounds by special casing scenarios such as these. Fun!
|
//! bounds by special casing scenarios such as these. Fun!
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
@ -118,18 +117,6 @@ pub fn merge_bounds(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericParamDef> {
|
|
||||||
for param in &mut params {
|
|
||||||
match param.kind {
|
|
||||||
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
|
|
||||||
*bounds = mem::take(bounds);
|
|
||||||
}
|
|
||||||
_ => panic!("expected only type parameters"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
params
|
|
||||||
}
|
|
||||||
|
|
||||||
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) -> bool {
|
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) -> bool {
|
||||||
if child == trait_ {
|
if child == trait_ {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,8 +11,8 @@ pub enum Order {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
|
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
|
||||||
// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl<const ORDER: Order, T> Send for VSet<T, ORDER>'
|
// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
|
||||||
// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl<const ORDER: Order, T> Sync for VSet<T, ORDER>'
|
// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
|
||||||
pub struct VSet<T, const ORDER: Order> {
|
pub struct VSet<T, const ORDER: Order> {
|
||||||
inner: Vec<T>,
|
inner: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue