Clean up
Simplify match statement Add multiple tests - 1 test for checking `N + 1 + 1` does not unify with `N+1` - 2 tests for checking that a function that uses two parameters only returns the parameter that is actually used. - Check exact repeat predicates
This commit is contained in:
parent
7c5cb73735
commit
21c5ffe008
8 changed files with 133 additions and 25 deletions
23
src/test/ui/const-generics/fn_with_two_const_inputs.rs
Normal file
23
src/test/ui/const-generics/fn_with_two_const_inputs.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
const fn both(_: usize, b: usize) -> usize {
|
||||
b
|
||||
}
|
||||
|
||||
fn foo<const N: usize, const M: usize>() -> [(); N + 2]
|
||||
where
|
||||
[(); both(N + 1, M + 1)]:,
|
||||
{
|
||||
bar()
|
||||
//~^ ERROR: unconstrained generic constant
|
||||
}
|
||||
|
||||
fn bar<const N: usize>() -> [(); N]
|
||||
where
|
||||
[(); N + 1]:,
|
||||
{
|
||||
[(); N]
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
18
src/test/ui/const-generics/fn_with_two_const_inputs.stderr
Normal file
18
src/test/ui/const-generics/fn_with_two_const_inputs.stderr
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
error: unconstrained generic constant
|
||||
--> $DIR/fn_with_two_const_inputs.rs:12:5
|
||||
|
|
||||
LL | bar()
|
||||
| ^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); N + 1]:`
|
||||
note: required by a bound in `bar`
|
||||
--> $DIR/fn_with_two_const_inputs.rs:18:10
|
||||
|
|
||||
LL | fn bar<const N: usize>() -> [(); N]
|
||||
| --- required by a bound in this
|
||||
LL | where
|
||||
LL | [(); N + 1]:,
|
||||
| ^^^^^ required by this bound in `bar`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
22
src/test/ui/const-generics/fn_with_two_same_const_inputs.rs
Normal file
22
src/test/ui/const-generics/fn_with_two_same_const_inputs.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// check-pass
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
const fn both(_: usize, b: usize) -> usize {
|
||||
b
|
||||
}
|
||||
|
||||
fn foo<const N: usize>()
|
||||
where
|
||||
[(); both(N + 1, N + 1)]:,
|
||||
{
|
||||
bar::<N>();
|
||||
}
|
||||
|
||||
fn bar<const N: usize>()
|
||||
where
|
||||
[(); N + 1]:,
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -15,8 +15,8 @@ where
|
|||
[(); (L - 1) + 1 + L]:,
|
||||
{
|
||||
foo::<_, L>([(); L + 1 + L]);
|
||||
//~^ ERROR: unconstrained generic constant
|
||||
//~| ERROR: mismatched types
|
||||
//~^ ERROR: mismatched types
|
||||
//~^^ ERROR: unconstrained generic constant
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
19
src/test/ui/const-generics/two_matching_preds.rs
Normal file
19
src/test/ui/const-generics/two_matching_preds.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// check-pass
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
fn foo<const N: usize>()
|
||||
where
|
||||
[(); N + 1]:,
|
||||
[(); N + 1]:,
|
||||
{
|
||||
bar::<N>();
|
||||
}
|
||||
|
||||
fn bar<const N: usize>()
|
||||
where
|
||||
[(); N + 1]:,
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
18
src/test/ui/const-generics/unify_with_nested_expr.rs
Normal file
18
src/test/ui/const-generics/unify_with_nested_expr.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
fn foo<const N: usize>()
|
||||
where
|
||||
[(); N + 1 + 1]:,
|
||||
{
|
||||
bar();
|
||||
//~^ ERROR: type annotations
|
||||
}
|
||||
|
||||
fn bar<const N: usize>()
|
||||
where
|
||||
[(); N + 1]:,
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
22
src/test/ui/const-generics/unify_with_nested_expr.stderr
Normal file
22
src/test/ui/const-generics/unify_with_nested_expr.stderr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
error[E0284]: type annotations needed
|
||||
--> $DIR/unify_with_nested_expr.rs:8:5
|
||||
|
|
||||
LL | bar();
|
||||
| ^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
||||
|
|
||||
note: required by a bound in `bar`
|
||||
--> $DIR/unify_with_nested_expr.rs:14:10
|
||||
|
|
||||
LL | fn bar<const N: usize>()
|
||||
| --- required by a bound in this
|
||||
LL | where
|
||||
LL | [(); N + 1]:,
|
||||
| ^^^^^ required by this bound in `bar`
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | bar::<N>();
|
||||
| +++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0284`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue