Promote Refs to constants instead of static

This commit is contained in:
Santiago Pastorino 2019-11-22 17:26:09 -03:00 committed by Oliver Scherer
parent a59abfa450
commit 1688719214
53 changed files with 447 additions and 223 deletions

View file

@ -4,4 +4,5 @@ fn main() {
&{[1, 2, 3][4]};
//~^ ERROR index out of bounds
//~| ERROR reaching this expression at runtime will panic or abort
//~| ERROR erroneous constant used [E0080]
}

View file

@ -14,5 +14,12 @@ LL | &{[1, 2, 3][4]};
| |
| indexing out of bounds: the len is 3 but the index is 4
error: aborting due to 2 previous errors
error[E0080]: erroneous constant used
--> $DIR/array-literal-index-oob.rs:4:5
|
LL | &{[1, 2, 3][4]};
| ^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -10,4 +10,5 @@ const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
fn main() {
println!("{}", FOO);
//~^ ERROR
//~| ERROR erroneous constant used [E0080]
}

View file

@ -18,6 +18,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{}", FOO);
| ^^^ referenced constant has errors
error: aborting due to previous error
error[E0080]: erroneous constant used
--> $DIR/conditional_array_execution.rs:11:20
|
LL | println!("{}", FOO);
| ^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -17,6 +17,8 @@ const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
fn main() {
assert_eq!(Y, 4);
//~^ ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080]
assert_eq!(Z, 4);
//~^ ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080]
}

View file

@ -14,8 +14,16 @@ LL | assert_eq!(Y, 4);
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0080]: erroneous constant used
--> $DIR/const_fn_ptr_fail2.rs:18:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:20:5
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^-^^^^^
@ -24,6 +32,14 @@ LL | assert_eq!(Z, 4);
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 2 previous errors
error[E0080]: erroneous constant used
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -14,4 +14,6 @@ fn main() {
println!("{} {}", X, Y);
//~^ ERROR evaluation of constant expression failed
//~| ERROR evaluation of constant expression failed
//~| ERROR erroneous constant used [E0080]
//~| ERROR erroneous constant used [E0080]
}

View file

@ -26,12 +26,24 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{} {}", X, Y);
| ^ referenced constant has errors
error[E0080]: erroneous constant used
--> $DIR/issue-43197.rs:14:23
|
LL | println!("{} {}", X, Y);
| ^ referenced constant has errors
error[E0080]: evaluation of constant expression failed
--> $DIR/issue-43197.rs:14:26
|
LL | println!("{} {}", X, Y);
| ^ referenced constant has errors
error: aborting due to 2 previous errors
error[E0080]: erroneous constant used
--> $DIR/issue-43197.rs:14:26
|
LL | println!("{} {}", X, Y);
| ^ referenced constant has errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -25,5 +25,6 @@ impl Foo for u16 {
fn main() {
println!("{}", <Bar<u16, u8> as Foo>::AMT);
//~^ ERROR E0080
//~^ ERROR erroneous constant used [E0080]
//~| ERROR evaluation of constant expression failed [E0080]
}

View file

@ -4,6 +4,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to previous error
error[E0080]: erroneous constant used
--> $DIR/issue-44578.rs:27:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -12,11 +12,13 @@ impl Unsigned for U8 {
struct Sum<A,B>(A,B);
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error
const MAX: u8 = A::MAX + B::MAX;
//~^ ERROR any use of this value will cause an error [const_err]
}
fn foo<T>(_: T) -> &'static u8 {
&Sum::<U8,U8>::MAX //~ ERROR E0080
&Sum::<U8,U8>::MAX
//~^ ERROR E0080
}
fn main() {

View file

@ -9,7 +9,7 @@ LL | const MAX: u8 = A::MAX + B::MAX;
= note: `#[deny(const_err)]` on by default
error[E0080]: evaluation of constant expression failed
--> $DIR/issue-50814.rs:19:5
--> $DIR/issue-50814.rs:20:5
|
LL | &Sum::<U8,U8>::MAX
| ^-----------------

View file

@ -10,11 +10,13 @@ fn main() {
println!("{}", 1/(1-1));
//~^ ERROR attempt to divide by zero [const_err]
//~| ERROR const_err
//~| ERROR erroneous constant used [E0080]
let _x = 1/(1-1);
//~^ ERROR const_err
println!("{}", 1/(false as u32));
//~^ ERROR attempt to divide by zero [const_err]
//~| ERROR const_err
//~| ERROR erroneous constant used [E0080]
let _x = 1/(false as u32);
//~^ ERROR const_err
}

View file

@ -22,29 +22,42 @@ error: reaching this expression at runtime will panic or abort
LL | println!("{}", 1/(1-1));
| ^^^^^^^ dividing by zero
error[E0080]: erroneous constant used
--> $DIR/promoted_errors.rs:10:20
|
LL | println!("{}", 1/(1-1));
| ^^^^^^^ referenced constant has errors
error: attempt to divide by zero
--> $DIR/promoted_errors.rs:13:14
--> $DIR/promoted_errors.rs:14:14
|
LL | let _x = 1/(1-1);
| ^^^^^^^
error: attempt to divide by zero
--> $DIR/promoted_errors.rs:15:20
--> $DIR/promoted_errors.rs:16:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors.rs:15:20
--> $DIR/promoted_errors.rs:16:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used
--> $DIR/promoted_errors.rs:16:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero
--> $DIR/promoted_errors.rs:18:14
--> $DIR/promoted_errors.rs:20:14
|
LL | let _x = 1/(false as u32);
| ^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -11,11 +11,13 @@ fn main() {
println!("{}", 1/(1-1));
//~^ ERROR attempt to divide by zero [const_err]
//~| ERROR const_err
//~| ERROR erroneous constant used [E0080]
let _x = 1/(1-1);
//~^ ERROR const_err
println!("{}", 1/(false as u32));
//~^ ERROR attempt to divide by zero [const_err]
//~| ERROR const_err
//~| ERROR erroneous constant used [E0080]
let _x = 1/(false as u32);
//~^ ERROR const_err
}

View file

@ -28,29 +28,42 @@ error: reaching this expression at runtime will panic or abort
LL | println!("{}", 1/(1-1));
| ^^^^^^^ dividing by zero
error[E0080]: erroneous constant used
--> $DIR/promoted_errors2.rs:11:20
|
LL | println!("{}", 1/(1-1));
| ^^^^^^^ referenced constant has errors
error: attempt to divide by zero
--> $DIR/promoted_errors2.rs:14:14
--> $DIR/promoted_errors2.rs:15:14
|
LL | let _x = 1/(1-1);
| ^^^^^^^
error: attempt to divide by zero
--> $DIR/promoted_errors2.rs:16:20
--> $DIR/promoted_errors2.rs:17:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^
error: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors2.rs:16:20
--> $DIR/promoted_errors2.rs:17:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^ dividing by zero
error[E0080]: erroneous constant used
--> $DIR/promoted_errors2.rs:17:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^ referenced constant has errors
error: attempt to divide by zero
--> $DIR/promoted_errors2.rs:19:14
--> $DIR/promoted_errors2.rs:21:14
|
LL | let _x = 1/(false as u32);
| ^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors
error: aborting due to 10 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -13,7 +13,7 @@ LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
LL | | // Use address-of-element for pointer arithmetic. This could wrap around to NULL!
LL | | let out_of_bounds_ptr = &ptr[255];
| | ^^^^^^^^^ Memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of allocation 6 which has size 1
| | ^^^^^^^^^ Memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of allocation 8 which has size 1
LL | | mem::transmute(out_of_bounds_ptr)
LL | | } };
| |____-

