diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-23 12:28:27 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-23 12:29:05 +0200 |
| commit | e41072479edd514ae6ebe00449ce4808204c5afb (patch) | |
| tree | 654f2b47437c1622594c85cb1d6353dc09808da6 | |
| parent | 8a2e4262e88bede44cfc5a3ab54e5b88442d6ed2 (diff) | |
| download | rust-e41072479edd514ae6ebe00449ce4808204c5afb.tar.gz rust-e41072479edd514ae6ebe00449ce4808204c5afb.zip | |
fix ICE caused by wrongly ordered generic params
| -rw-r--r-- | src/librustc_resolve/late/lifetimes.rs | 5 | ||||
| -rw-r--r-- | src/librustc_typeck/collect.rs | 26 |
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, ¶m.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, ¶m.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; + } } } |
