diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-09-28 19:44:23 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-09-28 20:18:06 +0200 |
| commit | a4783debe021c6d13ce3cf5167efe98c5baeaa26 (patch) | |
| tree | c4ff8aa3490e6a21b1354edc03d30ef171045e4e /src/test/ui/const-generics/const_evaluatable_checked | |
| parent | 535d27ac9a3d45dd92769f4d4c7b9f454d1077ea (diff) | |
| download | rust-a4783debe021c6d13ce3cf5167efe98c5baeaa26.tar.gz rust-a4783debe021c6d13ce3cf5167efe98c5baeaa26.zip | |
const evaluatable: improve `TooGeneric` handling
Diffstat (limited to 'src/test/ui/const-generics/const_evaluatable_checked')
3 files changed, 48 insertions, 28 deletions
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs b/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs index 52b89cfa045..e3a4d9a96aa 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs +++ b/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs @@ -5,10 +5,10 @@ extern crate const_evaluatable_lib; fn user<T>() { let _ = const_evaluatable_lib::test1::<T>(); - //~^ ERROR constant expression depends - //~| ERROR constant expression depends - //~| ERROR constant expression depends - //~| ERROR constant expression depends + //~^ ERROR unconstrained generic constant + //~| ERROR unconstrained generic constant + //~| ERROR unconstrained generic constant + //~| ERROR unconstrained generic constant } fn main() {} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr b/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr index 4af68118be3..8a298b47fff 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr +++ b/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr @@ -1,54 +1,50 @@ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/cross_crate_predicate.rs:7:13 | LL | let _ = const_evaluatable_lib::test1::<T>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - ::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | -LL | [u8; std::mem::size_of::<T>() - 1]: Sized, - | ---------------------------- required by this bound in `test1` +help: consider adding a `where` bound for this expression + --> $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | - = note: this may fail depending on what value the parameter takes +LL | [u8; std::mem::size_of::<T>() - 1]: Sized, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/cross_crate_predicate.rs:7:13 | LL | let _ = const_evaluatable_lib::test1::<T>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - ::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | -LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] - | ---------------------------- required by this bound in `test1` +help: consider adding a `where` bound for this expression + --> $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | - = note: this may fail depending on what value the parameter takes +LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/cross_crate_predicate.rs:7:13 | LL | let _ = const_evaluatable_lib::test1::<T>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - ::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | -LL | [u8; std::mem::size_of::<T>() - 1]: Sized, - | ---------------------------- required by this bound in `test1` +help: consider adding a `where` bound for this expression + --> $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | - = note: this may fail depending on what value the parameter takes +LL | [u8; std::mem::size_of::<T>() - 1]: Sized, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/cross_crate_predicate.rs:7:13 | LL | let _ = const_evaluatable_lib::test1::<T>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - ::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | -LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] - | ---------------------------- required by this bound in `test1` +help: consider adding a `where` bound for this expression + --> $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | - = note: this may fail depending on what value the parameter takes +LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs b/src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs new file mode 100644 index 00000000000..cad06ea4004 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs @@ -0,0 +1,24 @@ +// run-pass +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +use std::{mem, ptr}; + +fn split_first<T, const N: usize>(arr: [T; N]) -> (T, [T; N - 1]) +where + [T; N - 1]: Sized, +{ + let arr = mem::ManuallyDrop::new(arr); + unsafe { + let head = ptr::read(&arr[0]); + let tail = ptr::read(&arr[1..] as *const [T] as *const [T; N - 1]); + (head, tail) + } +} + +fn main() { + let arr = [0, 1, 2, 3, 4]; + let (head, tail) = split_first(arr); + assert_eq!(head, 0); + assert_eq!(tail, [1, 2, 3, 4]); +} |
