Skip to content

Commit 337dd71

Browse files
committed
Bless (and add) some tests
1 parent ae7539a commit 337dd71

40 files changed

+544
-212
lines changed

tests/crashes/127643.rs

-18
This file was deleted.

tests/crashes/131046.rs

-15
This file was deleted.

tests/crashes/131406.rs

-12
This file was deleted.

tests/crashes/133066.rs

-12
This file was deleted.

tests/crashes/133199.rs

-11
This file was deleted.

tests/crashes/136894.rs

-8
This file was deleted.

tests/crashes/137813.rs

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// regression test for #137813 where we would assume all constants in the type system
2+
// cannot contain inference variables, even though associated const equality syntax
3+
// was still lowered without the feature gate enabled.
4+
5+
trait AssocConst {
6+
const A: u8;
7+
}
8+
9+
impl<T> AssocConst for (T,) {
10+
const A: u8 = 0;
11+
}
12+
13+
trait Trait {}
14+
15+
impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
16+
17+
fn foo()
18+
where
19+
(): Trait,
20+
{
21+
}
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() {}
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`.
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+
}
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

+3
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>;

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

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
warning: cannot use constants which depend on trivially-false where clauses
2+
--> $DIR/impossible_preds_repeat_expr_hack.rs:25:28
3+
|
4+
LL | let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
9+
= note: `#[warn(const_evaluatable_unchecked)]` on by default
10+
11+
error[E0308]: mismatched types
12+
--> $DIR/impossible_preds_repeat_expr_hack.rs:25:23
13+
|
14+
LL | let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
15+
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an array with a size of 1, found one with a size of <u8 as Trait<()>>::ASSOC
16+
| |
17+
| expected due to this
18+
119
error[E0277]: the trait bound `for<'a> (): Unimplemented<'a>` is not satisfied
2-
--> $DIR/impossible_preds_repeat_expr_hack.rs:34:43
20+
--> $DIR/impossible_preds_repeat_expr_hack.rs:37:43
321
|
422
LL | let _a: Foo<1> = Foo::<{ <u8 as Trait<()>>::ASSOC }>;
523
| ^^ the trait `for<'a> Unimplemented<'a>` is not implemented for `()`
@@ -19,7 +37,7 @@ LL | const ASSOC: usize;
1937
| ----- required by a bound in this associated constant
2038

2139
error[E0277]: the trait bound `for<'a> (): Unimplemented<'a>` is not satisfied
22-
--> $DIR/impossible_preds_repeat_expr_hack.rs:34:31
40+
--> $DIR/impossible_preds_repeat_expr_hack.rs:37:31
2341
|
2442
LL | let _a: Foo<1> = Foo::<{ <u8 as Trait<()>>::ASSOC }>;
2543
| ^^ the trait `for<'a> Unimplemented<'a>` is not implemented for `()`
@@ -38,6 +56,7 @@ LL | where
3856
LL | for<'a> T: Unimplemented<'a>,
3957
| ----------------- unsatisfied trait bound introduced here
4058

41-
error: aborting due to 2 previous errors
59+
error: aborting due to 3 previous errors; 1 warning emitted
4260

43-
For more information about this error, try `rustc --explain E0277`.
61+
Some errors have detailed explanations: E0277, E0308.
62+
For more information about an error, try `rustc --explain E0277`.

tests/crashes/auxiliary/aux133199.rs renamed to tests/ui/const-generics/generic_const_exprs/auxiliary/cross-crate-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![allow(incomplete_features)]
22
#![feature(generic_const_exprs)]
33

4-
pub struct FixedBitSet<const N: usize>;
4+
pub struct Foo<const N: usize>;
55

6-
impl<const N: usize> FixedBitSet<N>
6+
impl<const N: usize> Foo<N>
77
where
88
[u8; N.div_ceil(8)]: Sized,
99
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
//@ aux-build: cross-crate-2.rs
3+
4+
extern crate cross_crate_2;
5+
6+
use cross_crate_2::Foo;
7+
8+
fn main() {
9+
Foo::<7>::new();
10+
}

tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: generic parameters may not be used in const operations
2-
--> $DIR/dependence_lint.rs:14:32
2+
--> $DIR/dependence_lint.rs:15:32
33
|
44
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
55
| ^ cannot perform const operation using `T`
@@ -8,7 +8,7 @@ LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
88
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
99

1010
error: generic parameters may not be used in const operations
11-
--> $DIR/dependence_lint.rs:21:37
11+
--> $DIR/dependence_lint.rs:22:37
1212
|
1313
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce
1414
| ^ cannot perform const operation using `T`
@@ -27,7 +27,7 @@ LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_
2727
= note: `#[warn(const_evaluatable_unchecked)]` on by default
2828

2929
warning: cannot use constants which depend on generic parameters in types
30-
--> $DIR/dependence_lint.rs:17:9
30+
--> $DIR/dependence_lint.rs:18:9
3131
|
3232
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)