Skip to content

Commit 98a9397

Browse files
authored
Rollup merge of #74992 - lcnr:fix-generic-param-order, r=GuillaumeGomez
fix rustdoc generic param order fixes #61292 r? @varkor cc @GuillaumeGomez
2 parents fac959b + b90bc8d commit 98a9397

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

src/librustdoc/clean/auto_trait.rs

+5
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
480480
.clean(self.cx)
481481
.params;
482482

483+
debug!(
484+
"param_env_to_generics({:?}): generic_params={:?}",
485+
param_env_def_id, generic_params
486+
);
487+
483488
let mut has_sized = FxHashSet::default();
484489
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
485490
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();

src/librustdoc/clean/mod.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,11 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
716716
// Bounds in the type_params and lifetimes fields are repeated in the
717717
// predicates field (see rustc_typeck::collect::ty_generics), so remove
718718
// them.
719-
let stripped_typarams = gens
719+
let stripped_params = gens
720720
.params
721721
.iter()
722722
.filter_map(|param| match param.kind {
723-
ty::GenericParamDefKind::Lifetime => None,
723+
ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
724724
ty::GenericParamDefKind::Type { synthetic, .. } => {
725725
if param.name == kw::SelfUpper {
726726
assert_eq!(param.index, 0);
@@ -732,7 +732,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
732732
}
733733
Some(param.clean(cx))
734734
}
735-
ty::GenericParamDefKind::Const { .. } => None,
735+
ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
736736
})
737737
.collect::<Vec<GenericParamDef>>();
738738

@@ -844,8 +844,10 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
844844

845845
// Run through the type parameters again and insert a ?Sized
846846
// unbound for any we didn't find to be Sized.
847-
for tp in &stripped_typarams {
848-
if !sized_params.contains(&tp.name) {
847+
for tp in &stripped_params {
848+
if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
849+
&& !sized_params.contains(&tp.name)
850+
{
849851
where_predicates.push(WP::BoundPredicate {
850852
ty: Type::Generic(tp.name.clone()),
851853
bounds: vec![GenericBound::maybe_sized(cx)],
@@ -858,16 +860,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
858860
// and instead see `where T: Foo + Bar + Sized + 'a`
859861

860862
Generics {
861-
params: gens
862-
.params
863-
.iter()
864-
.flat_map(|param| match param.kind {
865-
ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
866-
ty::GenericParamDefKind::Type { .. } => None,
867-
ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
868-
})
869-
.chain(simplify::ty_params(stripped_typarams).into_iter())
870-
.collect(),
863+
params: stripped_params,
871864
where_predicates: simplify::where_clauses(cx, where_predicates),
872865
}
873866
}

src/librustdoc/clean/simplify.rs

-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! bounds by special casing scenarios such as these. Fun!
1313
1414
use std::collections::BTreeMap;
15-
use std::mem;
1615

1716
use rustc_hir::def_id::DefId;
1817
use rustc_middle::ty;
@@ -118,18 +117,6 @@ pub fn merge_bounds(
118117
})
119118
}
120119

121-
pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericParamDef> {
122-
for param in &mut params {
123-
match param.kind {
124-
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
125-
*bounds = mem::take(bounds);
126-
}
127-
_ => panic!("expected only type parameters"),
128-
}
129-
}
130-
params
131-
}
132-
133120
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) -> bool {
134121
if child == trait_ {
135122
return true;

src/test/rustdoc/const-generics/const-impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub enum Order {
1111
}
1212

1313
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
14-
// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl<const ORDER: Order, T> Send for VSet<T, ORDER>'
15-
// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl<const ORDER: Order, T> Sync for VSet<T, ORDER>'
14+
// @has foo/struct.VSet.html '//h3[@id="impl-Send"]/code' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
15+
// @has foo/struct.VSet.html '//h3[@id="impl-Sync"]/code' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
1616
pub struct VSet<T, const ORDER: Order> {
1717
inner: Vec<T>,
1818
}

0 commit comments

Comments
 (0)