diff options
Diffstat (limited to 'src/test/ui/const-generics')
96 files changed, 841 insertions, 277 deletions
diff --git a/src/test/ui/const-generics/argument_order.min.stderr b/src/test/ui/const-generics/argument_order.min.stderr deleted file mode 100644 index afd9ed1a723..00000000000 --- a/src/test/ui/const-generics/argument_order.min.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:4:28 - | -LL | struct Bad<const N: usize, T> { - | -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>` - -error: lifetime parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:10:32 - | -LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> { - | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>` - -error: type parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:10:36 - | -LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> { - | ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>` - -error[E0747]: lifetime provided when a type was expected - --> $DIR/argument_order.rs:18:23 - | -LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; - | ^^^^^^^ - | - = note: lifetime arguments must be provided before type arguments - = help: reorder the arguments: lifetimes, then types, then consts: `<'a, 'b, T, U, N, M>` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/const-generics/argument_order.rs b/src/test/ui/const-generics/argument_order.rs index 97dd0f14352..196d9b8a1e2 100644 --- a/src/test/ui/const-generics/argument_order.rs +++ b/src/test/ui/const-generics/argument_order.rs @@ -1,15 +1,10 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics_defaults))] - struct Bad<const N: usize, T> { - //[min]~^ ERROR type parameters must be declared prior to const parameters arr: [u8; { N }], another: T, } struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> { //~^ ERROR lifetime parameters must be declared prior - //[min]~^^ ERROR type parameters must be declared prior to const parameters a: &'a T, b: &'b U, } diff --git a/src/test/ui/const-generics/argument_order.full.stderr b/src/test/ui/const-generics/argument_order.stderr index 9762748f441..6b33dffb434 100644 --- a/src/test/ui/const-generics/argument_order.full.stderr +++ b/src/test/ui/const-generics/argument_order.stderr @@ -1,11 +1,11 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:10:32 + --> $DIR/argument_order.rs:6:32 | LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> { | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>` error[E0747]: lifetime provided when a type was expected - --> $DIR/argument_order.rs:18:23 + --> $DIR/argument_order.rs:13:23 | LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; | ^^^^^^^ diff --git a/src/test/ui/const-generics/associated-type-bound-fail.stderr b/src/test/ui/const-generics/associated-type-bound-fail.stderr index 60e624fc6a8..9dc677ef6ed 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `u16: Bar<N>` is not satisfied - --> $DIR/associated-type-bound-fail.rs:9:5 + --> $DIR/associated-type-bound-fail.rs:9:18 | LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16` + | ^^^ the trait `Bar<N>` is not implemented for `u16` | = help: the following implementations were found: <u16 as Bar<3_usize>> diff --git a/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr b/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr index 104ee9b48b4..4e12f7a8c6e 100644 --- a/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr +++ b/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr @@ -3,9 +3,6 @@ error[E0747]: constant provided when a type was expected | LL | fn foo<const N: usize>() -> Array<N, ()> { | ^ - | - = note: type arguments must be provided before constant arguments - = help: reorder the arguments: types, then consts: `<T, N>` error: aborting due to previous error diff --git a/src/test/ui/const-generics/const-param-before-other-params.min.stderr b/src/test/ui/const-generics/const-param-before-other-params.min.stderr deleted file mode 100644 index f439cd9d69f..00000000000 --- a/src/test/ui/const-generics/const-param-before-other-params.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: lifetime parameters must be declared prior to const parameters - --> $DIR/const-param-before-other-params.rs:5:21 - | -LL | fn bar<const X: u8, 'a>(_: &'a ()) { - | --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: u8>` - -error: type parameters must be declared prior to const parameters - --> $DIR/const-param-before-other-params.rs:9:21 - | -LL | fn foo<const X: u8, T>(_: &T) {} - | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: u8>` - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index 0a7b57fe626..da06aca308e 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -1,12 +1,7 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics_defaults))] -#![cfg_attr(full, allow(incomplete_features))] - fn bar<const X: u8, 'a>(_: &'a ()) { //~^ ERROR lifetime parameters must be declared prior to const parameters } fn foo<const X: u8, T>(_: &T) {} -//[min]~^ ERROR type parameters must be declared prior to const parameters fn main() {} diff --git a/src/test/ui/const-generics/const-param-before-other-params.full.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 982417eb3c6..607d20c4a25 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.full.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -1,5 +1,5 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/const-param-before-other-params.rs:5:21 + --> $DIR/const-param-before-other-params.rs:1:21 | LL | fn bar<const X: u8, 'a>(_: &'a ()) { | --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: u8>` diff --git a/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs b/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs index 5c548740af2..eed982534c2 100644 --- a/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs +++ b/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - pub struct Defaulted<const N: usize=3>; impl Defaulted { pub fn new() -> Self { diff --git a/src/test/ui/const-generics/defaults/auxiliary/trait_object_lt_defaults_lib.rs b/src/test/ui/const-generics/defaults/auxiliary/trait_object_lt_defaults_lib.rs new file mode 100644 index 00000000000..26a2c47ffb2 --- /dev/null +++ b/src/test/ui/const-generics/defaults/auxiliary/trait_object_lt_defaults_lib.rs @@ -0,0 +1 @@ +pub struct Foo<'a, const N: usize, T: 'a + ?Sized>(pub &'a T, [(); N]); diff --git a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr index aa289ec0778..b836cfeaedb 100644 --- a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr +++ b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr @@ -1,5 +1,5 @@ error: generic parameters may not be used in const operations - --> $DIR/complex-generic-default-expr.rs:7:47 + --> $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` @@ -8,7 +8,7 @@ LL | struct Foo<const N: usize, const M: usize = { N + 1 }>; = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/complex-generic-default-expr.rs:10:62 + --> $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` diff --git a/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs b/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs index 814c996fbad..7f50d4c9f29 100644 --- a/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs +++ b/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs @@ -1,8 +1,7 @@ // revisions: full min //[full] check-pass #![cfg_attr(full, feature(generic_const_exprs))] -#![feature(const_generics_defaults)] -#![allow(incomplete_features)] +#![cfg_attr(full, allow(incomplete_features))] struct Foo<const N: usize, const M: usize = { N + 1 }>; //[min]~^ ERROR generic parameters may not be used in const operations diff --git a/src/test/ui/const-generics/defaults/complex-unord-param.rs b/src/test/ui/const-generics/defaults/complex-unord-param.rs index c27ed298afd..aebc5975a5a 100644 --- a/src/test/ui/const-generics/defaults/complex-unord-param.rs +++ b/src/test/ui/const-generics/defaults/complex-unord-param.rs @@ -1,12 +1,8 @@ -// [full] run-pass -// revisions: full min +// run-pass // Checks a complicated usage of unordered params -#![cfg_attr(full, feature(const_generics_defaults))] -#![cfg_attr(full, allow(incomplete_features))] #![allow(dead_code)] struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> { - //[min]~^ ERROR type parameters must be declared prior to const parameters args: &'a [&'a [T; M]; N], specifier: A, } diff --git a/src/test/ui/const-generics/defaults/const-default.rs b/src/test/ui/const-generics/defaults/const-default.rs index e7cbf01a301..65cb0eb14a3 100644 --- a/src/test/ui/const-generics/defaults/const-default.rs +++ b/src/test/ui/const-generics/defaults/const-default.rs @@ -1,6 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] - pub struct ConstDefault<const N: usize = 3>; impl<const N: usize> ConstDefault<N> { diff --git a/src/test/ui/const-generics/defaults/const-param-as-default-value.rs b/src/test/ui/const-generics/defaults/const-param-as-default-value.rs index 9779835d315..c1c955d8758 100644 --- a/src/test/ui/const-generics/defaults/const-param-as-default-value.rs +++ b/src/test/ui/const-generics/defaults/const-param-as-default-value.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] struct Foo<const N: usize, const M: usize = N>([u8; N], [u8; M]); fn foo<const N: usize>() -> Foo<N> { diff --git a/src/test/ui/const-generics/defaults/const-param-in-ty-defaults.rs b/src/test/ui/const-generics/defaults/const-param-in-ty-defaults.rs index dbcab77dcd2..5f0cafe2ef1 100644 --- a/src/test/ui/const-generics/defaults/const-param-in-ty-defaults.rs +++ b/src/test/ui/const-generics/defaults/const-param-in-ty-defaults.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] struct Foo<const N: usize, T = [u8; N]>(T); impl<const N: usize> Foo<N> { diff --git a/src/test/ui/const-generics/defaults/default-annotation.rs b/src/test/ui/const-generics/defaults/default-annotation.rs index 5517bf8ac5f..7a9f5732f7f 100644 --- a/src/test/ui/const-generics/defaults/default-annotation.rs +++ b/src/test/ui/const-generics/defaults/default-annotation.rs @@ -1,6 +1,5 @@ // run-pass #![feature(staged_api)] -#![feature(const_generics_defaults)] #![allow(incomplete_features)] // FIXME(const_generics_defaults): It seems like we aren't testing the right thing here, // I would assume that we want the attributes to apply to the const parameter defaults diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs index 9af84439252..45275e60920 100644 --- a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct Struct<const N: usize = { Self; 10 }>; //~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr index 5dfec2fcb73..72d7001fdf1 100644 --- a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr @@ -1,17 +1,17 @@ error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:3:34 + --> $DIR/default-const-param-cannot-reference-self.rs:1:34 | LL | struct Struct<const N: usize = { Self; 10 }>; | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:6:30 + --> $DIR/default-const-param-cannot-reference-self.rs:4:30 | LL | enum Enum<const N: usize = { Self; 10 }> { } | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:9:32 + --> $DIR/default-const-param-cannot-reference-self.rs:7:32 | LL | union Union<const N: usize = { Self; 10 }> { not_empty: () } | ^^^^ `Self` in generic parameter default diff --git a/src/test/ui/const-generics/defaults/default-on-impl.rs b/src/test/ui/const-generics/defaults/default-on-impl.rs index 280d92f839f..9ce46aa09de 100644 --- a/src/test/ui/const-generics/defaults/default-on-impl.rs +++ b/src/test/ui/const-generics/defaults/default-on-impl.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct Foo<const N: usize>; impl<const N: usize = 1> Foo<N> {} diff --git a/src/test/ui/const-generics/defaults/default-on-impl.stderr b/src/test/ui/const-generics/defaults/default-on-impl.stderr index 0f85ceccc8a..ddfc0ead8ad 100644 --- a/src/test/ui/const-generics/defaults/default-on-impl.stderr +++ b/src/test/ui/const-generics/defaults/default-on-impl.stderr @@ -1,5 +1,5 @@ error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default-on-impl.rs:5:12 + --> $DIR/default-on-impl.rs:3:12 | LL | impl<const N: usize = 1> Foo<N> {} | ^ diff --git a/src/test/ui/const-generics/defaults/default-param-wf-concrete.rs b/src/test/ui/const-generics/defaults/default-param-wf-concrete.rs index d4271adefd1..41a52c7eb0d 100644 --- a/src/test/ui/const-generics/defaults/default-param-wf-concrete.rs +++ b/src/test/ui/const-generics/defaults/default-param-wf-concrete.rs @@ -1,4 +1,3 @@ -#![feature(const_generics_defaults)] struct Foo<const N: u8 = { 255 + 1 }>; //~^ ERROR evaluation of constant value failed fn main() {} diff --git a/src/test/ui/const-generics/defaults/default-param-wf-concrete.stderr b/src/test/ui/const-generics/defaults/default-param-wf-concrete.stderr index 6fca9d31c0a..e8ebddade5c 100644 --- a/src/test/ui/const-generics/defaults/default-param-wf-concrete.stderr +++ b/src/test/ui/const-generics/defaults/default-param-wf-concrete.stderr @@ -1,5 +1,5 @@ error[E0080]: evaluation of constant value failed - --> $DIR/default-param-wf-concrete.rs:2:28 + --> $DIR/default-param-wf-concrete.rs:1:28 | LL | struct Foo<const N: u8 = { 255 + 1 }>; | ^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow diff --git a/src/test/ui/const-generics/defaults/doesnt_infer.rs b/src/test/ui/const-generics/defaults/doesnt_infer.rs index c7f14e47a9d..cd533b57bc3 100644 --- a/src/test/ui/const-generics/defaults/doesnt_infer.rs +++ b/src/test/ui/const-generics/defaults/doesnt_infer.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - // test that defaulted const params are not used to help type inference struct Foo<const N: u32 = 2>; diff --git a/src/test/ui/const-generics/defaults/doesnt_infer.stderr b/src/test/ui/const-generics/defaults/doesnt_infer.stderr index b57975e26f2..1551e81ea75 100644 --- a/src/test/ui/const-generics/defaults/doesnt_infer.stderr +++ b/src/test/ui/const-generics/defaults/doesnt_infer.stderr @@ -1,10 +1,10 @@ error[E0282]: type annotations needed for `Foo<{_: u32}>` - --> $DIR/doesnt_infer.rs:13:15 + --> $DIR/doesnt_infer.rs:11:15 | LL | let foo = Foo::foo(); | --- ^^^^^^^^ cannot infer the value of const parameter `N` | | - | consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified + | consider giving `foo` the explicit type `Foo<N>`, where the const parameter `N` is specified error: aborting due to previous error diff --git a/src/test/ui/const-generics/defaults/external.rs b/src/test/ui/const-generics/defaults/external.rs index 276e74355c2..25ec523cb54 100644 --- a/src/test/ui/const-generics/defaults/external.rs +++ b/src/test/ui/const-generics/defaults/external.rs @@ -1,7 +1,5 @@ // aux-build:const_defaulty.rs // check-pass -#![feature(const_generics_defaults)] - extern crate const_defaulty; use const_defaulty::Defaulted; diff --git a/src/test/ui/const-generics/defaults/forward-declared.rs b/src/test/ui/const-generics/defaults/forward-declared.rs index 09fc105320e..ede3d873bdc 100644 --- a/src/test/ui/const-generics/defaults/forward-declared.rs +++ b/src/test/ui/const-generics/defaults/forward-declared.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct Foo<const N: usize = M, const M: usize = 10>; //~^ ERROR generic parameters with a default cannot use forward declared identifiers diff --git a/src/test/ui/const-generics/defaults/forward-declared.stderr b/src/test/ui/const-generics/defaults/forward-declared.stderr index a6c4a7ae4ef..4856c7a1fd2 100644 --- a/src/test/ui/const-generics/defaults/forward-declared.stderr +++ b/src/test/ui/const-generics/defaults/forward-declared.stderr @@ -1,23 +1,23 @@ error[E0128]: generic parameters with a default cannot use forward declared identifiers - --> $DIR/forward-declared.rs:3:29 + --> $DIR/forward-declared.rs:1:29 | LL | struct Foo<const N: usize = M, const M: usize = 10>; | ^ defaulted generic parameters cannot be forward declared error[E0128]: generic parameters with a default cannot use forward declared identifiers - --> $DIR/forward-declared.rs:6:27 + --> $DIR/forward-declared.rs:4:27 | LL | enum Bar<const N: usize = M, const M: usize = 10> {} | ^ defaulted generic parameters cannot be forward declared error[E0128]: generic parameters with a default cannot use forward declared identifiers - --> $DIR/forward-declared.rs:9:30 + --> $DIR/forward-declared.rs:7:30 | LL | struct Foo2<const N: usize = N>; | ^ defaulted generic parameters cannot be forward declared error[E0128]: generic parameters with a default cannot use forward declared identifiers - --> $DIR/forward-declared.rs:12:28 + --> $DIR/forward-declared.rs:10:28 | LL | enum Bar2<const N: usize = N> {} | ^ defaulted generic parameters cannot be forward declared diff --git a/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs index 52cea51aae1..f082bd8d2e9 100644 --- a/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const N: usize, const M: usize = { N + 1 }>; diff --git a/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs index 3a11631fc47..777865d1cb6 100644 --- a/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const N: usize, const M: usize = { N + 1 }>; diff --git a/src/test/ui/const-generics/defaults/generic-expr-default.rs b/src/test/ui/const-generics/defaults/generic-expr-default.rs index 0adbd5cdf31..8fe43feb78a 100644 --- a/src/test/ui/const-generics/defaults/generic-expr-default.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub struct Foo<const N: usize, const M: usize = { N + 1 }>; diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr deleted file mode 100644 index 725cc36b428..00000000000 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: lifetime parameters must be declared prior to const parameters - --> $DIR/intermixed-lifetime.rs:5: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>` - -error: lifetime parameters must be declared prior to type parameters - --> $DIR/intermixed-lifetime.rs:8:37 - | -LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T); - | --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs index cc215ab0c25..578938db4c4 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -1,6 +1,4 @@ // Checks that lifetimes cannot be interspersed between consts and types. -// revisions: full min -#![feature(const_generics_defaults)] struct Foo<const N: usize, 'a, T = u32>(&'a (), T); //~^ Error lifetime parameters must be declared prior to const parameters diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr index 725cc36b428..e27976deb2b 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr @@ -1,11 +1,11 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/intermixed-lifetime.rs:5:28 + --> $DIR/intermixed-lifetime.rs:3: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>` error: lifetime parameters must be declared prior to type parameters - --> $DIR/intermixed-lifetime.rs:8:37 + --> $DIR/intermixed-lifetime.rs:6:37 | LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T); | --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` diff --git a/src/test/ui/const-generics/defaults/mismatch.rs b/src/test/ui/const-generics/defaults/mismatch.rs index 4ae93a9166d..fce4ec4edda 100644 --- a/src/test/ui/const-generics/defaults/mismatch.rs +++ b/src/test/ui/const-generics/defaults/mismatch.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - pub struct Example<const N: usize=13>; pub struct Example2<T=u32, const N: usize=13>(T); pub struct Example3<const N: usize=13, T=u32>(T); diff --git a/src/test/ui/const-generics/defaults/mismatch.stderr b/src/test/ui/const-generics/defaults/mismatch.stderr index 3c7f4fe3b28..36976819195 100644 --- a/src/test/ui/const-generics/defaults/mismatch.stderr +++ b/src/test/ui/const-generics/defaults/mismatch.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/mismatch.rs:9:28 + --> $DIR/mismatch.rs:7:28 | LL | let e: Example::<13> = (); | ------------- ^^ expected struct `Example`, found `()` @@ -10,7 +10,7 @@ LL | let e: Example::<13> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:12:34 + --> $DIR/mismatch.rs:10:34 | LL | let e: Example2::<u32, 13> = (); | ------------------- ^^ expected struct `Example2`, found `()` @@ -21,7 +21,7 @@ LL | let e: Example2::<u32, 13> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:15:34 + --> $DIR/mismatch.rs:13:34 | LL | let e: Example3::<13, u32> = (); | ------------------- ^^ expected struct `Example3`, found `()` @@ -32,7 +32,7 @@ LL | let e: Example3::<13, u32> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:18:28 + --> $DIR/mismatch.rs:16:28 | LL | let e: Example3::<7> = (); | ------------- ^^ expected struct `Example3`, found `()` @@ -43,7 +43,7 @@ LL | let e: Example3::<7> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:21:28 + --> $DIR/mismatch.rs:19:28 | LL | let e: Example4::<7> = (); | ------------- ^^ expected struct `Example4`, found `()` diff --git a/src/test/ui/const-generics/defaults/needs-feature.min.stderr b/src/test/ui/const-generics/defaults/needs-feature.min.stderr deleted file mode 100644 index 158fa2ec1c8..00000000000 --- a/src/test/ui/const-generics/defaults/needs-feature.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/needs-feature.rs:7:26 - | -LL | struct A<const N: usize, T=u32>(T); - | -----------------^----- help: reorder the parameters: lifetimes, then types, then consts: `<T = u32, const N: usize>` - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/defaults/needs-feature.rs b/src/test/ui/const-generics/defaults/needs-feature.rs deleted file mode 100644 index 9ba8184e058..00000000000 --- a/src/test/ui/const-generics/defaults/needs-feature.rs +++ /dev/null @@ -1,12 +0,0 @@ -//[full] run-pass -// Verifies that having generic parameters after constants is not permitted without the -// `const_generics_defaults` feature. -// revisions: min full -#![cfg_attr(full, feature(const_generics_defaults))] - -struct A<const N: usize, T=u32>(T); -//[min]~^ ERROR type parameters must be declared prior - -fn main() { - let _: A<3> = A(0); -} diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs index 933eacb312d..da087ffc3c4 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs @@ -1,4 +1,3 @@ -#![feature(const_generics_defaults)] struct Foo<const M: usize = 10, 'a>(&'a u32); //~^ Error lifetime parameters must be declared prior to const parameters diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr index f50653fe9a1..55f5a535385 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr @@ -1,5 +1,5 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/param-order-err-pretty-prints-default.rs:2:33 + --> $DIR/param-order-err-pretty-prints-default.rs:1:33 | LL | struct Foo<const M: usize = 10, 'a>(&'a u32); | ----------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const M: usize = 10>` diff --git a/src/test/ui/const-generics/defaults/pretty-printing-ast.rs b/src/test/ui/const-generics/defaults/pretty-printing-ast.rs index 0487668cd2a..e202d4e86a2 100644 --- a/src/test/ui/const-generics/defaults/pretty-printing-ast.rs +++ b/src/test/ui/const-generics/defaults/pretty-printing-ast.rs @@ -3,7 +3,6 @@ // compile-flags: -Z unpretty=expanded #![crate_type = "lib"] -#![feature(const_generics_defaults)] trait Foo<const KIND: bool = true> {} diff --git a/src/test/ui/const-generics/defaults/pretty-printing-ast.stdout b/src/test/ui/const-generics/defaults/pretty-printing-ast.stdout index 1bceb8cbb94..99fe9d2e4b3 100644 --- a/src/test/ui/const-generics/defaults/pretty-printing-ast.stdout +++ b/src/test/ui/const-generics/defaults/pretty-printing-ast.stdout @@ -5,15 +5,14 @@ // compile-flags: -Z unpretty=expanded #![crate_type = "lib"] -#![feature(const_generics_defaults)] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] extern crate std; -trait Foo<const KIND : bool = true> { } +trait Foo<const KIND : bool = true> {} -fn foo<const SIZE : usize = 5>() { } +fn foo<const SIZE : usize = 5>() {} struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize = FROM>; diff --git a/src/test/ui/const-generics/defaults/repr-c-issue-82792.rs b/src/test/ui/const-generics/defaults/repr-c-issue-82792.rs index ca29ee94206..118da2723ac 100644 --- a/src/test/ui/const-generics/defaults/repr-c-issue-82792.rs +++ b/src/test/ui/const-generics/defaults/repr-c-issue-82792.rs @@ -2,8 +2,6 @@ // run-pass -#![feature(const_generics_defaults)] - #[repr(C)] pub struct Loaf<T: Sized, const N: usize = 1> { head: [T; N], diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait.rs b/src/test/ui/const-generics/defaults/rp_impl_trait.rs index 1447ebe5348..dde8eea4525 100644 --- a/src/test/ui/const-generics/defaults/rp_impl_trait.rs +++ b/src/test/ui/const-generics/defaults/rp_impl_trait.rs @@ -1,6 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] - struct Uwu<const N: u32 = 1, const M: u32 = N>; trait Trait {} diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs index c989fc8338b..308c121a941 100644 --- a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs +++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct Uwu<const N: u32 = 1, const M: u32 = N>; trait Trait {} diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr index cf28932177a..8c8bfdc0e48 100644 --- a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr +++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied - --> $DIR/rp_impl_trait_fail.rs:8:14 + --> $DIR/rp_impl_trait_fail.rs:6:14 | LL | fn rawr() -> impl Trait { | ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>` @@ -8,7 +8,7 @@ LL | fn rawr() -> impl Trait { <Uwu<N> as Trait> error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied - --> $DIR/rp_impl_trait_fail.rs:19:26 + --> $DIR/rp_impl_trait_fail.rs:17:26 | LL | fn uwu<const N: u8>() -> impl Traitor<N> { | ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32` @@ -17,7 +17,7 @@ LL | fn uwu<const N: u8>() -> impl Traitor<N> { <u32 as Traitor<N, 2_u8>> error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied - --> $DIR/rp_impl_trait_fail.rs:24:13 + --> $DIR/rp_impl_trait_fail.rs:22:13 | LL | fn owo() -> impl Traitor { | ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64` diff --git a/src/test/ui/const-generics/defaults/simple-defaults.rs b/src/test/ui/const-generics/defaults/simple-defaults.rs index bc01fe2656c..6a782d2238c 100644 --- a/src/test/ui/const-generics/defaults/simple-defaults.rs +++ b/src/test/ui/const-generics/defaults/simple-defaults.rs @@ -1,6 +1,5 @@ // run-pass // Checks that type param defaults are allowed after const params. -#![feature(const_generics_defaults)] #![allow(dead_code)] struct FixedOutput<'a, const N: usize, T=u32> { diff --git a/src/test/ui/const-generics/defaults/trait_object_lt_defaults.rs b/src/test/ui/const-generics/defaults/trait_object_lt_defaults.rs new file mode 100644 index 00000000000..a1828727ecd --- /dev/null +++ b/src/test/ui/const-generics/defaults/trait_object_lt_defaults.rs @@ -0,0 +1,24 @@ +// aux-build:trait_object_lt_defaults_lib.rs +// run-pass +#![allow(dead_code)] +extern crate trait_object_lt_defaults_lib; + +// Tests that `A<'a, 3, dyn Test>` is short for `A<'a, 3, dyn Test + 'a>` +// and `Foo<'a, 3, dyn Test>` is short for `Foo<'a, 3, dyn Test + 'a>` +// Test is in `const-generics/defaults` because it relies on param ordering + +trait Test {} + +struct A<'a, const N: usize, T: ?Sized + 'a>(&'a T, [(); N]); +fn blah<'a>(mut a: A<'a, 3, dyn Test>, arg: &'a (dyn Test + 'a)) { + a.0 = arg; +} + +fn other_blah<'a>( + mut a: trait_object_lt_defaults_lib::Foo<'a, 3, dyn Test>, + arg: &'a (dyn Test + 'a), +) { + a.0 = arg; +} + +fn main() {} diff --git a/src/test/ui/const-generics/defaults/trait_objects.rs b/src/test/ui/const-generics/defaults/trait_objects.rs index e36f23fadb2..750e40313fb 100644 --- a/src/test/ui/const-generics/defaults/trait_objects.rs +++ b/src/test/ui/const-generics/defaults/trait_objects.rs @@ -1,6 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] - trait Trait<const N: u8 = 12> { fn uwu(&self) -> u8 { N diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.rs b/src/test/ui/const-generics/defaults/trait_objects_fail.rs index 09e4265a7a0..7ba12d02b6e 100644 --- a/src/test/ui/const-generics/defaults/trait_objects_fail.rs +++ b/src/test/ui/const-generics/defaults/trait_objects_fail.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - trait Trait<const N: u8 = 12> { fn uwu(&self) -> u8 { N diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr index b097c8cd4ba..13d03c2d42d 100644 --- a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr +++ b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `u32: Trait` is not satisfied - --> $DIR/trait_objects_fail.rs:28:9 + --> $DIR/trait_objects_fail.rs:26:9 | LL | foo(&10_u32); | --- ^^^^^^^ the trait `Trait` is not implemented for `u32` @@ -11,7 +11,7 @@ LL | foo(&10_u32); = note: required for the cast to the object type `dyn Trait` error[E0277]: the trait bound `bool: Traitor<{_: u8}, {_: u8}>` is not satisfied - --> $DIR/trait_objects_fail.rs:30:9 + --> $DIR/trait_objects_fail.rs:28:9 | LL | bar(&true); | --- ^^^^^ the trait `Traitor<{_: u8}, {_: u8}>` is not implemented for `bool` diff --git a/src/test/ui/const-generics/defaults/type-default-const-param-name.rs b/src/test/ui/const-generics/defaults/type-default-const-param-name.rs index 8b35c5860d9..405664dedc7 100644 --- a/src/test/ui/const-generics/defaults/type-default-const-param-name.rs +++ b/src/test/ui/const-generics/defaults/type-default-const-param-name.rs @@ -1,6 +1,4 @@ // check-pass -#![feature(const_generics_defaults)] - struct N; struct Foo<const N: usize = 1, T = N>(T); diff --git a/src/test/ui/const-generics/defaults/wfness.rs b/src/test/ui/const-generics/defaults/wfness.rs index c171f292fd6..d366040ba3e 100644 --- a/src/test/ui/const-generics/defaults/wfness.rs +++ b/src/test/ui/const-generics/defaults/wfness.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct Ooopsies<const N: u8 = { u8::MAX + 1 }>; //~^ error: evaluation of constant value failed diff --git a/src/test/ui/const-generics/defaults/wfness.stderr b/src/test/ui/const-generics/defaults/wfness.stderr index 2d400f9bbf5..facf0ae19f7 100644 --- a/src/test/ui/const-generics/defaults/wfness.stderr +++ b/src/test/ui/const-generics/defaults/wfness.stderr @@ -1,11 +1,11 @@ error[E0080]: evaluation of constant value failed - --> $DIR/wfness.rs:3:33 + --> $DIR/wfness.rs:1:33 | LL | struct Ooopsies<const N: u8 = { u8::MAX + 1 }>; | ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow error[E0277]: the trait bound `(): Trait<2_u8>` is not satisfied - --> $DIR/wfness.rs:8:47 + --> $DIR/wfness.rs:6:47 | LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>; | ^^^^^^^^ the trait `Trait<2_u8>` is not implemented for `()` @@ -14,7 +14,7 @@ LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>; <() as Trait<3_u8>> error[E0277]: the trait bound `(): Trait<1_u8>` is not satisfied - --> $DIR/wfness.rs:16:13 + --> $DIR/wfness.rs:14:13 | LL | fn foo() -> DependentDefaultWfness { | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1_u8>` is not implemented for `()` @@ -22,7 +22,7 @@ LL | fn foo() -> DependentDefaultWfness { = help: the following implementations were found: <() as Trait<3_u8>> note: required by a bound in `WhereClause` - --> $DIR/wfness.rs:8:47 + --> $DIR/wfness.rs:6:47 | LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>; | ^^^^^^^^ required by this bound in `WhereClause` diff --git a/src/test/ui/const-generics/defaults/wrong-order.rs b/src/test/ui/const-generics/defaults/wrong-order.rs index 94e7367b1fb..d53d56f41e6 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.rs +++ b/src/test/ui/const-generics/defaults/wrong-order.rs @@ -1,5 +1,3 @@ -#![feature(const_generics_defaults)] - struct A<T = u32, const N: usize> { //~^ ERROR generic parameters with a default must be trailing arg: T, diff --git a/src/test/ui/const-generics/defaults/wrong-order.stderr b/src/test/ui/const-generics/defaults/wrong-order.stderr index 143ce5c4fea..4d2628d034f 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.stderr +++ b/src/test/ui/const-generics/defaults/wrong-order.stderr @@ -1,11 +1,11 @@ error: generic parameters with a default must be trailing - --> $DIR/wrong-order.rs:3:10 + --> $DIR/wrong-order.rs:1:10 | LL | struct A<T = u32, const N: usize> { | ^ error: generic parameters with a default must be trailing - --> $DIR/wrong-order.rs:8:18 + --> $DIR/wrong-order.rs:6:18 | LL | struct Foo<const N: u8 = 3, T>(T); | ^ diff --git a/src/test/ui/const-generics/generic_arg_infer/dont-use-defaults.rs b/src/test/ui/const-generics/generic_arg_infer/dont-use-defaults.rs new file mode 100644 index 00000000000..251160a0f5f --- /dev/null +++ b/src/test/ui/const-generics/generic_arg_infer/dont-use-defaults.rs @@ -0,0 +1,15 @@ +// run-pass +#![feature(generic_arg_infer)] + +// test that we dont use defaults to aide in type inference + +struct Foo<const N: usize = 2>; +impl<const N: usize> Foo<N> { + fn make_arr() -> [(); N] { + [(); N] + } +} + +fn main() { + let [(), (), ()] = Foo::<_>::make_arr(); +} diff --git a/src/test/ui/const-generics/generic_arg_infer/issue-91614.rs b/src/test/ui/const-generics/generic_arg_infer/issue-91614.rs new file mode 100644 index 00000000000..413cc153924 --- /dev/null +++ b/src/test/ui/const-generics/generic_arg_infer/issue-91614.rs @@ -0,0 +1,8 @@ +#![feature(portable_simd)] +#![feature(generic_arg_infer)] +use std::simd::Mask; + +fn main() { + let y = Mask::<_, _>::splat(false); + //~^ error: type annotations needed for `Mask<_, {_: usize}>` +} diff --git a/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr b/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr new file mode 100644 index 00000000000..71a5ff79280 --- /dev/null +++ b/src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr @@ -0,0 +1,18 @@ +error[E0283]: type annotations needed for `Mask<_, {_: usize}>` + --> $DIR/issue-91614.rs:6:13 + | +LL | let y = Mask::<_, _>::splat(false); + | - ^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` + | | + | consider giving `y` the explicit type `Mask<_, LANES>`, where the type parameter `T` is specified + | + = note: cannot satisfy `_: MaskElement` +note: required by a bound in `Mask::<T, LANES>::splat` + --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL + | +LL | T: MaskElement, + | ^^^^^^^^^^^ required by this bound in `Mask::<T, LANES>::splat` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.stderr b/src/test/ui/const-generics/generic_const_exprs/closures.stderr index 0dfd804be41..18010413b93 100644 --- a/src/test/ui/const-generics/generic_const_exprs/closures.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/closures.stderr @@ -4,7 +4,7 @@ error: overly complex generic constant LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {} | ^^^^-------^^ | | - | dereferencing is not supported in generic constants + | borrowing is not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs index b79bc262d2b..18f33acaabb 100644 --- a/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs +++ b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs @@ -1,4 +1,3 @@ -// run-pass #![feature(generic_const_exprs)] #![allow(incomplete_features)] @@ -22,8 +21,11 @@ where } fn main() { - // Test that we can correctly infer `T` which requires evaluating - // `{ N + 1 }` which has substs containing an inference var + // FIXME(generic_const_exprs): We can't correctly infer `T` which requires + // evaluating `{ N + 1 }` which has substs containing an inference var let mut _q = Default::default(); + //~^ ERROR type annotations needed + _q = foo::<_, 2>(_q); + //~^ ERROR type annotations needed } diff --git a/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.stderr b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.stderr new file mode 100644 index 00000000000..e59f1ac8027 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.stderr @@ -0,0 +1,33 @@ +error[E0282]: type annotations needed + --> $DIR/const_eval_resolve_canonical.rs:26:9 + | +LL | let mut _q = Default::default(); + | ^^^^^^ consider giving `_q` a type + +error[E0283]: type annotations needed + --> $DIR/const_eval_resolve_canonical.rs:29:10 + | +LL | _q = foo::<_, 2>(_q); + | ^^^^^^^^^^^ cannot infer type + | +note: multiple `impl`s satisfying `(): Foo<{ N + 1 }>` found + --> $DIR/const_eval_resolve_canonical.rs:8:1 + | +LL | impl Foo<0> for () { + | ^^^^^^^^^^^^^^^^^^ +... +LL | impl Foo<3> for () { + | ^^^^^^^^^^^^^^^^^^ +note: required by a bound in `foo` + --> $DIR/const_eval_resolve_canonical.rs:18:9 + | +LL | fn foo<T, const N: usize>(_: T) -> <() as Foo<{ N + 1 }>>::Assoc + | --- required by a bound in this +LL | where +LL | (): Foo<{ N + 1 }>, + | ^^^^^^^^^^^^^^ required by this bound in `foo` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0282, E0283. +For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs index 80d0662f1f4..8023b998a40 100644 --- a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -9,12 +9,7 @@ pub trait Trait { fn assoc_fn() -> Self::AssocTy; } -impl<const U: u8> Trait for Const<U> -//~^ WARN private type -//~| WARN this was previously -//~| WARN private type -//~| WARN this was previously - +impl<const U: u8> Trait for Const<U> // OK, trait impl predicates where Const<{ my_const_fn(U) }>: , { diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr index 842c22c5c67..c6b0ce93145 100644 --- a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -1,36 +1,5 @@ -warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) - --> $DIR/eval-privacy.rs:12:1 - | -LL | / impl<const U: u8> Trait for Const<U> -LL | | -LL | | -LL | | -... | -LL | | } -LL | | } - | |_^ - | - = note: `#[warn(private_in_public)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - -warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) - --> $DIR/eval-privacy.rs:12:1 - | -LL | / impl<const U: u8> Trait for Const<U> -LL | | -LL | | -LL | | -... | -LL | | } -LL | | } - | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> - error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/eval-privacy.rs:21:5 + --> $DIR/eval-privacy.rs:16:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type @@ -38,6 +7,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -error: aborting due to previous error; 2 warnings emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0446`. diff --git a/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs index 67fefd07ec0..9580f8a7fbc 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const N: usize, const M: usize = { N + 1 }>; struct Bar<const N: usize>(Foo<N, 3>); diff --git a/src/test/ui/const-generics/invalid-enum.rs b/src/test/ui/const-generics/invalid-enum.rs index bc3c09238f2..cb6d05349db 100644 --- a/src/test/ui/const-generics/invalid-enum.rs +++ b/src/test/ui/const-generics/invalid-enum.rs @@ -1,4 +1,4 @@ -#![feature(adt_const_params, const_generics_defaults)] +#![feature(adt_const_params)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/issues/issue-72845.rs b/src/test/ui/const-generics/issues/issue-72845.rs new file mode 100644 index 00000000000..bea5dc8ba21 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-72845.rs @@ -0,0 +1,49 @@ +#![feature(generic_const_exprs)] +#![feature(specialization)] +#![allow(incomplete_features)] + +//-------------------------------------------------- + +trait Depth { + const C: usize; +} + +trait Type { + type AT: Depth; +} + +//-------------------------------------------------- + +enum Predicate<const B: bool> {} + +trait Satisfied {} + +impl Satisfied for Predicate<true> {} + +//-------------------------------------------------- + +trait Spec1 {} + +impl<T: Type> Spec1 for T where Predicate<{T::AT::C > 0}>: Satisfied {} + +trait Spec2 {} + +//impl<T: Type > Spec2 for T where Predicate<{T::AT::C > 1}>: Satisfied {} +impl<T: Type > Spec2 for T where Predicate<true>: Satisfied {} + +//-------------------------------------------------- + +trait Foo { + fn Bar(); +} + +impl<T: Spec1> Foo for T { + default fn Bar() {} +} + +impl<T: Spec2> Foo for T { +//~^ ERROR conflicting implementations of trait + fn Bar() {} +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-72845.stderr b/src/test/ui/const-generics/issues/issue-72845.stderr new file mode 100644 index 00000000000..631c8605fb4 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-72845.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Foo` + --> $DIR/issue-72845.rs:44:1 + | +LL | impl<T: Spec1> Foo for T { + | ------------------------ first implementation here +... +LL | impl<T: Spec2> Foo for T { + | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/const-generics/issues/issue-79674.rs b/src/test/ui/const-generics/issues/issue-79674.rs new file mode 100644 index 00000000000..2f196533dd8 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-79674.rs @@ -0,0 +1,28 @@ +#![feature(const_fn_trait_bound, generic_const_exprs)] +#![allow(incomplete_features)] + +trait MiniTypeId { + const TYPE_ID: u64; +} + +impl<T> MiniTypeId for T { + const TYPE_ID: u64 = 0; +} + +enum Lift<const V: bool> {} + +trait IsFalse {} +impl IsFalse for Lift<false> {} + +const fn is_same_type<T: MiniTypeId, U: MiniTypeId>() -> bool { + T::TYPE_ID == U::TYPE_ID +} + +fn requires_distinct<A, B>(_a: A, _b: B) where + A: MiniTypeId, B: MiniTypeId, + Lift<{is_same_type::<A, B>()}>: IsFalse {} + +fn main() { + requires_distinct("str", 12); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/const-generics/issues/issue-79674.stderr b/src/test/ui/const-generics/issues/issue-79674.stderr new file mode 100644 index 00000000000..8c029289cbb --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-79674.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-79674.rs:26:5 + | +LL | requires_distinct("str", 12); + | ^^^^^^^^^^^^^^^^^ expected `true`, found `false` + | + = note: expected type `true` + found type `false` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-83249.rs b/src/test/ui/const-generics/issues/issue-83249.rs new file mode 100644 index 00000000000..65148c55ee5 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83249.rs @@ -0,0 +1,23 @@ +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +trait Foo { + const N: usize; +} + +impl Foo for u8 { + const N: usize = 1; +} + +fn foo<T: Foo>(_: [u8; T::N]) -> T { + todo!() +} + +pub fn bar() { + let _: u8 = foo([0; 1]); + + let _ = foo([0; 1]); + //~^ ERROR type annotations needed +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83249.stderr b/src/test/ui/const-generics/issues/issue-83249.stderr new file mode 100644 index 00000000000..402b3aa2d61 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83249.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed + --> $DIR/issue-83249.rs:19:13 + | +LL | let _ = foo([0; 1]); + | - ^^^ cannot infer type for type parameter `T` declared on the function `foo` + | | + | consider giving this pattern a type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/issues/issue-83288.rs b/src/test/ui/const-generics/issues/issue-83288.rs new file mode 100644 index 00000000000..a24596d242e --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83288.rs @@ -0,0 +1,69 @@ +// build-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +use std::{marker::PhantomData, ops::Mul}; + +pub enum Nil {} +pub struct Cons<T, L> { + _phantom: PhantomData<(T, L)>, +} + +pub trait Indices<const N: usize> { + const RANK: usize; + const NUM_ELEMS: usize; +} + +impl<const N: usize> Indices<N> for Nil { + const RANK: usize = 0; + const NUM_ELEMS: usize = 1; +} + +impl<T, I: Indices<N>, const N: usize> Indices<N> for Cons<T, I> { + const RANK: usize = I::RANK + 1; + const NUM_ELEMS: usize = I::NUM_ELEMS * N; +} + +pub trait Concat<J> { + type Output; +} + +impl<J> Concat<J> for Nil { + type Output = J; +} + +impl<T, I, J> Concat<J> for Cons<T, I> +where + I: Concat<J>, +{ + type Output = Cons<T, <I as Concat<J>>::Output>; +} + +pub struct Tensor<I: Indices<N>, const N: usize> +where + [u8; I::NUM_ELEMS]: Sized, +{ + pub data: [u8; I::NUM_ELEMS], + _phantom: PhantomData<I>, +} + +impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul<Tensor<J, N>> for Tensor<I, N> +where + I: Concat<J>, + <I as Concat<J>>::Output: Indices<N>, + [u8; I::NUM_ELEMS]: Sized, + [u8; J::NUM_ELEMS]: Sized, + [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized, +{ + type Output = Tensor<<I as Concat<J>>::Output, N>; + + fn mul(self, _rhs: Tensor<J, N>) -> Self::Output { + Tensor { + data: [0u8; <I as Concat<J>>::Output::NUM_ELEMS], + _phantom: PhantomData, + } + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/issues/issue-83765.rs new file mode 100644 index 00000000000..68536348d38 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.rs @@ -0,0 +1,115 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait TensorDimension { + const DIM : usize; + const ISSCALAR : bool = Self::DIM == 0; + fn is_scalar(&self) -> bool {Self::ISSCALAR} +} + +trait TensorSize : TensorDimension { + fn size(&self) -> [usize;Self::DIM]; + fn inbounds(&self,index : [usize;Self::DIM]) -> bool { + index.iter().zip(self.size().iter()).all(|(i,s)| i < s) + } +} + + +trait Broadcastable: TensorSize + Sized { + type Element; + fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>; + fn lazy_updim<const NEWDIM : usize>(&self, size : [usize;NEWDIM] ) -> + LazyUpdim<Self,{Self::DIM},NEWDIM> + { + assert!(NEWDIM >= Self::DIM, + "Updimmed tensor cannot have fewer indices than the initial one."); + LazyUpdim {size,reference:&self} + } + fn bmap<T,F :Fn(Self::Element) -> T>(&self,foo : F) -> BMap<T,Self,F,{Self::DIM}>{ + BMap {reference:self,closure : foo} + } +} + + +struct LazyUpdim<'a,T : Broadcastable,const OLDDIM : usize, const DIM : usize> { + size : [usize;DIM], + reference : &'a T +} + +impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,{T::DIM},DIM> { + const DIM : usize = DIM; +} + +impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> { + fn size(&self) -> [usize;DIM] {self.size} + //~^ ERROR method not compatible with trait +} + +impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> +{ + type Element = T::Element; + fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> { + //~^ ERROR method not compatible with trait + assert!(DIM >= T::DIM); + if !self.inbounds(index) {return None} + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + let size = self.size(); + //~^ ERROR unconstrained generic constant + let newindex : [usize;T::DIM] = Default::default(); + //~^ ERROR the trait bound `[usize; _]: Default` is not satisfied + self.reference.bget(newindex) + } +} + +struct BMap<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , const DIM: usize> { + reference : &'a T, + closure : F +} + +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R, + const DIM: usize> TensorDimension for BMap<'a,R,T,F,DIM> { + + const DIM : usize = DIM; +} +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , + const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> { + + fn size(&self) -> [usize;DIM] {self.reference.size()} + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + //~| ERROR method not compatible with trait +} + +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , + const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> { + + type Element = R; + fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> { + //~^ ERROR method not compatible with trait + self.reference.bget(index).map(&self.closure) + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + } +} + +impl<T> TensorDimension for Vec<T> { + const DIM : usize = 1; +} +impl<T> TensorSize for Vec<T> { + fn size(&self) -> [usize;1] {[self.len()]} +} +impl<T: Clone> Broadcastable for Vec<T> { + type Element = T; + fn bget(& self,index : [usize;1]) -> Option<T> { + self.get(index[0]).cloned() + } +} + +fn main() { + let v = vec![1,2,3]; + let bv = v.lazy_updim([3,4]); + let bbv = bv.bmap(|x| x*x); + + println!("The size of v is {:?}",bbv.bget([0,2]).expect("Out of bounds.")); +} diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/issues/issue-83765.stderr new file mode 100644 index 00000000000..a49f850717f --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.stderr @@ -0,0 +1,130 @@ +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:44:5 + | +LL | fn size(&self) -> [usize;DIM] {self.size} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:51:5 + | +LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:78:5 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:88:5 + | +LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:54:18 + | +LL | if !self.inbounds(index) {return None} + | ^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::inbounds` + --> $DIR/issue-83765.rs:12:38 + | +LL | fn inbounds(&self,index : [usize;Self::DIM]) -> bool { + | ^^^^^^^^^ required by this bound in `TensorSize::inbounds` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:54:27 + | +LL | if !self.inbounds(index) {return None} + | ^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:57:25 + | +LL | let size = self.size(); + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::size` + --> $DIR/issue-83765.rs:11:30 + | +LL | fn size(&self) -> [usize;Self::DIM]; + | ^^^^^^^^^ required by this bound in `TensorSize::size` + +error[E0277]: the trait bound `[usize; _]: Default` is not satisfied + --> $DIR/issue-83765.rs:59:41 + | +LL | let newindex : [usize;T::DIM] = Default::default(); + | ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[usize; _]` + | +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> where [usize; _]: Default + | +++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:78:51 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::size` + --> $DIR/issue-83765.rs:11:30 + | +LL | fn size(&self) -> [usize;Self::DIM]; + | ^^^^^^^^^ required by this bound in `TensorSize::size` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:78:36 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM` + | + = note: expected type `DIM` + found type `Self::DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:90:24 + | +LL | self.reference.bget(index).map(&self.closure) + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `Broadcastable::bget` + --> $DIR/issue-83765.rs:20:33 + | +LL | fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>; + | ^^^^^^^^^ required by this bound in `Broadcastable::bget` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:90:29 + | +LL | self.reference.bget(index).map(&self.closure) + | ^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: aborting due to 12 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/issues/issue-86033.rs b/src/test/ui/const-generics/issues/issue-86033.rs new file mode 100644 index 00000000000..cf08f722fbb --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-86033.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait IsTrue<const T: bool> {} +impl IsTrue<true> for () {} + +pub trait IsZST {} + +impl<T> IsZST for T +where + (): IsTrue<{ std::mem::size_of::<T>() == 0 }> +{} + +fn _func() -> impl IsZST { + || {} +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-87470.rs b/src/test/ui/const-generics/issues/issue-87470.rs new file mode 100644 index 00000000000..d60181a418a --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-87470.rs @@ -0,0 +1,24 @@ +// build-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait TraitWithConst { + const SOME_CONST: usize; +} + +pub trait OtherTrait: TraitWithConst { + fn some_fn(self) -> [u8 ; <Self as TraitWithConst>::SOME_CONST]; +} + +impl TraitWithConst for f32 { + const SOME_CONST: usize = 32; +} + +impl OtherTrait for f32 { + fn some_fn(self) -> [u8 ; <Self as TraitWithConst>::SOME_CONST] { + [0; 32] + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-87964.rs b/src/test/ui/const-generics/issues/issue-87964.rs new file mode 100644 index 00000000000..116686abb9e --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-87964.rs @@ -0,0 +1,29 @@ +// build-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait Target { + const LENGTH: usize; +} + + +pub struct Container<T: Target> +where + [(); T::LENGTH]: Sized, +{ + _target: T, +} + +impl<T: Target> Container<T> +where + [(); T::LENGTH]: Sized, +{ + pub fn start( + _target: T, + ) -> Container<T> { + Container { _target } + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-88468.rs b/src/test/ui/const-generics/issues/issue-88468.rs new file mode 100644 index 00000000000..914047236ab --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-88468.rs @@ -0,0 +1,13 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +pub struct Assert<const COND: bool>(); +pub trait IsTrue {} +impl IsTrue for Assert<true> {} + +pub trait IsNotZST {} +impl<T> IsNotZST for T where Assert<{ std::mem::size_of::<T>() > 0 }>: IsTrue {} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-89146.rs b/src/test/ui/const-generics/issues/issue-89146.rs new file mode 100644 index 00000000000..e3540f46f1e --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-89146.rs @@ -0,0 +1,26 @@ +// build-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +pub trait Foo { + const SIZE: usize; + + fn to_bytes(&self) -> [u8; Self::SIZE]; +} + +pub fn bar<G: Foo>(a: &G) -> u8 +where + [(); G::SIZE]: Sized, +{ + deeper_bar(a) +} + +fn deeper_bar<G: Foo>(a: &G) -> u8 +where + [(); G::SIZE]: Sized, +{ + a.to_bytes()[0] +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-89320.rs b/src/test/ui/const-generics/issues/issue-89320.rs new file mode 100644 index 00000000000..afa5c8fab74 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-89320.rs @@ -0,0 +1,19 @@ +// build-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait Enumerable { + const N: usize; +} + +#[derive(Clone)] +pub struct SymmetricGroup<S> +where + S: Enumerable, + [(); S::N]: Sized, +{ + _phantom: std::marker::PhantomData<S>, +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-90318.rs b/src/test/ui/const-generics/issues/issue-90318.rs new file mode 100644 index 00000000000..0c640a5ef71 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90318.rs @@ -0,0 +1,32 @@ +#![feature(const_type_id)] +#![feature(generic_const_exprs)] +#![feature(core_intrinsics)] +#![allow(incomplete_features)] + +use std::any::TypeId; + +struct If<const B: bool>; +pub trait True {} +impl True for If<true> {} + +fn consume<T: 'static>(_val: T) +where + If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + //~^ ERROR: overly complex generic constant + //~| ERROR: calls in constants are limited to constant functions +{ +} + +fn test<T: 'static>() +where + If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + //~^ ERROR: overly complex generic constant + //~| ERROR: calls in constants are limited to constant functions +{ +} + +fn main() { + let a = (); + consume(0i32); + consume(a); +} diff --git a/src/test/ui/const-generics/issues/issue-90318.stderr b/src/test/ui/const-generics/issues/issue-90318.stderr new file mode 100644 index 00000000000..2b8afe2ef09 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90318.stderr @@ -0,0 +1,37 @@ +error: overly complex generic constant + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | borrowing is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-90318.rs:14:10 + | +LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: overly complex generic constant + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | borrowing is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-90318.rs:22:10 + | +LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/const-generics/issues/issue-90455.rs b/src/test/ui/const-generics/issues/issue-90455.rs new file mode 100644 index 00000000000..a580410cf37 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90455.rs @@ -0,0 +1,12 @@ +#![feature(generic_const_exprs, adt_const_params)] +#![allow(incomplete_features)] + +struct FieldElement<const N: &'static str> { + n: [u64; num_limbs(N)], + //~^ ERROR unconstrained generic constant +} +const fn num_limbs(_: &str) -> usize { + 0 +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-90455.stderr b/src/test/ui/const-generics/issues/issue-90455.stderr new file mode 100644 index 00000000000..724d7f42e69 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90455.stderr @@ -0,0 +1,10 @@ +error: unconstrained generic constant + --> $DIR/issue-90455.rs:5:8 + | +LL | n: [u64; num_limbs(N)], + | ^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); num_limbs(N)]:` + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs index ae8863c567d..e12e07a28e7 100644 --- a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs +++ b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs @@ -12,8 +12,6 @@ fn b() { //~^ ERROR expected trait, found constant `BAR` //~| ERROR expected trait, found constant `BAR` //~| ERROR type provided when a constant was expected - //~| WARN trait objects without an explicit `dyn` are deprecated - //~| WARN this is accepted in the current edition } fn c() { foo::<3 + 3>(); //~ ERROR expressions must be enclosed in braces diff --git a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr index 380c17c8e62..d9bcc523b1f 100644 --- a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr +++ b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr @@ -10,7 +10,7 @@ LL | foo::<{ BAR + 3 }>(); | + + error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:19:11 + --> $DIR/const-expression-suggest-missing-braces.rs:17:11 | LL | foo::<3 + 3>(); | ^^^^^ @@ -21,7 +21,7 @@ LL | foo::<{ 3 + 3 }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:22:15 + --> $DIR/const-expression-suggest-missing-braces.rs:20:15 | LL | foo::<BAR - 3>(); | ^ expected one of `,` or `>` @@ -32,7 +32,7 @@ LL | foo::<{ BAR - 3 }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:25:15 + --> $DIR/const-expression-suggest-missing-braces.rs:23:15 | LL | foo::<BAR - BAR>(); | ^ expected one of `,` or `>` @@ -43,7 +43,7 @@ LL | foo::<{ BAR - BAR }>(); | + + error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:28:11 + --> $DIR/const-expression-suggest-missing-braces.rs:26:11 | LL | foo::<100 - BAR>(); | ^^^^^^^^^ @@ -54,7 +54,7 @@ LL | foo::<{ 100 - BAR }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:31:19 + --> $DIR/const-expression-suggest-missing-braces.rs:29:19 | LL | foo::<bar<i32>()>(); | ^ expected one of `,` or `>` @@ -65,7 +65,7 @@ LL | foo::<{ bar<i32>() }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:34:21 + --> $DIR/const-expression-suggest-missing-braces.rs:32:21 | LL | foo::<bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -76,7 +76,7 @@ LL | foo::<{ bar::<i32>() }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:37:21 + --> $DIR/const-expression-suggest-missing-braces.rs:35:21 | LL | foo::<bar::<i32>() + BAR>(); | ^ expected one of `,` or `>` @@ -87,7 +87,7 @@ LL | foo::<{ bar::<i32>() + BAR }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:40:21 + --> $DIR/const-expression-suggest-missing-braces.rs:38:21 | LL | foo::<bar::<i32>() - BAR>(); | ^ expected one of `,` or `>` @@ -98,7 +98,7 @@ LL | foo::<{ bar::<i32>() - BAR }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:43:15 + --> $DIR/const-expression-suggest-missing-braces.rs:41:15 | LL | foo::<BAR - bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -109,7 +109,7 @@ LL | foo::<{ BAR - bar::<i32>() }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:46:15 + --> $DIR/const-expression-suggest-missing-braces.rs:44:15 | LL | foo::<BAR - bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -131,23 +131,13 @@ error[E0404]: expected trait, found constant `BAR` LL | foo::<BAR + BAR>(); | ^^^ not a trait -warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/const-expression-suggest-missing-braces.rs:11:11 - | -LL | foo::<BAR + BAR>(); - | ^^^^^^^^^ help: use `dyn`: `dyn BAR + BAR` - | - = note: `#[warn(bare_trait_objects)]` on by default - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> - error[E0747]: type provided when a constant was expected --> $DIR/const-expression-suggest-missing-braces.rs:11:11 | LL | foo::<BAR + BAR>(); | ^^^^^^^^^ -error: aborting due to 14 previous errors; 1 warning emitted +error: aborting due to 14 previous errors Some errors have detailed explanations: E0404, E0747. For more information about an error, try `rustc --explain E0404`. diff --git a/src/test/ui/const-generics/min_const_generics/const_default_first.rs b/src/test/ui/const-generics/min_const_generics/const_default_first.rs index bba4e68d4cc..eafafb8a274 100644 --- a/src/test/ui/const-generics/min_const_generics/const_default_first.rs +++ b/src/test/ui/const-generics/min_const_generics/const_default_first.rs @@ -1,6 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics_defaults)] -#![allow(incomplete_features, dead_code)] +#![allow(dead_code)] struct Both<const N: usize=3, T> { //~^ ERROR: generic parameters with a default must be diff --git a/src/test/ui/const-generics/min_const_generics/const_default_first.stderr b/src/test/ui/const-generics/min_const_generics/const_default_first.stderr index 1a333642f0c..0d5a393cb7b 100644 --- a/src/test/ui/const-generics/min_const_generics/const_default_first.stderr +++ b/src/test/ui/const-generics/min_const_generics/const_default_first.stderr @@ -1,5 +1,5 @@ error: generic parameters with a default must be trailing - --> $DIR/const_default_first.rs:5:19 + --> $DIR/const_default_first.rs:4:19 | LL | struct Both<const N: usize=3, T> { | ^ diff --git a/src/test/ui/const-generics/min_const_generics/default_function_param.rs b/src/test/ui/const-generics/min_const_generics/default_function_param.rs index b47dd2f618c..92d495ef665 100644 --- a/src/test/ui/const-generics/min_const_generics/default_function_param.rs +++ b/src/test/ui/const-generics/min_const_generics/default_function_param.rs @@ -1,5 +1,4 @@ #![crate_type = "lib"] -#![feature(const_generics_defaults)] fn foo<const SIZE: usize = 5usize>() {} //~^ ERROR defaults for const parameters are diff --git a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr index 11df8621faa..07dcd57dab8 100644 --- a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr +++ b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr @@ -1,5 +1,5 @@ error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default_function_param.rs:4:14 + --> $DIR/default_function_param.rs:3:14 | LL | fn foo<const SIZE: usize = 5usize>() {} | ^^^^ diff --git a/src/test/ui/const-generics/min_const_generics/default_trait_param.rs b/src/test/ui/const-generics/min_const_generics/default_trait_param.rs index 14bac473ed9..9cd5e3279ff 100644 --- a/src/test/ui/const-generics/min_const_generics/default_trait_param.rs +++ b/src/test/ui/const-generics/min_const_generics/default_trait_param.rs @@ -1,4 +1,4 @@ +// check-pass trait Foo<const KIND: bool = true> {} -//~^ ERROR default values for const generic parameters are experimental fn main() {} diff --git a/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr b/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr deleted file mode 100644 index 5617b35ad01..00000000000 --- a/src/test/ui/const-generics/min_const_generics/default_trait_param.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: default values for const generic parameters are experimental - --> $DIR/default_trait_param.rs:1:28 - | -LL | trait Foo<const KIND: bool = true> {} - | ^^^^^^ - | - = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information - = help: add `#![feature(const_generics_defaults)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs b/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs index 2adfa9a8c4b..fa119c59f61 100644 --- a/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs +++ b/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_generics_defaults)] #![allow(dead_code)] struct Both<T=u32, const N: usize=3> { diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr index 17defbe86aa..a5e70f6b9e6 100644 --- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr @@ -3,8 +3,6 @@ error: generic parameters with a default must be trailing | 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: generic parameters may not be used in const operations --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:5:44 diff --git a/src/test/ui/const-generics/type-after-const-ok.rs b/src/test/ui/const-generics/type-after-const-ok.rs index 68d1940160c..f37b0b10233 100644 --- a/src/test/ui/const-generics/type-after-const-ok.rs +++ b/src/test/ui/const-generics/type-after-const-ok.rs @@ -1,11 +1,6 @@ -// [full] run-pass -// revisions: full min +// run-pass // Verifies that having generic parameters after constants is permitted -#![cfg_attr(full, feature(const_generics_defaults))] -#![cfg_attr(full, allow(incomplete_features))] - #[allow(dead_code)] struct A<const N: usize, T>(T); -//[min]~^ ERROR type parameters must be declared prior to const parameters fn main() {} |
