Rollup merge of #81433 - lcnr:stop-looking-into-ty-alias, r=oli-obk

const_evaluatable: stop looking into type aliases

see https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias

r? ````@oli-obk````
This commit is contained in:
Yuki Okushi 2021-01-28 15:09:20 +09:00 committed by GitHub
commit d98fcbd561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 38 deletions

View file

@ -1,9 +1,15 @@
error[E0080]: evaluation of constant value failed
--> $DIR/simple_fail.rs:9:48
|
LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error[E0080]: evaluation of constant value failed
--> $DIR/simple_fail.rs:6:33
|
LL | type Arr<const N: usize> = [u8; N - 1];
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -7,5 +7,14 @@ LL | type Arr<const N: usize> = [u8; N - 1];
= help: const parameters may only be used as standalone arguments, i.e. `N`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
error: aborting due to previous error
error: generic parameters may not be used in const operations
--> $DIR/simple_fail.rs:9:48
|
LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
error: aborting due to 2 previous errors

View file

@ -1,12 +1,14 @@
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![feature(const_evaluatable_checked)]
#![cfg_attr(full, feature(const_evaluatable_checked))]
#![allow(incomplete_features)]
type Arr<const N: usize> = [u8; N - 1]; //[full]~ ERROR evaluation of constant
//[min]~^ ERROR generic parameters may not be used in const operations
fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized {
fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ ERROR evaluation of constant
todo!()
}

View file

@ -0,0 +1,14 @@
// check-pass
// Test that we correctly substitute generic arguments for type aliases.
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
type Alias<T, const N: usize> = [T; N + 1];
fn foo<const M: usize>() -> Alias<u32, M> where [u8; M + 1]: Sized {
[0; M + 1]
}
fn main() {
foo::<0>();
}