const evaluatable: improve TooGeneric handling
This commit is contained in:
parent
535d27ac9a
commit
a4783debe0
8 changed files with 199 additions and 75 deletions
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
||||
help: consider adding a `where` bound for this expression
|
||||
--> $DIR/auxiliary/const_evaluatable_lib.rs:6:10
|
||||
|
|
||||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
|
||||
| ---------------------------- required by this bound in `test1`
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
|
|
||||
help: consider adding a `where` bound for this expression
|
||||
--> $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`
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
|
|
||||
help: consider adding a `where` bound for this expression
|
||||
--> $DIR/auxiliary/const_evaluatable_lib.rs:6:10
|
||||
|
|
||||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
|
||||
| ---------------------------- required by this bound in `test1`
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
|
|
||||
help: consider adding a `where` bound for this expression
|
||||
--> $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`
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
|
|
@ -14,5 +14,4 @@ fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
|
|||
fn main() {
|
||||
test::<2>();
|
||||
//~^ ERROR wrong number of type
|
||||
//~| ERROR constant expression depends
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,6 @@ error[E0107]: wrong number of type arguments: expected 1, found 0
|
|||
LL | test::<2>();
|
||||
| ^^^^^^^^^ expected 1 type argument
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-76595.rs:15:5
|
||||
|
|
||||
LL | fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
|
||||
| ------------------------------- required by this bound in `test`
|
||||
...
|
||||
LL | test::<2>();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue