diff options
| author | Boxy <supbscripter@gmail.com> | 2024-06-04 09:10:08 +0100 |
|---|---|---|
| committer | Boxy <supbscripter@gmail.com> | 2024-06-05 22:25:42 +0100 |
| commit | f74119a2e4a5c040c054ebee1ae2ccda828fd21f (patch) | |
| tree | f74f411f1cd0b38b54711cd64b8c9f845050abc7 /tests/ui/const-generics/generic_const_exprs | |
| parent | 7fa98d0c01050ee8c39bfc644d1414f5a21a1f21 (diff) | |
| download | rust-f74119a2e4a5c040c054ebee1ae2ccda828fd21f.tar.gz rust-f74119a2e4a5c040c054ebee1ae2ccda828fd21f.zip | |
Bless tests and handle tests/crashes
Diffstat (limited to 'tests/ui/const-generics/generic_const_exprs')
4 files changed, 71 insertions, 4 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs b/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs new file mode 100644 index 00000000000..29ad935c014 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs @@ -0,0 +1,21 @@ +//@ compile-flags: -Znext-solver=coherence + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub struct A<const z: [usize; x]> {} +//~^ ERROR: cannot find value `x` in this scope +//~| ERROR: `[usize; x]` is forbidden as the type of a const generic parameter + +impl A<2> { + //~^ ERROR: mismatched types + pub const fn B() {} + //~^ ERROR: duplicate definitions +} + +impl A<2> { + //~^ ERROR: mismatched types + pub const fn B() {} +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr new file mode 100644 index 00000000000..0e40255bcf5 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr @@ -0,0 +1,45 @@ +error[E0425]: cannot find value `x` in this scope + --> $DIR/error_in_ty.rs:6:31 + | +LL | pub struct A<const z: [usize; x]> {} + | - ^ help: a const parameter with a similar name exists: `z` + | | + | similarly named const parameter `z` defined here + +error: `[usize; x]` is forbidden as the type of a const generic parameter + --> $DIR/error_in_ty.rs:6:23 + | +LL | pub struct A<const z: [usize; x]> {} + | ^^^^^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error[E0308]: mismatched types + --> $DIR/error_in_ty.rs:10:8 + | +LL | impl A<2> { + | ^ expected `[usize; x]`, found integer + +error[E0308]: mismatched types + --> $DIR/error_in_ty.rs:16:8 + | +LL | impl A<2> { + | ^ expected `[usize; x]`, found integer + +error[E0592]: duplicate definitions with name `B` + --> $DIR/error_in_ty.rs:12:5 + | +LL | pub const fn B() {} + | ^^^^^^^^^^^^^^^^ duplicate definitions for `B` +... +LL | pub const fn B() {} + | ---------------- other definition for `B` + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0308, E0425, E0592. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs index af17a37bf23..b662939c27e 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -9,9 +9,10 @@ pub trait Trait { fn assoc_fn() -> Self::AssocTy; } -impl<const U: u8> Trait for Const<U> // OK, trait impl predicates +impl<const U: u8> Trait for Const<U> where - Const<{ my_const_fn(U) }>: , + // OK, trait impl predicates + Const<{ my_const_fn(U) }>:, { type AssocTy = Const<{ my_const_fn(U) }>; //~^ ERROR private type diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr index df0d43bef87..98dac313be4 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -1,5 +1,5 @@ error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/eval-privacy.rs:16:5 + --> $DIR/eval-privacy.rs:17:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -8,7 +8,7 @@ LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/eval-privacy.rs:16:5 + --> $DIR/eval-privacy.rs:17:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type |
