add tests
This commit is contained in:
parent
7530c43b79
commit
6000b4844a
9 changed files with 225 additions and 3 deletions
|
|
@ -1,4 +1,3 @@
|
|||
// run-pass
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
|
@ -22,8 +21,10 @@ where
|
|||
}
|
||||
|
||||
fn main() {
|
||||
// Test that we can correctly infer `T` which requires evaluating
|
||||
// `{ N + 1 }` which has substs containing an inference var
|
||||
// FIXME(generic_const_exprs): We can't correctly infer `T` which requires
|
||||
// evaluating `{ N + 1 }` which has substs containing an inference var
|
||||
let mut _q = Default::default();
|
||||
//~^ ERROR type annotations needed
|
||||
|
||||
_q = foo::<_, 2>(_q);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/const_eval_resolve_canonical.rs:26:9
|
||||
|
|
||||
LL | let mut _q = Default::default();
|
||||
| ^^^^^^ consider giving `_q` a type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
23
src/test/ui/const-generics/issues/issue-83249.rs
Normal file
23
src/test/ui/const-generics/issues/issue-83249.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
trait Foo {
|
||||
const N: usize;
|
||||
}
|
||||
|
||||
impl Foo for u8 {
|
||||
const N: usize = 1;
|
||||
}
|
||||
|
||||
fn foo<T: Foo>(_: [u8; T::N]) -> T {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn bar() {
|
||||
let _: u8 = foo([0; 1]);
|
||||
|
||||
let _ = foo([0; 1]);
|
||||
//~^ ERROR type annotations needed
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
22
src/test/ui/const-generics/issues/issue-83249.stderr
Normal file
22
src/test/ui/const-generics/issues/issue-83249.stderr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-83249.rs:19:13
|
||||
|
|
||||
LL | let _ = foo([0; 1]);
|
||||
| - ^^^ cannot infer type for type parameter `T` declared on the function `foo`
|
||||
| |
|
||||
| consider giving this pattern a type
|
||||
|
|
||||
= note: cannot satisfy `_: Foo`
|
||||
note: required by a bound in `foo`
|
||||
--> $DIR/issue-83249.rs:12:11
|
||||
|
|
||||
LL | fn foo<T: Foo>(_: [u8; T::N]) -> T {
|
||||
| ^^^ required by this bound in `foo`
|
||||
help: consider specifying the type argument in the function call
|
||||
|
|
||||
LL | let _ = foo::<T>([0; 1]);
|
||||
| +++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
69
src/test/ui/const-generics/issues/issue-83288.rs
Normal file
69
src/test/ui/const-generics/issues/issue-83288.rs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// build-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use std::{marker::PhantomData, ops::Mul};
|
||||
|
||||
pub enum Nil {}
|
||||
pub struct Cons<T, L> {
|
||||
_phantom: PhantomData<(T, L)>,
|
||||
}
|
||||
|
||||
pub trait Indices<const N: usize> {
|
||||
const RANK: usize;
|
||||
const NUM_ELEMS: usize;
|
||||
}
|
||||
|
||||
impl<const N: usize> Indices<N> for Nil {
|
||||
const RANK: usize = 0;
|
||||
const NUM_ELEMS: usize = 1;
|
||||
}
|
||||
|
||||
impl<T, I: Indices<N>, const N: usize> Indices<N> for Cons<T, I> {
|
||||
const RANK: usize = I::RANK + 1;
|
||||
const NUM_ELEMS: usize = I::NUM_ELEMS * N;
|
||||
}
|
||||
|
||||
pub trait Concat<J> {
|
||||
type Output;
|
||||
}
|
||||
|
||||
impl<J> Concat<J> for Nil {
|
||||
type Output = J;
|
||||
}
|
||||
|
||||
impl<T, I, J> Concat<J> for Cons<T, I>
|
||||
where
|
||||
I: Concat<J>,
|
||||
{
|
||||
type Output = Cons<T, <I as Concat<J>>::Output>;
|
||||
}
|
||||
|
||||
pub struct Tensor<I: Indices<N>, const N: usize>
|
||||
where
|
||||
[u8; I::NUM_ELEMS]: Sized,
|
||||
{
|
||||
pub data: [u8; I::NUM_ELEMS],
|
||||
_phantom: PhantomData<I>,
|
||||
}
|
||||
|
||||
impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul<Tensor<J, N>> for Tensor<I, N>
|
||||
where
|
||||
I: Concat<J>,
|
||||
<I as Concat<J>>::Output: Indices<N>,
|
||||
[u8; I::NUM_ELEMS]: Sized,
|
||||
[u8; J::NUM_ELEMS]: Sized,
|
||||
[u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
|
||||
{
|
||||
type Output = Tensor<<I as Concat<J>>::Output, N>;
|
||||
|
||||
fn mul(self, _rhs: Tensor<J, N>) -> Self::Output {
|
||||
Tensor {
|
||||
data: [0u8; <I as Concat<J>>::Output::NUM_ELEMS],
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
24
src/test/ui/const-generics/issues/issue-87470.rs
Normal file
24
src/test/ui/const-generics/issues/issue-87470.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// build-pass
|
||||
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
pub trait TraitWithConst {
|
||||
const SOME_CONST: usize;
|
||||
}
|
||||
|
||||
pub trait OtherTrait: TraitWithConst {
|
||||
fn some_fn(self) -> [u8 ; <Self as TraitWithConst>::SOME_CONST];
|
||||
}
|
||||
|
||||
impl TraitWithConst for f32 {
|
||||
const SOME_CONST: usize = 32;
|
||||
}
|
||||
|
||||
impl OtherTrait for f32 {
|
||||
fn some_fn(self) -> [u8 ; <Self as TraitWithConst>::SOME_CONST] {
|
||||
[0; 32]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
29
src/test/ui/const-generics/issues/issue-87964.rs
Normal file
29
src/test/ui/const-generics/issues/issue-87964.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// build-pass
|
||||
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
pub trait Target {
|
||||
const LENGTH: usize;
|
||||
}
|
||||
|
||||
|
||||
pub struct Container<T: Target>
|
||||
where
|
||||
[(); T::LENGTH]: Sized,
|
||||
{
|
||||
_target: T,
|
||||
}
|
||||
|
||||
impl<T: Target> Container<T>
|
||||
where
|
||||
[(); T::LENGTH]: Sized,
|
||||
{
|
||||
pub fn start(
|
||||
_target: T,
|
||||
) -> Container<T> {
|
||||
Container { _target }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
26
src/test/ui/const-generics/issues/issue-89146.rs
Normal file
26
src/test/ui/const-generics/issues/issue-89146.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// build-pass
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
pub trait Foo {
|
||||
const SIZE: usize;
|
||||
|
||||
fn to_bytes(&self) -> [u8; Self::SIZE];
|
||||
}
|
||||
|
||||
pub fn bar<G: Foo>(a: &G) -> u8
|
||||
where
|
||||
[(); G::SIZE]: Sized,
|
||||
{
|
||||
deeper_bar(a)
|
||||
}
|
||||
|
||||
fn deeper_bar<G: Foo>(a: &G) -> u8
|
||||
where
|
||||
[(); G::SIZE]: Sized,
|
||||
{
|
||||
a.to_bytes()[0]
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
19
src/test/ui/const-generics/issues/issue-89320.rs
Normal file
19
src/test/ui/const-generics/issues/issue-89320.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// build-pass
|
||||
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
pub trait Enumerable {
|
||||
const N: usize;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SymmetricGroup<S>
|
||||
where
|
||||
S: Enumerable,
|
||||
[(); S::N]: Sized,
|
||||
{
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue