Skip to content

Commit 22404d9

Browse files
committed
Fix tests
1 parent ed9f230 commit 22404d9

20 files changed

+356
-104
lines changed

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,24 @@
1+
#![feature(generic_arg_infer, associated_const_equality, generic_const_items)]
2+
#![expect(incomplete_features)]
3+
4+
// Regression test for #133066 where we would try to evaluate `<() as Foo>::ASSOC<_>` even
5+
// though it contained inference variables, which would cause ICEs.
6+
7+
trait Foo {
8+
const ASSOC<const N: u32>: u32;
9+
}
10+
11+
impl Foo for () {
12+
const ASSOC<const N: u32>: u32 = N;
13+
}
14+
15+
fn bar<const N: u32, T: Foo<ASSOC<N> = 10>>() {}
16+
17+
fn main() {
18+
bar::<_, ()>();
19+
//~^ ERROR: type mismatch resolving `<() as Foo>::ASSOC<_> == 10`
20+
21+
// FIXME(mgca):
22+
// FIXME(associated_const_equality):
23+
// This ought to start compiling once const items are aliases rather than bodies
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0271]: type mismatch resolving `<() as Foo>::ASSOC<_> == 10`
2+
--> $DIR/equality_bound_with_infer.rs:18:14
3+
|
4+
LL | bar::<_, ()>();
5+
| ^^ expected `10`, found `<() as Foo>::ASSOC::<_>`
6+
|
7+
= note: expected constant `10`
8+
found constant `<() as Foo>::ASSOC::<_>`
9+
note: required by a bound in `bar`
10+
--> $DIR/equality_bound_with_infer.rs:15:29
11+
|
12+
LL | fn bar<const N: u32, T: Foo<ASSOC<N> = 10>>() {}
13+
| ^^^^^^^^^^^^^ required by this bound in `bar`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0271`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
//~^ ERROR associated const equality is incomplete
17+
//~| ERROR the type parameter `U` is not constrained by the impl trait
18+
19+
fn foo()
20+
where
21+
(): Trait,
22+
//~^ ERROR type mismatch resolving
23+
{
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0658]: associated const equality is incomplete
2+
--> $DIR/unconstrained_impl_param.rs:15:45
3+
|
4+
LL | impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
8+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
12+
--> $DIR/unconstrained_impl_param.rs:15:6
13+
|
14+
LL | impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
15+
| ^ unconstrained type parameter
16+
17+
error[E0271]: type mismatch resolving `<(_,) as AssocConst>::A == 0`
18+
--> $DIR/unconstrained_impl_param.rs:21:5
19+
|
20+
LL | (): Trait,
21+
| ^^^^^^^^^ expected `0`, found `<(_,) as AssocConst>::A`
22+
|
23+
= note: expected constant `0`
24+
found constant `<(_,) as AssocConst>::A`
25+
note: required for `()` to implement `Trait`
26+
--> $DIR/unconstrained_impl_param.rs:15:9
27+
|
28+
LL | impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
29+
| ^^^^^ ^^ --------- unsatisfied trait bound introduced here
30+
= help: see issue #48214
31+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
32+
|
33+
LL + #![feature(trivial_bounds)]
34+
|
35+
36+
error: aborting due to 3 previous errors
37+
38+
Some errors have detailed explanations: E0207, E0271, E0658.
39+
For more information about an error, try `rustc --explain E0207`.

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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: overly complex generic constant
2-
--> $DIR/dependence_lint.rs:21:17
2+
--> $DIR/dependence_lint.rs:22:17
33
|
44
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants
66
|
77
= help: consider moving this anonymous constant into a `const` function
88

99
error: unconstrained generic constant
10-
--> $DIR/dependence_lint.rs:14:12
10+
--> $DIR/dependence_lint.rs:15:12
1111
|
1212
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,13 +28,24 @@ help: try adding a `where` bound
2828
LL | fn foo<T>() where [(); size_of::<*mut T>()]: {
2929
| ++++++++++++++++++++++++++++++++
3030

31+
error: unconstrained generic constant
32+
--> $DIR/dependence_lint.rs:10:5
33+
|
34+
LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs`
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
help: try adding a `where` bound
38+
|
39+
LL | fn foo<T>() where [(); size_of::<*mut T>()]: {
40+
| ++++++++++++++++++++++++++++++++
41+
3142
error: overly complex generic constant
32-
--> $DIR/dependence_lint.rs:17:9
43+
--> $DIR/dependence_lint.rs:18:9
3344
|
3445
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce
3546
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants
3647
|
3748
= help: consider moving this anonymous constant into a `const` function
3849

39-
error: aborting due to 4 previous errors
50+
error: aborting due to 5 previous errors
4051

tests/ui/const-generics/generic_const_exprs/dependence_lint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use std::mem::size_of;
99
fn foo<T>() {
1010
[0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs`
1111
//[gce]~^ ERROR unconstrained
12-
//[full]~^^ WARNING cannot use constants
12+
//[gce]~| ERROR unconstrained generic constant
13+
//[full]~^^^ WARNING cannot use constants
1314
//[full]~| WARNING this was previously accepted
1415
let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
1516
//[full]~^ ERROR generic parameters may not be used

tests/ui/const-generics/generic_const_exprs/different-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error[E0308]: mismatched types
22
--> $DIR/different-fn.rs:10:5
33
|
44
LL | [0; size_of::<Foo<T>>()]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `size_of::<T>()`, found `0`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `size_of::<T>()`, found `size_of::<Foo<T>>()`
66
|
77
= note: expected constant `size_of::<T>()`
8-
found constant `0`
8+
found constant `size_of::<Foo<T>>()`
99

1010
error: unconstrained generic constant
1111
--> $DIR/different-fn.rs:10:9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ check-pass
2+
3+
// regression test for #136894.
4+
// I (BoxyUwU) don't know what the underlying cause was here
5+
6+
#![feature(generic_const_exprs)]
7+
#![crate_type = "lib"]
8+
#![allow(incomplete_features, dead_code)]
9+
10+
struct X<T>([(); f::<T>()])
11+
where
12+
[(); f::<T>()]:;
13+
14+
const fn f<T>() -> usize {
15+
panic!()
16+
}

tests/ui/const-generics/issues/issue-71202.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ impl<T: Copy> DataHolder<T> {
2525
}
2626

2727
<IsCopy<T>>::VALUE
28-
} as usize] = []; //~ ERROR unconstrained generic constant
28+
} as usize] = [];
29+
//~^ ERROR unconstrained generic constant
30+
//~^^ ERROR mismatched types
2931
}
3032

3133
fn main() {}

tests/ui/const-generics/issues/issue-71202.stderr

+45-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,49 @@ LL + <IsCopy<T>>::VALUE
5959
LL ~ } as usize]: = [];
6060
|
6161

62-
error: aborting due to 2 previous errors
62+
error[E0308]: mismatched types
63+
--> $DIR/issue-71202.rs:28:19
64+
|
65+
LL | } as usize] = [];
66+
| ^^ expected `1 - {
67+
trait NotCopy {
68+
const VALUE: bool = false;
69+
}
70+
71+
impl<__Type: ?Sized> NotCopy for __Type {}
72+
73+
struct IsCopy<__Type: ?Sized>(PhantomData<__Type>);
74+
75+
impl<__Type> IsCopy<__Type>
76+
where
77+
__Type: Sized + Copy,
78+
{
79+
const VALUE: bool = true;
80+
}
81+
82+
<IsCopy<T>>::VALUE
83+
} as usize`, found `0`
84+
|
85+
= note: expected constant `1 - {
86+
trait NotCopy {
87+
const VALUE: bool = false;
88+
}
89+
90+
impl<__Type: ?Sized> NotCopy for __Type {}
91+
92+
struct IsCopy<__Type: ?Sized>(PhantomData<__Type>);
93+
94+
impl<__Type> IsCopy<__Type>
95+
where
96+
__Type: Sized + Copy,
97+
{
98+
const VALUE: bool = true;
99+
}
100+
101+
<IsCopy<T>>::VALUE
102+
} as usize`
103+
found constant `0`
104+
105+
error: aborting due to 3 previous errors
63106

107+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)