Skip to content

Commit 8a2e426

Browse files
committed
stop sorting generic params
1 parent fcac119 commit 8a2e426

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -936,20 +936,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
936936
})
937937
});
938938

939-
let mut lowered_params: Vec<_> =
940-
lowered_generics.params.into_iter().chain(in_band_defs).collect();
941-
942-
// FIXME(const_generics): the compiler doesn't always cope with
943-
// unsorted generic parameters at the moment, so we make sure
944-
// that they're ordered correctly here for now. (When we chain
945-
// the `in_band_defs`, we might make the order unsorted.)
946-
lowered_params.sort_by_key(|param| match param.kind {
947-
hir::GenericParamKind::Lifetime { .. } => ParamKindOrd::Lifetime,
948-
hir::GenericParamKind::Type { .. } => ParamKindOrd::Type,
949-
hir::GenericParamKind::Const { .. } => ParamKindOrd::Const,
950-
});
951-
952-
lowered_generics.params = lowered_params.into();
939+
lowered_generics.params = lowered_generics.params.into_iter().chain(in_band_defs).collect();
953940

954941
let lowered_generics = lowered_generics.into_generics(self.arena);
955942
(lowered_generics, res)

src/librustc_typeck/collect.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,13 +1362,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13621362
let type_start = own_start - has_self as u32 + params.len() as u32;
13631363
let mut i = 0;
13641364

1365-
// FIXME(const_generics): a few places in the compiler expect generic params
1366-
// to be in the order lifetimes, then type params, then const params.
1367-
//
1368-
// To prevent internal errors in case const parameters are supplied before
1369-
// type parameters we first add all type params, then all const params.
1370-
params.extend(ast_generics.params.iter().filter_map(|param| {
1371-
if let GenericParamKind::Type { ref default, synthetic, .. } = param.kind {
1365+
params.extend(ast_generics.params.iter().filter_map(|param| match param.kind {
1366+
GenericParamKind::Lifetime { .. } => None,
1367+
GenericParamKind::Type { ref default, synthetic, .. } => {
13721368
if !allow_defaults && default.is_some() {
13731369
if !tcx.features().default_type_parameter_fallback {
13741370
tcx.struct_span_lint_hir(
@@ -1378,7 +1374,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13781374
|lint| {
13791375
lint.build(
13801376
"defaults for type parameters are only allowed in \
1381-
`struct`, `enum`, `type`, or `trait` definitions.",
1377+
`struct`, `enum`, `type`, or `trait` definitions.",
13821378
)
13831379
.emit();
13841380
},
@@ -1403,13 +1399,8 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
14031399
};
14041400
i += 1;
14051401
Some(param_def)
1406-
} else {
1407-
None
14081402
}
1409-
}));
1410-
1411-
params.extend(ast_generics.params.iter().filter_map(|param| {
1412-
if let GenericParamKind::Const { .. } = param.kind {
1403+
GenericParamKind::Const { .. } => {
14131404
let param_def = ty::GenericParamDef {
14141405
index: type_start + i as u32,
14151406
name: param.name.ident().name,
@@ -1419,8 +1410,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
14191410
};
14201411
i += 1;
14211412
Some(param_def)
1422-
} else {
1423-
None
14241413
}
14251414
}));
14261415

0 commit comments

Comments
 (0)