]> git.lizzy.rs Git - rust.git/commitdiff
fix rustdoc generic param order
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Fri, 31 Jul 2020 21:51:19 +0000 (23:51 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Fri, 31 Jul 2020 21:51:19 +0000 (23:51 +0200)
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/mod.rs
src/librustdoc/clean/simplify.rs
src/test/rustdoc/const-generics/const-impl.rs

index b170b4131464af2947f850c7ffd99ee989ad5109..9c44d27447db8614445e2073acb3a640db25f426 100644 (file)
@@ -480,6 +480,11 @@ fn param_env_to_generics(
                 .clean(self.cx)
                 .params;
 
+        debug!(
+            "param_env_to_generics({:?}): generic_params={:?}",
+            param_env_def_id, generic_params
+        );
+
         let mut has_sized = FxHashSet::default();
         let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
         let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
index cc3a60c596ae7a321cdafc3e6b4acd789129d149..5b048372624a4a9ff399d552cac939cc5350804f 100644 (file)
@@ -716,11 +716,11 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
         // Bounds in the type_params and lifetimes fields are repeated in the
         // predicates field (see rustc_typeck::collect::ty_generics), so remove
         // them.
-        let stripped_typarams = gens
+        let stripped_params = gens
             .params
             .iter()
             .filter_map(|param| match param.kind {
-                ty::GenericParamDefKind::Lifetime => None,
+                ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
                 ty::GenericParamDefKind::Type { synthetic, .. } => {
                     if param.name == kw::SelfUpper {
                         assert_eq!(param.index, 0);
@@ -732,7 +732,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
                     }
                     Some(param.clean(cx))
                 }
-                ty::GenericParamDefKind::Const { .. } => None,
+                ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
             })
             .collect::<Vec<GenericParamDef>>();
 
@@ -844,8 +844,10 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
 
         // Run through the type parameters again and insert a ?Sized
         // unbound for any we didn't find to be Sized.
-        for tp in &stripped_typarams {
-            if !sized_params.contains(&tp.name) {
+        for tp in &stripped_params {
+            if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
+                && !sized_params.contains(&tp.name)
+            {
                 where_predicates.push(WP::BoundPredicate {
                     ty: Type::Generic(tp.name.clone()),
                     bounds: vec![GenericBound::maybe_sized(cx)],
@@ -858,16 +860,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
         // and instead see `where T: Foo + Bar + Sized + 'a`
 
         Generics {
-            params: gens
-                .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(),
+            params: stripped_params,
             where_predicates: simplify::where_clauses(cx, where_predicates),
         }
     }
index 0f995a60c22fd06d0247391a850ad588524251ef..990189f6ea04dd54da709737eaa198fdab113635 100644 (file)
@@ -12,7 +12,6 @@
 //! bounds by special casing scenarios such as these. Fun!
 
 use std::collections::BTreeMap;
-use std::mem;
 
 use rustc_hir::def_id::DefId;
 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 {
     if child == trait_ {
         return true;
index 7361b22b7479842533420cd5c9685094677b2884..03f5bb2ca4374784065e047691780d914f9b4720 100644 (file)
@@ -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 '//h3[@id="impl-Send"]/code' 'impl<const ORDER: Order, T> 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-Send"]/code' 'impl<T, const ORDER: Order> Send 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> {
     inner: Vec<T>,
 }