mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
loosen ordering restricts for const_generics_defaults
This commit is contained in:
parent
259a368e9e
commit
7cb1dcd488
@ -754,7 +754,7 @@ fn validate_generic_param_order(
|
||||
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
|
||||
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
|
||||
let ty = pprust::ty_to_string(ty);
|
||||
let unordered = sess.features_untracked().const_generics;
|
||||
let unordered = sess.features_untracked().unordered_const_ty_params();
|
||||
(ParamKindOrd::Const { unordered }, Some(format!("const {}: {}", param.ident, ty)))
|
||||
}
|
||||
};
|
||||
|
@ -63,6 +63,10 @@ macro_rules! declare_features {
|
||||
_ => panic!("`{}` was not listed in `declare_features`", feature),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unordered_const_ty_params(&self) -> bool {
|
||||
self.const_generics || self.const_generics_defaults
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -296,7 +296,9 @@ impl GenericArg<'_> {
|
||||
match self {
|
||||
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
|
||||
GenericArg::Type(_) => ast::ParamKindOrd::Type,
|
||||
GenericArg::Const(_) => ast::ParamKindOrd::Const { unordered: feats.const_generics },
|
||||
GenericArg::Const(_) => {
|
||||
ast::ParamKindOrd::Const { unordered: feats.unordered_const_ty_params() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ impl GenericParamDefKind {
|
||||
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
|
||||
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
ast::ParamKindOrd::Const { unordered: tcx.features().const_generics }
|
||||
ast::ParamKindOrd::Const { unordered: tcx.features().unordered_const_ty_params() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
ParamKindOrd::Const {
|
||||
unordered: tcx
|
||||
.features()
|
||||
.const_generics,
|
||||
.unordered_const_ty_params(),
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -309,7 +309,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
|
||||
GenericArg::Type(_) => ParamKindOrd::Type,
|
||||
GenericArg::Const(_) => ParamKindOrd::Const {
|
||||
unordered: tcx.features().const_generics,
|
||||
unordered: tcx
|
||||
.features()
|
||||
.unordered_const_ty_params(),
|
||||
},
|
||||
}),
|
||||
Some(&format!(
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(const_generics)]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
||||
--> $DIR/complex-generic-default-expr.rs:6:62
|
||||
--> $DIR/complex-generic-default-expr.rs:9:62
|
||||
|
|
||||
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
|
||||
| - ^ doesn't have a size known at compile-time
|
@ -0,0 +1,20 @@
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/complex-generic-default-expr.rs:6:47
|
||||
|
|
||||
LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
|
||||
| ^ cannot perform const operation using `N`
|
||||
|
|
||||
= help: const parameters may only be used as standalone arguments, i.e. `N`
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/complex-generic-default-expr.rs:9:62
|
||||
|
|
||||
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
|
||||
| ^ cannot perform const operation using `T`
|
||||
|
|
||||
= note: type parameters may not be used in const expressions
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -1,9 +1,13 @@
|
||||
#![feature(const_generics, const_generics_defaults)]
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Foo<const N: usize, const M: usize = { N + 1 }>;
|
||||
//[min]~^ ERROR generic parameters may not be used in const operations
|
||||
|
||||
struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
|
||||
//~^ ERROR the size for values of type `T` cannot be known at compilation time
|
||||
//[min]~^ ERROR generic parameters may not be used in const operations
|
||||
//[full]~^^ ERROR the size for values of type `T` cannot be known at compilation time
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(const_generics)]
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
--> $DIR/default-on-impl.rs:6:12
|
||||
--> $DIR/default-on-impl.rs:8:12
|
||||
|
|
||||
LL | impl<const N: usize = 1> Foo<N> {}
|
||||
| ^
|
@ -0,0 +1,8 @@
|
||||
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
--> $DIR/default-on-impl.rs:8:12
|
||||
|
|
||||
LL | impl<const N: usize = 1> Foo<N> {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,4 +1,6 @@
|
||||
#![feature(const_generics, const_generics_defaults)]
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Foo<const N: usize>;
|
||||
|
@ -1,5 +1,7 @@
|
||||
// aux-build:const_defaulty.rs
|
||||
// check-pass
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/intermixed-lifetime.rs:6:28
|
||||
--> $DIR/intermixed-lifetime.rs:7:28
|
||||
|
|
||||
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
|
||||
|
@ -1,26 +1,14 @@
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/intermixed-lifetime.rs:6:28
|
||||
--> $DIR/intermixed-lifetime.rs:7:28
|
||||
|
|
||||
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = u32, const N: usize>`
|
||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
||||
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/intermixed-lifetime.rs:6:32
|
||||
|
|
||||
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||
| ---------------------^------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = u32, const N: usize>`
|
||||
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
error: lifetime parameters must be declared prior to type parameters
|
||||
--> $DIR/intermixed-lifetime.rs:10:37
|
||||
|
|
||||
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
||||
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = u32, const N: usize>`
|
||||
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
||||
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/intermixed-lifetime.rs:10:28
|
||||
|
|
||||
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
||||
| -----------------^----------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = u32, const N: usize>`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
// revisions: full min
|
||||
// Checks that lifetimes cannot be interspersed between consts and types.
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||
//~^ Error lifetime parameters must be declared prior to const parameters
|
||||
//[min]~^^ Error type parameters must be declared prior to const parameters
|
||||
|
||||
struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
||||
//[full]~^ Error lifetime parameters must be declared prior to type parameters
|
||||
//[min]~^^ Error type parameters must be declared prior to const parameters
|
||||
//[min]~| Error lifetime parameters must be declared prior to const parameters
|
||||
//~^ Error lifetime parameters must be declared prior to type parameters
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:11:28
|
||||
--> $DIR/mismatch.rs:12:28
|
||||
|
|
||||
LL | let e: Example::<13> = ();
|
||||
| ------------- ^^ expected struct `Example`, found `()`
|
||||
@ -7,7 +7,7 @@ LL | let e: Example::<13> = ();
|
||||
| expected due to this
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:13:34
|
||||
--> $DIR/mismatch.rs:14:34
|
||||
|
|
||||
LL | let e: Example2::<u32, 13> = ();
|
||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||
@ -18,7 +18,7 @@ LL | let e: Example2::<u32, 13> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:15:34
|
||||
--> $DIR/mismatch.rs:16:34
|
||||
|
|
||||
LL | let e: Example3::<13, u32> = ();
|
||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -29,7 +29,7 @@ LL | let e: Example3::<13, u32> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:17:28
|
||||
--> $DIR/mismatch.rs:18:28
|
||||
|
|
||||
LL | let e: Example3::<7> = ();
|
||||
| ------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -40,7 +40,7 @@ LL | let e: Example3::<7> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:21:28
|
||||
--> $DIR/mismatch.rs:22:28
|
||||
|
|
||||
LL | let e: Example4::<7> = ();
|
||||
| ------------- ^^ expected struct `Example4`, found `()`
|
52
src/test/ui/const-generics/defaults/mismatch.min.stderr
Normal file
52
src/test/ui/const-generics/defaults/mismatch.min.stderr
Normal file
@ -0,0 +1,52 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:12:28
|
||||
|
|
||||
LL | let e: Example::<13> = ();
|
||||
| ------------- ^^ expected struct `Example`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:14:34
|
||||
|
|
||||
LL | let e: Example2::<u32, 13> = ();
|
||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example2`
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:16:34
|
||||
|
|
||||
LL | let e: Example3::<13, u32> = ();
|
||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example3`
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:18:28
|
||||
|
|
||||
LL | let e: Example3::<7> = ();
|
||||
| ------------- ^^ expected struct `Example3`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example3<7_usize>`
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:22:28
|
||||
|
|
||||
LL | let e: Example4::<7> = ();
|
||||
| ------------- ^^ expected struct `Example4`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -1,4 +1,5 @@
|
||||
#![feature(const_generics)]
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
@ -18,4 +18,3 @@ fn foo<const SIZE : usize = 5>() { }
|
||||
|
||||
struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize =
|
||||
FROM>;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Loaf<T: Sized, const N: usize = 1usize> {
|
||||
pub struct Loaf<T: Sized, const N: usize = 1> {
|
||||
head: [T; N],
|
||||
slice: [T],
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/simple-defaults.rs:8:40
|
||||
|
|
||||
LL | struct FixedOutput<'a, const N: usize, T=u32> {
|
||||
| ---------------------^----- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = u32, const N: usize>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,12 +1,12 @@
|
||||
// [full] run-pass
|
||||
// revisions: min full
|
||||
// Checks some basic test cases for defaults.
|
||||
// run-pass
|
||||
// Checks that type param defaults are allowed after const params.
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
struct FixedOutput<'a, const N: usize, T=u32> {
|
||||
//[min]~^ ERROR type parameters must be declared prior to const parameters
|
||||
out: &'a [T; N],
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
// check-pass
|
||||
#![feature(const_generics, const_generics_defaults)]
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct N;
|
||||
|
@ -1,19 +1,8 @@
|
||||
error: generic parameters with a default must be trailing
|
||||
--> $DIR/wrong-order.rs:4:10
|
||||
--> $DIR/wrong-order.rs:6:10
|
||||
|
|
||||
LL | struct A<T = u32, const N: usize> {
|
||||
| ^
|
||||
|
|
||||
= note: using type defaults and const parameters in the same parameter list is currently not permitted
|
||||
|
||||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/wrong-order.rs:2:27
|
||||
|
|
||||
LL | #![cfg_attr(full, feature(const_generics))]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
error: generic parameters with a default must be trailing
|
||||
--> $DIR/wrong-order.rs:4:10
|
||||
--> $DIR/wrong-order.rs:6:10
|
||||
|
|
||||
LL | struct A<T = u32, const N: usize> {
|
||||
| ^
|
||||
|
|
||||
= note: using type defaults and const parameters in the same parameter list is currently not permitted
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct A<T = u32, const N: usize> {
|
||||
//~^ ERROR generic parameters with a default must be trailing
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: generic parameters with a default must be trailing
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:12
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:12
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^
|
||||
@ -7,7 +7,7 @@ LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
= note: using type defaults and const parameters in the same parameter list is currently not permitted
|
||||
|
||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:21
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:21
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^ defaulted generic parameters cannot be forward declared
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: generic parameters with a default must be trailing
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:12
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:12
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^
|
||||
@ -16,7 +16,7 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:21
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:21
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^ defaulted generic parameters cannot be forward declared
|
||||
|
@ -7,7 +7,6 @@ struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||
//[full]~^ ERROR the size for values of type `T` cannot be known at compilation time
|
||||
//[min]~^^ ERROR generic parameters may not be used in const operations
|
||||
|
||||
// FIXME(const_generics_defaults): We still don't know how to deal with type defaults.
|
||||
struct Bar<T = [u8; N], const N: usize>(T);
|
||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
||||
//~| ERROR generic parameters with a default
|
||||
|
Loading…
Reference in New Issue
Block a user