Skip to content

Commit 7cb1dcd

Browse files
committed
loosen ordering restricts for const_generics_defaults
1 parent 259a368 commit 7cb1dcd

31 files changed

+145
-81
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ fn validate_generic_param_order(
754754
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
755755
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
756756
let ty = pprust::ty_to_string(ty);
757-
let unordered = sess.features_untracked().const_generics;
757+
let unordered = sess.features_untracked().unordered_const_ty_params();
758758
(ParamKindOrd::Const { unordered }, Some(format!("const {}: {}", param.ident, ty)))
759759
}
760760
};

compiler/rustc_feature/src/active.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ macro_rules! declare_features {
6363
_ => panic!("`{}` was not listed in `declare_features`", feature),
6464
}
6565
}
66+
67+
pub fn unordered_const_ty_params(&self) -> bool {
68+
self.const_generics || self.const_generics_defaults
69+
}
6670
}
6771
};
6872
}

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ impl GenericArg<'_> {
296296
match self {
297297
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
298298
GenericArg::Type(_) => ast::ParamKindOrd::Type,
299-
GenericArg::Const(_) => ast::ParamKindOrd::Const { unordered: feats.const_generics },
299+
GenericArg::Const(_) => {
300+
ast::ParamKindOrd::Const { unordered: feats.unordered_const_ty_params() }
301+
}
300302
}
301303
}
302304
}

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl GenericParamDefKind {
3636
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
3737
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
3838
GenericParamDefKind::Const { .. } => {
39-
ast::ParamKindOrd::Const { unordered: tcx.features().const_generics }
39+
ast::ParamKindOrd::Const { unordered: tcx.features().unordered_const_ty_params() }
4040
}
4141
}
4242
}

compiler/rustc_typeck/src/astconv/generics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
286286
ParamKindOrd::Const {
287287
unordered: tcx
288288
.features()
289-
.const_generics,
289+
.unordered_const_ty_params(),
290290
}
291291
}
292292
},
@@ -309,7 +309,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
309309
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
310310
GenericArg::Type(_) => ParamKindOrd::Type,
311311
GenericArg::Const(_) => ParamKindOrd::Const {
312-
unordered: tcx.features().const_generics,
312+
unordered: tcx
313+
.features()
314+
.unordered_const_ty_params(),
313315
},
314316
}),
315317
Some(&format!(

src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(const_generics)]
1+
#![cfg_attr(full, feature(const_generics))]
22
#![feature(const_generics_defaults)]
33
#![allow(incomplete_features)]
44

src/test/ui/const-generics/defaults/complex-generic-default-expr.stderr renamed to src/test/ui/const-generics/defaults/complex-generic-default-expr.full.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the size for values of type `T` cannot be known at compilation time
2-
--> $DIR/complex-generic-default-expr.rs:6:62
2+
--> $DIR/complex-generic-default-expr.rs:9:62
33
|
44
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
55
| - ^ doesn't have a size known at compile-time
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: generic parameters may not be used in const operations
2+
--> $DIR/complex-generic-default-expr.rs:6:47
3+
|
4+
LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
5+
| ^ cannot perform const operation using `N`
6+
|
7+
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
9+
10+
error: generic parameters may not be used in const operations
11+
--> $DIR/complex-generic-default-expr.rs:9:62
12+
|
13+
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
14+
| ^ cannot perform const operation using `T`
15+
|
16+
= note: type parameters may not be used in const expressions
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
18+
19+
error: aborting due to 2 previous errors
20+
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#![feature(const_generics, const_generics_defaults)]
1+
// revisions: full min
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![feature(const_generics_defaults)]
24
#![allow(incomplete_features)]
35

46
struct Foo<const N: usize, const M: usize = { N + 1 }>;
7+
//[min]~^ ERROR generic parameters may not be used in const operations
58

69
struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
7-
//~^ ERROR the size for values of type `T` cannot be known at compilation time
10+
//[min]~^ ERROR generic parameters may not be used in const operations
11+
//[full]~^^ ERROR the size for values of type `T` cannot be known at compilation time
812

913
fn main() {}

src/test/ui/const-generics/defaults/const-default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
2-
3-
#![feature(const_generics)]
2+
// revisions: full min
3+
#![cfg_attr(full, feature(const_generics))]
44
#![feature(const_generics_defaults)]
55
#![allow(incomplete_features)]
66

0 commit comments

Comments
 (0)