Auto merge of #52712 - oli-obk:const_eval_cleanups, r=RalfJung

Reintroduce `Undef` and properly check constant value sizes

r? @RalfJung

cc @eddyb

basically all kinds of silent failures that never occurred are assertions now
This commit is contained in:
bors 2018-08-03 14:28:12 +00:00
commit 59fa6bd6c1
28 changed files with 628 additions and 618 deletions

View file

@ -16,7 +16,7 @@ union Foo {
enum Bar {
Boo = [unsafe { Foo { b: () }.a }; 4][3],
//~^ ERROR constant evaluation of enum discriminant resulted in non-integer
//~^ ERROR could not evaluate enum discriminant
}
fn main() {

View file

@ -0,0 +1,16 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
const PARSE_BOOL: Option<&'static str> = None;
static FOO: (Option<&str>, u32) = (PARSE_BOOL, 42);
fn main() {}

View file

@ -34,7 +34,7 @@ const fn read_field2() -> Field2 {
}
const fn read_field3() -> Field3 {
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR exhibits undefined behavior
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR cannot be used
FIELD3
}

View file

@ -1,11 +1,10 @@
error[E0080]: this constant likely exhibits undefined behavior
error: this constant cannot be used
--> $DIR/union-const-eval-field.rs:37:5
|
LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR exhibits undefined behavior
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes
LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR cannot be used
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
= note: #[deny(const_err)] on by default
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -20,9 +20,9 @@ union DummyUnion {
const UNION: DummyUnion = DummyUnion { field1: 1065353216 };
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant likely exhibits undefined
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant cannot be used
const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior
const FIELD_PATH: Struct = Struct { //~ ERROR this constant cannot be used
a: 42,
b: unsafe { UNION.field3 },
};

View file

@ -1,21 +1,19 @@
error[E0080]: this constant likely exhibits undefined behavior
error: this constant cannot be used
--> $DIR/union-ice.rs:23:1
|
LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant likely exhibits undefined
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes
LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant cannot be used
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempted to read undefined bytes
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
= note: #[deny(const_err)] on by default
error[E0080]: this constant likely exhibits undefined behavior
error: this constant cannot be used
--> $DIR/union-ice.rs:25:1
|
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR this constant cannot be used
LL | | a: 42,
LL | | b: unsafe { UNION.field3 },
LL | | };
| |__^ type validation failed: encountered undefined bytes at .b
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
| |__^ attempted to read undefined bytes
error[E0080]: this constant likely exhibits undefined behavior
--> $DIR/union-ice.rs:35:1