Skip to content

Commit 78bb3a2

Browse files
committed
Impossible preds const arg test
1 parent 30f168e commit 78bb3a2

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#![feature(generic_const_items, min_generic_const_args)]
2+
#![expect(incomplete_features)]
3+
4+
// Tests behaviour of attempting to evaluate const arguments whose wellformedness
5+
// depends on impossible to satisfy predicates, that are satisfied from another
6+
// trivially false clause in the environment.
7+
//
8+
// Additionally tests how (or if) this behaviour differs depending on whether the
9+
// constants where trivially false where clause is global or not.
10+
11+
trait Unimplemented<'a> {}
12+
13+
trait Trait {
14+
const NON_GLOBAL<T>: usize
15+
where
16+
for<'a> T: Unimplemented<'a>;
17+
18+
const GLOBAL: usize
19+
where
20+
for<'a> (): Unimplemented<'a>;
21+
}
22+
23+
impl Trait for u8 {
24+
const NON_GLOBAL<T>: usize = 1
25+
where
26+
for<'a> T: Unimplemented<'a>;
27+
28+
const GLOBAL: usize = 1
29+
//~^ ERROR: evaluation of constant value failed
30+
where
31+
for<'a> (): Unimplemented<'a>;
32+
}
33+
34+
struct Foo<const N: usize>;
35+
36+
fn non_global()
37+
where
38+
for<'a> (): Unimplemented<'a>,
39+
{
40+
let _: Foo<1> = Foo::<{ <u8 as Trait>::NON_GLOBAL::<()> }>;
41+
}
42+
43+
fn global()
44+
where
45+
for<'a> (): Unimplemented<'a>,
46+
{
47+
let _: Foo<1> = Foo::<{ <u8 as Trait>::GLOBAL }>;
48+
}
49+
50+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/impossible_preds_on_anon_const.rs:28:5
3+
|
4+
LL | / const GLOBAL: usize = 1
5+
LL | |
6+
LL | | where
7+
LL | | for<'a> (): Unimplemented<'a>;
8+
| |______________________________________^ entering unreachable code
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)