support const_evaluatable_checked across crate boundaries

This commit is contained in:
Bastian Kauschke 2020-09-11 21:16:16 +02:00
parent 82ebbd7d6b
commit 30ff1ef3d0
14 changed files with 157 additions and 2 deletions

View file

@ -0,0 +1,9 @@
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1]
where
[u8; std::mem::size_of::<T>() - 1]: Sized,
{
[0; std::mem::size_of::<T>() - 1]
}

View file

@ -0,0 +1,15 @@
// aux-build:const_evaluatable_lib.rs
// run-pass
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
extern crate const_evaluatable_lib;
fn user<T>() where [u8; std::mem::size_of::<T>() - 1]: Sized {
assert_eq!(const_evaluatable_lib::test1::<T>(), [0; std::mem::size_of::<T>() - 1]);
}
fn main() {
assert_eq!(const_evaluatable_lib::test1::<u32>(), [0; 3]);
user::<u32>();
user::<u64>();
}

View file

@ -0,0 +1,13 @@
// aux-build:const_evaluatable_lib.rs
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
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
}
fn main() {}

View file

@ -0,0 +1,36 @@
error: constant expression depends on a generic parameter
--> $DIR/cross_crate_predicate.rs:7:13
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:41
|
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
--> $DIR/cross_crate_predicate.rs:7:13
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:41
|
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
| ----- required by this bound in `test1::{{constant}}#1`
|
= note: this may fail depending on what value the parameter takes
error: constant expression depends on a generic parameter
--> $DIR/cross_crate_predicate.rs:7:13
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to 3 previous errors