make ConstEvaluatable more strict

This commit is contained in:
Bastian Kauschke 2020-08-06 10:00:08 +02:00
parent 7bc0bf7254
commit c81935e6df
11 changed files with 133 additions and 26 deletions

View file

@ -0,0 +1,11 @@
// check-pass
struct Foo<T>(T);
impl<T> Foo<T> {
const VALUE: usize = std::mem::size_of::<T>();
}
fn test<T>() {
let _ = [0; Foo::<u8>::VALUE];
}
fn main() {}

View file

@ -1,5 +1,3 @@
// run-pass
#![feature(arbitrary_enum_discriminant, core_intrinsics)]
extern crate core;
@ -9,6 +7,7 @@ use core::intrinsics::discriminant_value;
enum MyWeirdOption<T> {
None = 0,
Some(T) = core::mem::size_of::<*mut T>(),
//~^ ERROR constant expression depends on a generic parameter
}
fn main() {

View file

@ -0,0 +1,10 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-70453-polymorphic-ctfe.rs:9:15
|
LL | Some(T) = core::mem::size_of::<*mut T>(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to previous error

View file

@ -5,8 +5,7 @@
use std::marker::PhantomData;
pub struct S<'a>
{
pub struct S<'a> {
pub m1: PhantomData<&'a u8>,
pub m2: [u8; S::size()],
}

View file

@ -1,4 +1,3 @@
// check-pass
#![feature(lazy_normalization_consts)]
#![allow(incomplete_features)]
@ -10,5 +9,6 @@ impl<T: ?Sized> L<T> {
}
impl<T> X<T, [u8; L::<T>::S]> {}
//~^ ERROR constant expression depends on a generic parameter
fn main() {}

View file

@ -0,0 +1,10 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-73980.rs:11:9
|
LL | impl<T> X<T, [u8; L::<T>::S]> {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to previous error