View file

@ -11,5 +11,7 @@ const C: () = foo(); //~ WARN: skipping const checks
//~^ WARN any use of this value will cause an error
fn main() {
println!("{:?}", C); //~ ERROR: evaluation of constant expression failed
println!("{:?}", C);
//~^ ERROR: evaluation of constant expression failed
//~| ERROR: erroneous constant used [E0080]
}

View file

@ -24,6 +24,12 @@ error[E0080]: evaluation of constant expression failed
LL | println!("{:?}", C);
| ^ referenced constant has errors
error: aborting due to previous error
error[E0080]: erroneous constant used
--> $DIR/non_const_fn.rs:14:22
|
LL | println!("{:?}", C);
| ^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -7,13 +7,15 @@ static FOO: Foo = Foo;
fn main() {
let x: &'static () = &();
assert_eq!(x as *const () as usize, 1);
assert_ne!(x as *const () as usize, 1);
let x: &'static Foo = &Foo;
assert_eq!(x as *const Foo as usize, 4);
assert_ne!(x as *const Foo as usize, 4);
// statics must have a unique address
assert_ne!(&FOO as *const Foo as usize, 4);
assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
// FIXME this two tests should be assert_eq!
// this stopped working since we are promoting to constants instead of statics
assert_ne!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
assert_ne!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
}

View file

@ -1,61 +0,0 @@
// run-pass
#![allow(unused_mut)]
// ignore-wasm32
// ignore-emscripten
// ignore-sgx no processes
// compile-flags: -C debug_assertions=yes
#![stable(feature = "rustc", since = "1.0.0")]
#![feature(const_fn, rustc_private, staged_api, rustc_attrs)]
#![allow(const_err)]
extern crate libc;
use std::env;
use std::process::{Command, Stdio};
// this will panic in debug mode and overflow in release mode
//
// NB we give bar an unused argument because otherwise memoization
// of the const fn kicks in, causing a different code path in the
// compiler to be executed (see PR #66294).
#[stable(feature = "rustc", since = "1.0.0")]
#[rustc_const_stable(feature = "rustc", since = "1.0.0")]
#[rustc_promotable]
const fn bar(_: bool) -> usize { 0 - 1 }
fn foo() {
let _: &'static _ = &bar(true);
}
#[cfg(unix)]
fn check_status(status: std::process::ExitStatus)
{
use std::os::unix::process::ExitStatusExt;
assert!(status.signal() == Some(libc::SIGILL)
|| status.signal() == Some(libc::SIGTRAP)
|| status.signal() == Some(libc::SIGABRT));
}
#[cfg(not(unix))]
fn check_status(status: std::process::ExitStatus)
{
assert!(!status.success());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() > 1 && args[1] == "test" {
foo();
return;
}
let mut p = Command::new(&args[0])
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.arg("test").output().unwrap();
check_status(p.status);
}

View file

@ -46,13 +46,13 @@ error: def-path(bar::<impl foo::Foo>::baz)
LL | #[rustc_def_path]
| ^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h92c563325b7ff21aE)
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17hf07584432cd4d8beE)
--> $DIR/impl1.rs:62:13
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::h92c563325b7ff21a)
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::hf07584432cd4d8be)
--> $DIR/impl1.rs:62:13
|
LL | #[rustc_symbol_name]