Skip to content

Commit 2855b92

Browse files
committed
add tests
1 parent 073127a commit 2855b92

12 files changed

+205
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// run-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features, unused_braces)]
4+
5+
trait Bar<T> {}
6+
impl<T> Bar<T> for [u8; {7}] {}
7+
8+
struct Foo<const N: usize> {}
9+
impl<const N: usize> Foo<N>
10+
where
11+
[u8; N]: Bar<[(); N]>,
12+
{
13+
fn foo() {}
14+
}
15+
16+
fn main() {
17+
Foo::foo();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_generics)]
2+
#![allow(incomplete_features)]
3+
4+
trait Bar<T> {}
5+
impl<T> Bar<T> for [u8; T] {}
6+
//~^ ERROR expected value, found type parameter `T`
7+
8+
struct Foo<const N: usize> {}
9+
impl<const N: usize> Foo<N>
10+
where
11+
[u8; N]: Bar<[(); N]>,
12+
{
13+
fn foo() {}
14+
}
15+
16+
fn main() {
17+
Foo::foo();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0423]: expected value, found type parameter `T`
2+
--> $DIR/issue-69654.rs:5:25
3+
|
4+
LL | impl<T> Bar<T> for [u8; T] {}
5+
| ^ not a value
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0423`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// build-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
// This test does not use any "unevaluated" consts, so it should compile just fine.
6+
7+
fn bind<const N: usize>(value: [u8; N]) -> [u8; N] {
8+
todo!()
9+
}
10+
11+
fn sink(_: [u8; 5]) {}
12+
13+
fn main() {
14+
let mut arr = Default::default();
15+
arr = bind(arr);
16+
sink(arr);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
2+
3+
// It depends on how we normalize constants and how const equate works if this
4+
// compiles.
5+
//
6+
// Please ping @lcnr if the output if this test changes.
7+
8+
9+
fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
10+
//~^ ERROR constant expression depends on a generic parameter
11+
//~| ERROR constant expression depends on a generic parameter
12+
todo!()
13+
}
14+
15+
fn main() {
16+
let mut arr = Default::default();
17+
arr = bind::<2>(arr);
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/unify-fixpoint.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
9+
10+
error: constant expression depends on a generic parameter
11+
--> $DIR/unify-fixpoint.rs:9:32
12+
|
13+
LL | fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
14+
| ^^^^^^^^^^^
15+
|
16+
= note: this may fail depending on what value the parameter takes
17+
18+
error: constant expression depends on a generic parameter
19+
--> $DIR/unify-fixpoint.rs:9:48
20+
|
21+
LL | fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
22+
| ^^^^^^^^^^^
23+
|
24+
= note: this may fail depending on what value the parameter takes
25+
26+
error: aborting due to 2 previous errors; 1 warning emitted
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(const_generics)]
2+
#![allow(incomplete_features)]
3+
4+
// This test would try to unify `N` with `N + 1` which must fail the occurs check.
5+
6+
fn bind<const N: usize>(value: [u8; N]) -> [u8; N + 1] {
7+
//~^ ERROR constant expression depends on a generic parameter
8+
todo!()
9+
}
10+
11+
fn sink(_: [u8; 5]) {}
12+
13+
fn main() {
14+
let mut arr = Default::default();
15+
arr = bind(arr);
16+
sink(arr);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/unify-n-nplusone.rs:6:44
3+
|
4+
LL | fn bind<const N: usize>(value: [u8; N]) -> [u8; N + 1] {
5+
| ^^^^^^^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
trait Bar<const M: usize> {}
6+
impl<const N: usize> Bar<N> for A<{ 6 + 1 }> {}
7+
8+
struct A<const N: usize>
9+
where
10+
A<N>: Bar<N>;
11+
12+
fn main() {
13+
let _ = A;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// check-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
6+
//
7+
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
8+
// artificial inference cycle.
9+
struct Foo<const N: usize>;
10+
11+
trait Bind<T> {
12+
fn bind() -> (T, Self);
13+
}
14+
15+
// `N` has to be `ConstKind::Unevaluated`.
16+
impl<T> Bind<T> for Foo<{ 6 + 1 }> {
17+
fn bind() -> (T, Self) {
18+
(panic!(), Foo)
19+
}
20+
}
21+
22+
fn main() {
23+
let (mut t, foo) = Foo::bind();
24+
// `t` is `ty::Infer(TyVar(_#1t))`
25+
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
26+
t = foo;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
6+
//
7+
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
8+
// artificial inference cycle.
9+
fn bind<T>() -> (T, [u8; 6 + 1]) {
10+
todo!()
11+
}
12+
13+
fn main() {
14+
let (mut t, foo) = bind();
15+
// `t` is `ty::Infer(TyVar(_#1t))`
16+
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
17+
t = foo;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// build-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
6+
todo!()
7+
}
8+
9+
fn main() {
10+
let mut arr = Default::default();
11+
arr = bind(arr);
12+
}

0 commit comments

Comments
 (0)