const_eval_checked: deal with unused nodes + div

This commit is contained in:
Bastian Kauschke 2020-10-23 12:13:44 +02:00
parent a9cd294cf2
commit 6ad140ca19
4 changed files with 113 additions and 12 deletions

View file

@ -0,0 +1,11 @@
// run-pass
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
fn with_bound<const N: usize>() where [u8; N / 2]: Sized {
let _: [u8; N / 2] = [0; N / 2];
}
fn main() {
with_bound::<4>();
}

View file

@ -0,0 +1,25 @@
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
fn add<const N: usize>() -> [u8; { N + 1; 5 }] {
//~^ ERROR overly complex generic constant
todo!()
}
fn div<const N: usize>() -> [u8; { N / 1; 5 }] {
//~^ ERROR overly complex generic constant
todo!()
}
const fn foo(n: usize) {}
fn fn_call<const N: usize>() -> [u8; { foo(N); 5 }] {
//~^ ERROR overly complex generic constant
todo!()
}
fn main() {
add::<12>();
div::<9>();
fn_call::<14>();
}

View file

@ -0,0 +1,26 @@
error: overly complex generic constant
--> $DIR/unused_expr.rs:4:34
|
LL | fn add<const N: usize>() -> [u8; { N + 1; 5 }] {
| ^^^^^^^^^^^^ unused node
|
= help: consider moving this anonymous constant into a `const` function
error: overly complex generic constant
--> $DIR/unused_expr.rs:9:34
|
LL | fn div<const N: usize>() -> [u8; { N / 1; 5 }] {
| ^^^^^^^^^^^^ unused node
|
= help: consider moving this anonymous constant into a `const` function
error: overly complex generic constant
--> $DIR/unused_expr.rs:16:38
|
LL | fn fn_call<const N: usize>() -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^ unused node
|
= help: consider moving this anonymous constant into a `const` function
error: aborting due to 3 previous errors