about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-07-23 12:28:27 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-07-23 12:29:05 +0200
commite41072479edd514ae6ebe00449ce4808204c5afb (patch)
tree654f2b47437c1622594c85cb1d6353dc09808da6
parent8a2e4262e88bede44cfc5a3ab54e5b88442d6ed2 (diff)
downloadrust-e41072479edd514ae6ebe00449ce4808204c5afb.tar.gz
rust-e41072479edd514ae6ebe00449ce4808204c5afb.zip
fix ICE caused by wrongly ordered generic params
-rw-r--r--src/librustc_resolve/late/lifetimes.rs5
-rw-r--r--src/librustc_typeck/collect.rs26
2 files changed, 22 insertions, 9 deletions
diff --git a/src/librustc_resolve/late/lifetimes.rs b/src/librustc_resolve/late/lifetimes.rs
index 6009e48a54f..658528b200d 100644
--- a/src/librustc_resolve/late/lifetimes.rs
+++ b/src/librustc_resolve/late/lifetimes.rs
@@ -1298,7 +1298,10 @@ fn object_lifetime_defaults_for_item(
             }
             GenericParamKind::Const { .. } => {
                 // Generic consts don't impose any constraints.
-                None
+                //
+                // We still store a dummy value here to allow generic paramters
+                // in arbitrary order.
+                Some(Set1::Empty)
             }
         })
         .collect()
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 5953863cb3c..c4734125e6f 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1888,14 +1888,24 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
     // Collect the predicates that were written inline by the user on each
     // type parameter (e.g., `<T: Foo>`).
     for param in ast_generics.params {
-        if let GenericParamKind::Type { .. } = param.kind {
-            let name = param.name.ident().name;
-            let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
-            index += 1;
-
-            let sized = SizedByDefault::Yes;
-            let bounds = AstConv::compute_bounds(&icx, param_ty, &param.bounds, sized, param.span);
-            predicates.extend(bounds.predicates(tcx, param_ty));
+        match param.kind {
+            // We already dealt with early bound lifetimes above.
+            GenericParamKind::Lifetime { .. } => (),
+            GenericParamKind::Type { .. } => {
+                let name = param.name.ident().name;
+                let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
+                index += 1;
+
+                let sized = SizedByDefault::Yes;
+                let bounds =
+                    AstConv::compute_bounds(&icx, param_ty, &param.bounds, sized, param.span);
+                predicates.extend(bounds.predicates(tcx, param_ty));
+            }
+            GenericParamKind::Const { .. } => {
+                // Bounds on const parameters are currently not possible.
+                debug_assert!(param.bounds.is_empty());
+                index += 1;
+            }
         }
     }