diff options
| author | lcnr <rust@lcnr.de> | 2021-08-27 18:04:57 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2021-08-30 11:00:21 +0200 |
| commit | 0c28e028b6f45f33447f24de7dd762b8599b7a4e (patch) | |
| tree | 3a573ebc79c4aefed676f4a693ebb62d32ea4e7f /src/test/ui/const-generics/generic_const_exprs | |
| parent | c0e853f274c42665373b719a5bd7b3f95afe10c2 (diff) | |
| download | rust-0c28e028b6f45f33447f24de7dd762b8599b7a4e.tar.gz rust-0c28e028b6f45f33447f24de7dd762b8599b7a4e.zip | |
`feature(const_generics)` -> `feature(const_param_types)`
Diffstat (limited to 'src/test/ui/const-generics/generic_const_exprs')
76 files changed, 920 insertions, 83 deletions
diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs index 4d7c4e003d0..06f00de13a3 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const N: u8>([u8; N as usize]) diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs index 08b46c4c4a3..3b5b87b2b3d 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Evaluatable<const N: u128> {} diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs index 0cb5410ed26..7561ae2febb 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs index 66afe517835..184263f899a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr new file mode 100644 index 00000000000..deb6f3bd12c --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr @@ -0,0 +1,18 @@ +error: unconstrained generic constant + --> $DIR/array-size-in-generic-struct-param.rs:8:38 + | +LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]); + | ^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); 0 + N]:` + +error: overly complex generic constant + --> $DIR/array-size-in-generic-struct-param.rs:19:15 + | +LL | arr: [u8; CFG.arr_size], + | ^^^^^^^^^^^^ unsupported projection + | + = help: consider moving this anonymous constant into a `const` function + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr new file mode 100644 index 00000000000..22e7ab1f7b1 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr @@ -0,0 +1,29 @@ +error: generic parameters may not be used in const operations + --> $DIR/array-size-in-generic-struct-param.rs:8:48 + | +LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]); + | ^ cannot perform const operation using `N` + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: generic parameters may not be used in const operations + --> $DIR/array-size-in-generic-struct-param.rs:19:15 + | +LL | arr: [u8; CFG.arr_size], + | ^^^ cannot perform const operation using `CFG` + | + = help: const parameters may only be used as standalone arguments, i.e. `CFG` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: `Config` is forbidden as the type of a const generic parameter + --> $DIR/array-size-in-generic-struct-param.rs:17:21 + | +LL | struct B<const CFG: Config> { + | ^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` + = help: more complex types are supported with `#![feature(const_param_types)]` + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs new file mode 100644 index 00000000000..68201b77dbf --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs @@ -0,0 +1,29 @@ +// Tests that array sizes that depend on const-params are checked using `ConstEvaluatable`. +// revisions: full min + +#![cfg_attr(full, feature(generic_const_exprs, const_param_types))] +#![cfg_attr(full, allow(incomplete_features))] + +#[allow(dead_code)] +struct ArithArrayLen<const N: usize>([u32; 0 + N]); +//[full]~^ ERROR unconstrained generic constant +//[min]~^^ ERROR generic parameters may not be used in const operations + +#[derive(PartialEq, Eq)] +struct Config { + arr_size: usize, +} + +struct B<const CFG: Config> { + //[min]~^ ERROR `Config` is forbidden + arr: [u8; CFG.arr_size], + //[full]~^ ERROR overly complex generic constant + //[min]~^^ ERROR generic parameters may not be used in const operations +} + +const C: Config = Config { arr_size: 5 }; + +fn main() { + let b = B::<C> { arr: [1, 2, 3, 4, 5] }; + assert_eq!(b.arr.len(), 5); +} diff --git a/src/test/ui/const-generics/generic_const_exprs/associated-const.rs b/src/test/ui/const-generics/generic_const_exprs/associated-const.rs new file mode 100644 index 00000000000..a6777632254 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/associated-const.rs @@ -0,0 +1,11 @@ +// check-pass +struct Foo<T>(T); +impl<T> Foo<T> { + const VALUE: usize = std::mem::size_of::<T>(); +} + +fn test<T>() { + let _ = [0; Foo::<u8>::VALUE]; +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs index 967d1b0f2ac..4d89f188ad7 100644 --- a/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs +++ b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub trait BlockCipher { diff --git a/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs index ce92f908e06..15d618caef4 100644 --- a/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs +++ b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.rs b/src/test/ui/const-generics/generic_const_exprs/closures.rs index c682fee4fab..847843fe1a6 100644 --- a/src/test/ui/const-generics/generic_const_exprs/closures.rs +++ b/src/test/ui/const-generics/generic_const_exprs/closures.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test<const N: usize>() -> [u8; N + (|| 42)()] {} //~^ ERROR overly complex generic constant diff --git a/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs index a8388fc541c..dfc69e0b068 100644 --- a/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs @@ -1,6 +1,6 @@ // aux-build:const_evaluatable_lib.rs // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs index 4e3aeec9c5d..b08fffd6922 100644 --- a/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs @@ -1,5 +1,5 @@ // aux-build:const_evaluatable_lib.rs -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/generic_const_exprs/different-fn.rs b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs index 0dcafc6a789..e8bc703bda6 100644 --- a/src/test/ui/const-generics/generic_const_exprs/different-fn.rs +++ b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/generic_const_exprs/division.rs b/src/test/ui/const-generics/generic_const_exprs/division.rs index c10ed834f0f..098fa9e0447 100644 --- a/src/test/ui/const-generics/generic_const_exprs/division.rs +++ b/src/test/ui/const-generics/generic_const_exprs/division.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn with_bound<const N: usize>() where [u8; N / 2]: Sized { diff --git a/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs index c99cfa6f52f..3543960c3eb 100644 --- a/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_generics)] #![feature(generic_const_exprs)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs index 45f63bad6fe..077f77aa0f4 100644 --- a/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs +++ b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs @@ -1,5 +1,5 @@ //check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const N: usize> diff --git a/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs index 3c6f01b6160..e4111157ecd 100644 --- a/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs +++ b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs @@ -1,7 +1,7 @@ // run-pass // Test that we use the elaborated predicates from traits // to satisfy const evaluatable predicates. -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; 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 f9d78fd708c..80d0662f1f4 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 @@ -1,5 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub struct Const<const U: u8>; diff --git a/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs index 8acb7aaf34e..340e35e1c65 100644 --- a/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs @@ -4,7 +4,7 @@ // only contain generic parameters. This is incorrect as trying to unify `N > 1` with `M > 1` // should fail. #![allow(incomplete_features)] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] enum Assert<const COND: bool> {} trait IsTrue {} diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr deleted file mode 100644 index 26dfcff5d3e..00000000000 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/feature-gate-generic_const_exprs.rs:8:30 - | -LL | fn test<const N: usize>() -> Arr<N> where Arr<N>: Default { - | ^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs index f49ca0251aa..10ab2fd867c 100644 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs @@ -1,12 +1,7 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - type Arr<const N: usize> = [u8; N - 1]; -//[min]~^ ERROR generic parameters may not be used in const operations +//~^ ERROR generic parameters may not be used in const operations fn test<const N: usize>() -> Arr<N> where Arr<N>: Default { - //[full]~^ ERROR constant expression depends Default::default() } diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr index fccd6ea144b..2d60ebaa83a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr @@ -1,11 +1,11 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-generic_const_exprs.rs:5:33 + --> $DIR/feature-gate-generic_const_exprs.rs:1:33 | LL | type Arr<const N: usize> = [u8; 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(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/generic_const_exprs/fn_call.rs b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs index a1b2a52a5a1..cbe4277df56 100644 --- a/src/test/ui/const-generics/generic_const_exprs/fn_call.rs +++ b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] const fn test_me<T>(a: usize, b: usize) -> usize { diff --git a/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs index db097567a15..90953145944 100644 --- a/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test<const N: usize>() -> [u8; N - 1] { diff --git a/src/test/ui/const-generics/generic_const_exprs/from-sig.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs index d2e672bae4d..28de4f86467 100644 --- a/src/test/ui/const-generics/generic_const_exprs/from-sig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const B: bool>; diff --git a/src/test/ui/const-generics/generic_const_exprs/function-call.rs b/src/test/ui/const-generics/generic_const_exprs/function-call.rs new file mode 100644 index 00000000000..b5de66621c5 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/function-call.rs @@ -0,0 +1,19 @@ +// check-pass + +const fn foo<T>() -> usize { + // We might instead branch on `std::mem::size_of::<*mut T>() < 8` here, + // which would cause this function to fail on 32 bit systems. + if false { + std::mem::size_of::<T>() + } else { + 8 + } +} + +fn test<T>() { + let _ = [0; foo::<T>()]; + //~^ WARN cannot use constants which depend on generic parameters in types + //~| WARN this was previously accepted by the compiler but is being phased out +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/function-call.stderr b/src/test/ui/const-generics/generic_const_exprs/function-call.stderr new file mode 100644 index 00000000000..0d8463714e8 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/function-call.stderr @@ -0,0 +1,12 @@ +warning: cannot use constants which depend on generic parameters in types + --> $DIR/function-call.rs:14:17 + | +LL | let _ = [0; foo::<T>()]; + | ^^^^^^^^^^ + | + = note: `#[warn(const_evaluatable_unchecked)]` 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 #76200 <https://github.com/rust-lang/rust/issues/76200> + +warning: 1 warning emitted + diff --git a/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs index d3f140755f7..7120d6ee251 100644 --- a/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs index 4c8fc7a3554..b8058c252e7 100644 --- a/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs +++ b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::{mem, ptr}; diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr new file mode 100644 index 00000000000..f2ae361dc81 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/issue-62504.rs:18:21 + | +LL | ArrayHolder([0; Self::SIZE]) + | ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE` + | + = note: expected type `X` + found type `Self::SIZE` + +error: unconstrained generic constant + --> $DIR/issue-62504.rs:18:25 + | +LL | ArrayHolder([0; Self::SIZE]) + | ^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::SIZE]:` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-62504.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-62504.min.stderr new file mode 100644 index 00000000000..5d45e302888 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-62504.min.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/issue-62504.rs:18:21 + | +LL | ArrayHolder([0; Self::SIZE]) + | ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE` + | + = note: expected array `[u32; X]` + found array `[u32; _]` + +error: constant expression depends on a generic parameter + --> $DIR/issue-62504.rs:18:25 + | +LL | ArrayHolder([0; Self::SIZE]) + | ^^^^^^^^^^ + | + = note: this may fail depending on what value the parameter takes + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-62504.rs b/src/test/ui/const-generics/generic_const_exprs/issue-62504.rs new file mode 100644 index 00000000000..a97f4b8ff31 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-62504.rs @@ -0,0 +1,27 @@ +// revisions: full min +#![allow(incomplete_features)] +#![cfg_attr(full, feature(generic_const_exprs))] +#![cfg_attr(full, allow(incomplete_features))] + +trait HasSize { + const SIZE: usize; +} + +impl<const X: usize> HasSize for ArrayHolder<X> { + const SIZE: usize = X; +} + +struct ArrayHolder<const X: usize>([u32; X]); + +impl<const X: usize> ArrayHolder<X> { + pub const fn new() -> Self { + ArrayHolder([0; Self::SIZE]) + //~^ ERROR mismatched types + //[full]~^^ ERROR unconstrained generic constant + //[min]~^^^ ERROR constant expression depends on a generic parameter + } +} + +fn main() { + let mut array = ArrayHolder::new(); +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-69654.rs b/src/test/ui/const-generics/generic_const_exprs/issue-69654.rs new file mode 100644 index 00000000000..9b36699bbf1 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-69654.rs @@ -0,0 +1,19 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait Bar<T> {} +impl<T> Bar<T> for [u8; T] {} +//~^ ERROR expected value, found type parameter `T` + +struct Foo<const N: usize> {} +impl<const N: usize> Foo<N> +where + [u8; N]: Bar<[(); N]>, +{ + fn foo() {} +} + +fn main() { + Foo::foo(); + //~^ ERROR the function or associated item +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr new file mode 100644 index 00000000000..0ce7640f685 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr @@ -0,0 +1,22 @@ +error[E0423]: expected value, found type parameter `T` + --> $DIR/issue-69654.rs:5:25 + | +LL | impl<T> Bar<T> for [u8; T] {} + | ^ not a value + +error[E0599]: the function or associated item `foo` exists for struct `Foo<{_: usize}>`, but its trait bounds were not satisfied + --> $DIR/issue-69654.rs:17:10 + | +LL | struct Foo<const N: usize> {} + | -------------------------- function or associated item `foo` not found for this +... +LL | Foo::foo(); + | ^^^ function or associated item cannot be called on `Foo<{_: usize}>` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `[u8; _]: Bar<[(); _]>` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0423, E0599. +For more information about an error, try `rustc --explain E0423`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr new file mode 100644 index 00000000000..3c7a740e843 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr @@ -0,0 +1,65 @@ +error: generic parameters may not be used in const operations + --> $DIR/issue-72787.rs:11:17 + | +LL | Condition<{ LHS <= RHS }>: True + | ^^^ cannot perform const operation using `LHS` + | + = help: const parameters may only be used as standalone arguments, i.e. `LHS` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: generic parameters may not be used in const operations + --> $DIR/issue-72787.rs:11:24 + | +LL | Condition<{ LHS <= RHS }>: True + | ^^^ cannot perform const operation using `RHS` + | + = help: const parameters may only be used as standalone arguments, i.e. `RHS` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: generic parameters may not be used in const operations + --> $DIR/issue-72787.rs:25:25 + | +LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, + | ^ cannot perform const operation using `I` + | + = help: const parameters may only be used as standalone arguments, i.e. `I` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: generic parameters may not be used in const operations + --> $DIR/issue-72787.rs:25:36 + | +LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, + | ^ cannot perform const operation using `J` + | + = help: const parameters may only be used as standalone arguments, i.e. `J` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error[E0283]: type annotations needed + --> $DIR/issue-72787.rs:21:26 + | +LL | IsLessOrEqual<I, 8>: True, + | ^^^^ cannot infer type for struct `IsLessOrEqual<I, 8_u32>` + | + = note: cannot satisfy `IsLessOrEqual<I, 8_u32>: True` +note: required by a bound in `True` + --> $DIR/issue-72787.rs:8:1 + | +LL | pub trait True {} + | ^^^^^^^^^^^^^^ required by this bound in `True` + +error[E0283]: type annotations needed + --> $DIR/issue-72787.rs:21:26 + | +LL | IsLessOrEqual<I, 8>: True, + | ^^^^ cannot infer type for struct `IsLessOrEqual<I, 8_u32>` + | + = note: cannot satisfy `IsLessOrEqual<I, 8_u32>: True` +note: required by a bound in `True` + --> $DIR/issue-72787.rs:8:1 + | +LL | pub trait True {} + | ^^^^^^^^^^^^^^ required by this bound in `True` + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs new file mode 100644 index 00000000000..77ad57f0640 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs @@ -0,0 +1,35 @@ +// [full] check-pass +// revisions: full min +#![cfg_attr(full, feature(generic_const_exprs))] +#![cfg_attr(full, allow(incomplete_features))] + +pub struct IsLessOrEqual<const LHS: u32, const RHS: u32>; +pub struct Condition<const CONDITION: bool>; +pub trait True {} + +impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where + Condition<{ LHS <= RHS }>: True +//[min]~^ Error generic parameters may not be used in const operations +//[min]~| Error generic parameters may not be used in const operations +{ +} +impl True for Condition<true> {} + +struct S<const I: u32, const J: u32>; +impl<const I: u32, const J: u32> S<I, J> +where + IsLessOrEqual<I, 8>: True, +//[min]~^ Error type annotations needed [E0283] +//[min]~| Error type annotations needed [E0283] + IsLessOrEqual<J, 8>: True, + IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, +//[min]~^ Error generic parameters may not be used in const operations +//[min]~| Error generic parameters may not be used in const operations + // Condition<{ 8 - I <= 8 - J }>: True, +{ + fn print() { + println!("I {} J {}", I, J); + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr new file mode 100644 index 00000000000..d536f6fd1d5 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/issue-72819-generic-in-const-eval.rs:20:12 + | +LL | let x: Arr<{usize::MAX}> = Arr {}; + | ^^^^^^^^^^^^^^^^^ expected `false`, found `true` + | + = note: expected type `false` + found type `true` + +error[E0308]: mismatched types + --> $DIR/issue-72819-generic-in-const-eval.rs:20:32 + | +LL | let x: Arr<{usize::MAX}> = Arr {}; + | ^^^ expected `false`, found `true` + | + = note: expected type `false` + found type `true` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr new file mode 100644 index 00000000000..42671412fa7 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr @@ -0,0 +1,11 @@ +error: generic parameters may not be used in const operations + --> $DIR/issue-72819-generic-in-const-eval.rs:8:17 + | +LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, + | ^ cannot perform const operation using `N` + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs new file mode 100644 index 00000000000..7a5aa9e47d4 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs @@ -0,0 +1,23 @@ +// Regression test for #72819: ICE due to failure in resolving the const generic in `Arr`'s type +// bounds. +// revisions: full min +#![cfg_attr(full, feature(generic_const_exprs))] +#![cfg_attr(full, allow(incomplete_features))] + +struct Arr<const N: usize> +where Assert::<{N < usize::MAX / 2}>: IsTrue, +//[min]~^ ERROR generic parameters may not be used in const operations +{ +} + +enum Assert<const CHECK: bool> {} + +trait IsTrue {} + +impl IsTrue for Assert<true> {} + +fn main() { + let x: Arr<{usize::MAX}> = Arr {}; + //[full]~^ ERROR mismatched types + //[full]~| ERROR mismatched types +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-73899.rs b/src/test/ui/const-generics/generic_const_exprs/issue-73899.rs new file mode 100644 index 00000000000..d1ab1be0473 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-73899.rs @@ -0,0 +1,20 @@ +// run-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait Foo {} + +impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} + +trait FooImpl<const IS_ZERO: bool> {} + +impl FooImpl<{ 0u8 == 0u8 }> for [(); 0] {} + +impl<const N: usize> FooImpl<{ 0u8 != 0u8 }> for [(); N] {} + +fn foo<T: Foo>(_v: T) {} + +fn main() { + foo([]); + foo([()]); +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-74634.rs b/src/test/ui/const-generics/generic_const_exprs/issue-74634.rs new file mode 100644 index 00000000000..cd1f7a9da68 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-74634.rs @@ -0,0 +1,28 @@ +// check-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait If<const COND: bool> {} +impl If<true> for () {} + +trait IsZero<const N: u8> { + type Answer; +} + +struct True; +struct False; + +impl<const N: u8> IsZero<N> for () +where (): If<{N == 0}> { + type Answer = True; +} + +trait Foobar<const N: u8> {} + +impl<const N: u8> Foobar<N> for () +where (): IsZero<N, Answer = True> {} + +impl<const N: u8> Foobar<N> for () +where (): IsZero<N, Answer = False> {} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-76595.rs b/src/test/ui/const-generics/generic_const_exprs/issue-76595.rs new file mode 100644 index 00000000000..faa8b3d10de --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-76595.rs @@ -0,0 +1,17 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Bool<const B: bool>; + +trait True {} + +impl True for Bool<true> {} + +fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True { + todo!() +} + +fn main() { + test::<2>(); + //~^ ERROR this function takes 2 generic arguments +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr new file mode 100644 index 00000000000..3b69a4066a9 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr @@ -0,0 +1,21 @@ +error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-76595.rs:15:5 + | +LL | test::<2>(); + | ^^^^ - supplied 1 generic argument + | | + | expected 2 generic arguments + | +note: function defined here, with 2 generic parameters: `T`, `P` + --> $DIR/issue-76595.rs:10:4 + | +LL | fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True { + | ^^^^ - - +help: add missing generic argument + | +LL | test::<2, P>(); + | +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs new file mode 100644 index 00000000000..2fa9a71fbb3 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs @@ -0,0 +1,21 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +// This test is a minimized reproduction for #79518 where +// during error handling for the type mismatch we would try +// to evaluate std::mem::size_of::<Self::Assoc> causing an ICE + +trait Foo { + type Assoc: PartialEq; + const AssocInstance: Self::Assoc; + + fn foo() + where + [(); std::mem::size_of::<Self::Assoc>()]: , + { + Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()]; + //~^ Error: mismatched types + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr new file mode 100644 index 00000000000..c90774e944f --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-79518-default_trait_method_normalization.rs:16:32 + | +LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]` + | + = note: expected associated type `<Self as Foo>::Assoc` + found array `[(); _]` + = help: consider constraining the associated type `<Self as Foo>::Assoc` to `[(); _]` or calling a method that returns `<Self as Foo>::Assoc` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs b/src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs new file mode 100644 index 00000000000..77d3c98dab9 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs @@ -0,0 +1,24 @@ +// check-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +// This tests that the correct `param_env` is used so that +// attempting to normalize `Self::N` does not cause an ICE. + +pub struct Foo<const N: usize>; + +impl<const N: usize> Foo<N> { + pub fn foo() {} +} + +pub trait Bar { + const N: usize; + fn bar() + where + [(); Self::N]: , + { + Foo::<{ Self::N }>::foo(); + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-80742.rs b/src/test/ui/const-generics/generic_const_exprs/issue-80742.rs new file mode 100644 index 00000000000..275f6995302 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80742.rs @@ -0,0 +1,32 @@ +// check-fail + +// This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +use std::fmt::Debug; +use std::marker::PhantomData; +use std::mem::size_of; + +struct Inline<T> +where + [u8; size_of::<T>() + 1]: , +{ + _phantom: PhantomData<T>, + buf: [u8; size_of::<T>() + 1], +} + +impl<T> Inline<T> +where + [u8; size_of::<T>() + 1]: , +{ + pub fn new(val: T) -> Inline<T> { + todo!() + } +} + +fn main() { + let dst = Inline::<dyn Debug>::new(0); //~ ERROR + //~^ ERROR +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr new file mode 100644 index 00000000000..56cb11bacbe --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr @@ -0,0 +1,72 @@ +error[E0080]: evaluation of `Inline::<dyn std::fmt::Debug>::{constant#0}` failed + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | intrinsics::size_of::<T>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | size_of called on unsized type `dyn Debug` + | inside `std::mem::size_of::<dyn Debug>` at $SRC_DIR/core/src/mem/mod.rs:LL:COL + | + ::: $DIR/issue-80742.rs:22:10 + | +LL | [u8; size_of::<T>() + 1]: , + | -------------- inside `Inline::<dyn Debug>::{constant#0}` at $DIR/issue-80742.rs:22:10 + +error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied + --> $DIR/issue-80742.rs:30:36 + | +LL | / struct Inline<T> +LL | | where +LL | | [u8; size_of::<T>() + 1]: , +LL | | { +LL | | _phantom: PhantomData<T>, +LL | | buf: [u8; size_of::<T>() + 1], +LL | | } + | |_- function or associated item `new` not found for this +... +LL | let dst = Inline::<dyn Debug>::new(0); + | ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds + | + ::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL + | +LL | pub trait Debug { + | --------------- doesn't satisfy `dyn Debug: Sized` + | + = note: the following trait bounds were not satisfied: + `dyn Debug: Sized` + +error[E0080]: evaluation of `Inline::<dyn std::fmt::Debug>::{constant#0}` failed + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | intrinsics::size_of::<T>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | size_of called on unsized type `dyn Debug` + | inside `std::mem::size_of::<dyn Debug>` at $SRC_DIR/core/src/mem/mod.rs:LL:COL + | + ::: $DIR/issue-80742.rs:14:10 + | +LL | [u8; size_of::<T>() + 1]: , + | -------------- inside `Inline::<dyn Debug>::{constant#0}` at $DIR/issue-80742.rs:14:10 + +error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time + --> $DIR/issue-80742.rs:30:15 + | +LL | let dst = Inline::<dyn Debug>::new(0); + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `dyn Debug` +note: required by a bound in `Inline` + --> $DIR/issue-80742.rs:12:15 + | +LL | struct Inline<T> + | ^ required by this bound in `Inline` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct Inline<T: ?Sized> + | ++++++++ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0080, E0277, E0599. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-83765.rs b/src/test/ui/const-generics/generic_const_exprs/issue-83765.rs new file mode 100644 index 00000000000..fac811d1302 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-83765.rs @@ -0,0 +1,38 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait TensorDimension { + const DIM: usize; +} + +trait TensorSize: TensorDimension { + fn size(&self) -> [usize; Self::DIM]; +} + +trait Broadcastable: TensorSize + Sized { + type Element; + fn lazy_updim<const NEWDIM: usize>(&self, size: [usize; NEWDIM]) {} +} + +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] { + //~^ ERROR: method not compatible with trait [E0308] + self.reference.size() + //~^ ERROR: unconstrained generic constant + //~| ERROR: mismatched types + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-83765.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-83765.stderr new file mode 100644 index 00000000000..ef785bf07eb --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-83765.stderr @@ -0,0 +1,29 @@ +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:30:5 + | +LL | fn size(&self) -> [usize; DIM] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:32:24 + | +LL | self.reference.size() + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:32:9 + | +LL | self.reference.size() + | ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM` + | + = note: expected type `DIM` + found type `Self::DIM` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-84408.rs b/src/test/ui/const-generics/generic_const_exprs/issue-84408.rs new file mode 100644 index 00000000000..fb2e5590d21 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-84408.rs @@ -0,0 +1,38 @@ +// Regression test for #84408. +// check-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait Melon<const X: usize> { + fn new(arr: [i32; X]) -> Self; + fn change<T: Melon<X>>(self) -> T; +} + +struct Foo([i32; 5]); +struct Bar<const A: usize, const B: usize>([i32; A + B]) +where + [(); A + B]: ; + +impl Melon<5> for Foo { + fn new(arr: [i32; 5]) -> Self { + Foo(arr) + } + fn change<T: Melon<5>>(self) -> T { + T::new(self.0) + } +} + +impl<const A: usize, const B: usize> Melon<{ A + B }> for Bar<A, B> +where + [(); A + B]: , +{ + fn new(arr: [i32; A + B]) -> Self { + Bar(arr) + } + fn change<T: Melon<{ A + B }>>(self) -> T { + T::new(self.0) + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-85848.rs b/src/test/ui/const-generics/generic_const_exprs/issue-85848.rs new file mode 100644 index 00000000000..771e68b0db5 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-85848.rs @@ -0,0 +1,31 @@ +#![feature(const_fn_trait_bound, generic_const_exprs)] +#![allow(incomplete_features)] + +trait _Contains<T> { + const does_contain: bool; +} + +trait Contains<T, const Satisfied: bool> {} + +trait Delegates<T> {} + +impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + +const fn contains<A, B>() -> bool +where + A: _Contains<B>, +{ + A::does_contain +} + +impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + +fn writes_to_path<C>(cap: &C) { + writes_to_specific_path(&cap); + //~^ ERROR: the trait bound `(): _Contains<&C>` is not satisfied [E0277] + //~| ERROR: unconstrained generic constant +} + +fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-85848.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-85848.stderr new file mode 100644 index 00000000000..e51db35925e --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-85848.stderr @@ -0,0 +1,48 @@ +error[E0277]: the trait bound `(): _Contains<&C>` is not satisfied + --> $DIR/issue-85848.rs:24:5 + | +LL | writes_to_specific_path(&cap); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `_Contains<&C>` is not implemented for `()` + | +note: required because of the requirements on the impl of `Contains<(), true>` for `&C` + --> $DIR/issue-85848.rs:21:12 + | +LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ +note: required because of the requirements on the impl of `Delegates<()>` for `&C` + --> $DIR/issue-85848.rs:12:12 + | +LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + | ^^^^^^^^^^^^ ^ +note: required by a bound in `writes_to_specific_path` + --> $DIR/issue-85848.rs:29:31 + | +LL | fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + | ^^^^^^^^^^^^^ required by this bound in `writes_to_specific_path` + +error: unconstrained generic constant + --> $DIR/issue-85848.rs:24:5 + | +LL | writes_to_specific_path(&cap); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); { contains::<T, U>() }]:` +note: required because of the requirements on the impl of `Contains<(), true>` for `&C` + --> $DIR/issue-85848.rs:21:12 + | +LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ +note: required because of the requirements on the impl of `Delegates<()>` for `&C` + --> $DIR/issue-85848.rs:12:12 + | +LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + | ^^^^^^^^^^^^ ^ +note: required by a bound in `writes_to_specific_path` + --> $DIR/issue-85848.rs:29:31 + | +LL | fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + | ^^^^^^^^^^^^^ required by this bound in `writes_to_specific_path` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/generic_const_exprs/less_than.rs b/src/test/ui/const-generics/generic_const_exprs/less_than.rs index 31fe9a53f03..2e9af1bf4f0 100644 --- a/src/test/ui/const-generics/generic_const_exprs/less_than.rs +++ b/src/test/ui/const-generics/generic_const_exprs/less_than.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const B: bool>; diff --git a/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs index ea5c95a7444..cd5d76dd949 100644 --- a/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs +++ b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // We do not yet want to support let-bindings in abstract consts, diff --git a/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs new file mode 100644 index 00000000000..2bd3c801fbf --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +const fn complex_maths<T>(n : usize) -> usize { + 2 * n + 1 +} + +struct Example<T, const N: usize> { + a: [f32; N], + b: [f32; complex_maths::<T>(N)], + //~^ ERROR unconstrained + c: T, +} diff --git a/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.stderr b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.stderr new file mode 100644 index 00000000000..7b41e39b7d7 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.stderr @@ -0,0 +1,10 @@ +error: unconstrained generic constant + --> $DIR/needs_where_clause.rs:11:6 + | +LL | b: [f32; complex_maths::<T>(N)], + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); complex_maths::<T>(N)]:` + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs index e70bdad9084..7e5022817e4 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn callee<const M2: usize>() -> usize diff --git a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs index aed3f476f1d..769e3ae6895 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Generic<const K: u64>; diff --git a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs index a86918adfa7..316887e5e7f 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn zero_init<const N: usize>() -> Substs1<N> diff --git a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs index 72fd39b96f8..d45a6465b76 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, unused_parens, unused_braces)] fn zero_init<const N: usize>() -> Substs1<{ (N) }> diff --git a/src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs new file mode 100644 index 00000000000..9c5de03170b --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs @@ -0,0 +1,29 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features, unused)] + +const fn complex_maths(n : usize) -> usize { + 2 * n + 1 +} + +pub struct Example<const N: usize> { + a: [f32; N], + b: [f32; complex_maths(N)], + //~^ ERROR unconstrained generic +} + +impl<const N: usize> Example<N> { + pub fn new() -> Self { + Self { + a: [0.; N], + b: [0.; complex_maths(N)], + } + } +} + +impl Example<2> { + pub fn sum(&self) -> f32 { + self.a.iter().sum::<f32>() + self.b.iter().sum::<f32>() + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/no_where_clause.stderr b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.stderr new file mode 100644 index 00000000000..3e5c2f5cad1 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.stderr @@ -0,0 +1,10 @@ +error: unconstrained generic constant + --> $DIR/no_where_clause.rs:10:6 + | +LL | b: [f32; complex_maths(N)], + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); complex_maths(N)]:` + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs index 81a634a4173..24d333aba0f 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs index 22ff9f41276..42c1cc507b5 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] #![deny(where_clauses_object_safety)] diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs index e421c43dd94..c6c196db6f2 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Foo<const N: usize> { diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs index 0ab8be80f37..f4c89f6235a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Foo<const N: usize> { diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr deleted file mode 100644 index f6192bbe9ca..00000000000 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/simple_fail.rs:6:33 - | -LL | type Arr<const N: usize> = [u8; 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(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/simple_fail.rs:10:48 - | -LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized { - | ^ 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(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs index db2f94b7fce..c47a350c7fb 100644 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs @@ -1,15 +1,11 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, feature(generic_const_exprs))] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] type Arr<const N: usize> = [u8; N - 1]; -//[min]~^ ERROR generic parameters may not be used in const operations -//[full]~^^ ERROR evaluation of `Arr::<0_usize>::{constant#0}` failed +//~^ ERROR evaluation of `Arr::<0_usize>::{constant#0}` failed fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized { -//[min]~^ ERROR generic parameters may not be used in const operations -//[full]~^^ ERROR evaluation of `test::<0_usize>::{constant#0}` failed +//~^ ERROR evaluation of `test::<0_usize>::{constant#0}` failed todo!() } diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.stderr index 1f2313a6028..99fc92fb4f0 100644 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.stderr @@ -1,11 +1,11 @@ error[E0080]: evaluation of `test::<0_usize>::{constant#0}` failed - --> $DIR/simple_fail.rs:10:48 + --> $DIR/simple_fail.rs:7:48 | LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized { | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow error[E0080]: evaluation of `Arr::<0_usize>::{constant#0}` failed - --> $DIR/simple_fail.rs:6:33 + --> $DIR/simple_fail.rs:4:33 | LL | type Arr<const N: usize> = [u8; N - 1]; | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow diff --git a/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs index 71c594657e0..d6574a3aa2f 100644 --- a/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn make_array<const M: usize>() -> [(); M + 1] { diff --git a/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs index abb9df16288..d058b363850 100644 --- a/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs +++ b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs @@ -1,6 +1,6 @@ // check-pass // Test that we correctly substitute generic arguments for type aliases. -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] type Alias<T, const N: usize> = [T; N + 1]; diff --git a/src/test/ui/const-generics/generic_const_exprs/unop.rs b/src/test/ui/const-generics/generic_const_exprs/unop.rs index e0e373b62f9..c12fef083cc 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unop.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unop.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo<const B: bool>; 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 c0da46d6d5f..67fefd07ec0 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(const_generics, generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics_defaults)] #![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/generic_const_exprs/unused_expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs index 44b6530f22e..c1bf19e0f8d 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn add<const N: usize>() -> [u8; { N + 1; 5 }] { |
