Skip to content

Commit 93e48fd

Browse files
committed
Bless (and add) some tests
1 parent ae7539a commit 93e48fd

36 files changed

+509
-186
lines changed

tests/crashes/127643.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/crashes/131046.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/crashes/131406.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/crashes/133066.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/crashes/133199.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(associated_const_equality)]
2+
3+
trait Owner<K> {
4+
const C: K;
5+
}
6+
impl<K: ConstDefault> Owner<K> for () {
7+
const C: K = K::DEFAULT;
8+
}
9+
10+
trait ConstDefault {
11+
const DEFAULT: Self;
12+
}
13+
14+
fn user() -> impl Owner<dyn Sized, C = 0> {}
15+
//~^ ERROR: the trait bound `(dyn Sized + 'static): ConstDefault` is not satisfied
16+
//~| ERROR: the size for values of type `(dyn Sized + 'static)` cannot be known at compilation time
17+
//~| ERROR: the trait `Sized` is not dyn compatible
18+
//~| ERROR: mismatched types
19+
20+
fn main() {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error[E0277]: the trait bound `(dyn Sized + 'static): ConstDefault` is not satisfied
2+
--> $DIR/wf_before_evaluate-2.rs:14:14
3+
|
4+
LL | fn user() -> impl Owner<dyn Sized, C = 0> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ConstDefault` is not implemented for `(dyn Sized + 'static)`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/wf_before_evaluate-2.rs:10:1
9+
|
10+
LL | trait ConstDefault {
11+
| ^^^^^^^^^^^^^^^^^^
12+
note: required for `()` to implement `Owner<(dyn Sized + 'static)>`
13+
--> $DIR/wf_before_evaluate-2.rs:6:23
14+
|
15+
LL | impl<K: ConstDefault> Owner<K> for () {
16+
| ------------ ^^^^^^^^ ^^
17+
| |
18+
| unsatisfied trait bound introduced here
19+
20+
error[E0277]: the size for values of type `(dyn Sized + 'static)` cannot be known at compilation time
21+
--> $DIR/wf_before_evaluate-2.rs:14:14
22+
|
23+
LL | fn user() -> impl Owner<dyn Sized, C = 0> {}
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
25+
|
26+
= help: the trait `Sized` is not implemented for `(dyn Sized + 'static)`
27+
= help: the trait `Owner<K>` is implemented for `()`
28+
note: required for `()` to implement `Owner<(dyn Sized + 'static)>`
29+
--> $DIR/wf_before_evaluate-2.rs:6:23
30+
|
31+
LL | impl<K: ConstDefault> Owner<K> for () {
32+
| - ^^^^^^^^ ^^
33+
| |
34+
| unsatisfied trait bound introduced here
35+
36+
error[E0038]: the trait `Sized` is not dyn compatible
37+
--> $DIR/wf_before_evaluate-2.rs:14:40
38+
|
39+
LL | fn user() -> impl Owner<dyn Sized, C = 0> {}
40+
| ^ `Sized` is not dyn compatible
41+
|
42+
= note: the trait is not dyn compatible because it requires `Self: Sized`
43+
= note: for a trait to be dyn compatible it needs to allow building a vtable
44+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
45+
46+
error[E0308]: mismatched types
47+
--> $DIR/wf_before_evaluate-2.rs:14:40
48+
|
49+
LL | fn user() -> impl Owner<dyn Sized, C = 0> {}
50+
| ^ expected `dyn Sized`, found integer
51+
|
52+
= note: expected trait object `(dyn Sized + 'static)`
53+
found type `{integer}`
54+
55+
error: aborting due to 4 previous errors
56+
57+
Some errors have detailed explanations: E0038, E0277, E0308.
58+
For more information about an error, try `rustc --explain E0038`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(associated_const_equality, generic_const_items)]
2+
#![expect(incomplete_features)]
3+
4+
// When we type check `main` we wind up having to prove `<() as Trait>::C<128_u64> = 128_u64`
5+
// doing this requires normalizing `<() as Trait>::C<128_u64>`. Previously we did not check
6+
// that consts are well formed before evaluating them (rust-lang/project-const-generics#37) so
7+
// in attempting to get the normalized form of `<() as Trait>::C<128_u64>` we would invoke the
8+
// ctfe machinery on a not-wf type system constant.
9+
10+
trait Trait {
11+
const C<const N: u32>: u32;
12+
}
13+
14+
impl Trait for () {
15+
const C<const N: u32>: u32 = N;
16+
}
17+
18+
fn ice<const N: u64, T: Trait<C<N> = { N }>>(_: T) {}
19+
//~^ ERROR: the constant `N` is not of type `u32`
20+
21+
fn main() {
22+
ice::<128, _>(());
23+
//~^ ERROR: type mismatch resolving `<() as Trait>::C<128> == 128`
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: the constant `N` is not of type `u32`
2+
--> $DIR/wf_before_evaluate.rs:18:31
3+
|
4+
LL | fn ice<const N: u64, T: Trait<C<N> = { N }>>(_: T) {}
5+
| ^^^^^^^^^^^^ expected `u32`, found `u64`
6+
|
7+
note: required by a const generic parameter in `Trait::C`
8+
--> $DIR/wf_before_evaluate.rs:11:13
9+
|
10+
LL | const C<const N: u32>: u32;
11+
| ^^^^^^^^^^^^ required by this const generic parameter in `Trait::C`
12+
13+
error[E0271]: type mismatch resolving `<() as Trait>::C<128> == 128`
14+
--> $DIR/wf_before_evaluate.rs:22:19
15+
|
16+
LL | ice::<128, _>(());
17+
| ------------- ^^ expected `128`, found `<() as Trait>::C::<128>`
18+
| |
19+
| required by a bound introduced by this call
20+
|
21+
= note: expected constant `128`
22+
found constant `<() as Trait>::C::<128>`
23+
note: required by a bound in `ice`
24+
--> $DIR/wf_before_evaluate.rs:18:31
25+
|
26+
LL | fn ice<const N: u64, T: Trait<C<N> = { N }>>(_: T) {}
27+
| ^^^^^^^^^^^^ required by this bound in `ice`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0271`.

tests/ui/const-generics/backcompat/impossible_preds_repeat_expr_hack.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ where
2323
for<'a> (): Unimplemented<'a>,
2424
{
2525
let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
26+
//~^ WARN: cannot use constants which depend on trivially-false where clauses
27+
//~| WARN: this was previously accepted by the compiler
28+
//~^^^ ERROR: mismatched types
2629
}
2730

2831
struct Foo<const N: usize>;

0 commit comments

Comments
 (0)