diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-11-20 03:08:52 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-12-04 20:29:36 +0000 |
| commit | 87ddc1ea33edbe1be119d73e57c2783940e797fe (patch) | |
| tree | 1078cb612921aa307c2700910e38c4441beccbd8 /tests | |
| parent | c0f00086f85ae1fff34dd2daf6a11850e5bfc2f0 (diff) | |
| download | rust-87ddc1ea33edbe1be119d73e57c2783940e797fe.tar.gz rust-87ddc1ea33edbe1be119d73e57c2783940e797fe.zip | |
Point at generic param through which a const is used in a pattern
```
error[E0158]: constant pattern depends on a generic parameter, which is not allowed
--> $DIR/associated-const-type-parameter-pattern.rs:20:9
|
LL | pub trait Foo {
| -------------
LL | const X: EFoo;
| ------------- constant defined here
...
LL | pub fn test<A: Foo, B: Foo>(arg: EFoo) {
| - constant depends on this generic param
LL | match arg {
LL | A::X => println!("A::X"),
| ^^^^ `const` depends on a generic parameter
```
Diffstat (limited to 'tests')
4 files changed, 35 insertions, 18 deletions
diff --git a/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr b/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr index 5aef0fa414b..455831e8401 100644 --- a/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr +++ b/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr @@ -1,4 +1,4 @@ -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/associated-const-type-parameter-pattern.rs:20:9 | LL | pub trait Foo { @@ -6,10 +6,13 @@ LL | pub trait Foo { LL | const X: EFoo; | ------------- constant defined here ... +LL | pub fn test<A: Foo, B: Foo>(arg: EFoo) { + | - constant depends on this generic param +LL | match arg { LL | A::X => println!("A::X"), - | ^^^^ + | ^^^^ `const` depends on a generic parameter -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/associated-const-type-parameter-pattern.rs:22:9 | LL | pub trait Foo { @@ -17,10 +20,13 @@ LL | pub trait Foo { LL | const X: EFoo; | ------------- constant defined here ... +LL | pub fn test<A: Foo, B: Foo>(arg: EFoo) { + | - constant depends on this generic param +... LL | B::X => println!("B::X"), - | ^^^^ + | ^^^^ `const` depends on a generic parameter -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/associated-const-type-parameter-pattern.rs:30:9 | LL | pub trait Foo { @@ -28,10 +34,13 @@ LL | pub trait Foo { LL | const X: EFoo; | ------------- constant defined here ... +LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) { + | - constant depends on this generic param +LL | LL | let A::X = arg; - | ^^^^ + | ^^^^ `const` depends on a generic parameter -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/associated-const-type-parameter-pattern.rs:28:48 | LL | pub trait Foo { @@ -40,7 +49,9 @@ LL | const X: EFoo; | ------------- constant defined here ... LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) { - | ^^^^ + | - ^^^^ `const` depends on a generic parameter + | | + | constant depends on this generic param error: aborting due to 4 previous errors diff --git a/tests/ui/consts/issue-73976-polymorphic.stderr b/tests/ui/consts/issue-73976-polymorphic.stderr index 79a03d4ec32..2f50e6ac2fd 100644 --- a/tests/ui/consts/issue-73976-polymorphic.stderr +++ b/tests/ui/consts/issue-73976-polymorphic.stderr @@ -1,4 +1,4 @@ -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/issue-73976-polymorphic.rs:20:37 | LL | impl<T: 'static> GetTypeId<T> { @@ -6,10 +6,12 @@ LL | impl<T: 'static> GetTypeId<T> { LL | pub const VALUE: TypeId = TypeId::of::<T>(); | ----------------------- constant defined here ... +LL | const fn check_type_id<T: 'static>() -> bool { + | - constant depends on this generic param LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE) - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ `const` depends on a generic parameter -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/issue-73976-polymorphic.rs:31:42 | LL | impl<T: 'static> GetTypeNameLen<T> { @@ -17,8 +19,10 @@ LL | impl<T: 'static> GetTypeNameLen<T> { LL | pub const VALUE: usize = any::type_name::<T>().len(); | ---------------------- constant defined here ... +LL | const fn check_type_name_len<T: 'static>() -> bool { + | - constant depends on this generic param LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `const` depends on a generic parameter error: aborting due to 2 previous errors diff --git a/tests/ui/consts/issue-79137-toogeneric.stderr b/tests/ui/consts/issue-79137-toogeneric.stderr index 9b53a259547..d36f3ecbb76 100644 --- a/tests/ui/consts/issue-79137-toogeneric.stderr +++ b/tests/ui/consts/issue-79137-toogeneric.stderr @@ -1,4 +1,4 @@ -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/issue-79137-toogeneric.rs:12:43 | LL | impl<T> GetVariantCount<T> { @@ -6,8 +6,10 @@ LL | impl<T> GetVariantCount<T> { LL | pub const VALUE: usize = std::mem::variant_count::<T>(); | ---------------------- constant defined here ... +LL | const fn check_variant_count<T>() -> bool { + | - constant depends on this generic param LL | matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `const` depends on a generic parameter error: aborting due to 1 previous error diff --git a/tests/ui/inline-const/const-match-pat-generic.stderr b/tests/ui/inline-const/const-match-pat-generic.stderr index 26f72b34eca..cf48161b5e3 100644 --- a/tests/ui/inline-const/const-match-pat-generic.stderr +++ b/tests/ui/inline-const/const-match-pat-generic.stderr @@ -1,14 +1,14 @@ -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/const-match-pat-generic.rs:7:9 | LL | const { V } => {}, - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ `const` depends on a generic parameter -error[E0158]: constant pattern depends on a generic parameter +error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/const-match-pat-generic.rs:19:9 | LL | const { f(V) } => {}, - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ `const` depends on a generic parameter error: aborting due to 2 previous errors |
