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