Skip to content

Commit e410724

Browse files
committed
fix ICE caused by wrongly ordered generic params
1 parent 8a2e426 commit e410724

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/librustc_resolve/late/lifetimes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,10 @@ fn object_lifetime_defaults_for_item(
12981298
}
12991299
GenericParamKind::Const { .. } => {
13001300
// Generic consts don't impose any constraints.
1301-
None
1301+
//
1302+
// We still store a dummy value here to allow generic paramters
1303+
// in arbitrary order.
1304+
Some(Set1::Empty)
13021305
}
13031306
})
13041307
.collect()

src/librustc_typeck/collect.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -1888,14 +1888,24 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
18881888
// Collect the predicates that were written inline by the user on each
18891889
// type parameter (e.g., `<T: Foo>`).
18901890
for param in ast_generics.params {
1891-
if let GenericParamKind::Type { .. } = param.kind {
1892-
let name = param.name.ident().name;
1893-
let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
1894-
index += 1;
1895-
1896-
let sized = SizedByDefault::Yes;
1897-
let bounds = AstConv::compute_bounds(&icx, param_ty, &param.bounds, sized, param.span);
1898-
predicates.extend(bounds.predicates(tcx, param_ty));
1891+
match param.kind {
1892+
// We already dealt with early bound lifetimes above.
1893+
GenericParamKind::Lifetime { .. } => (),
1894+
GenericParamKind::Type { .. } => {
1895+
let name = param.name.ident().name;
1896+
let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
1897+
index += 1;
1898+
1899+
let sized = SizedByDefault::Yes;
1900+
let bounds =
1901+
AstConv::compute_bounds(&icx, param_ty, &param.bounds, sized, param.span);
1902+
predicates.extend(bounds.predicates(tcx, param_ty));
1903+
}
1904+
GenericParamKind::Const { .. } => {
1905+
// Bounds on const parameters are currently not possible.
1906+
debug_assert!(param.bounds.is_empty());
1907+
index += 1;
1908+
}
18991909
}
19001910
}
19011911

0 commit comments

Comments
 (0)