Allow panicking with string literal messages inside constants

This commit is contained in:
Oliver Schneider 2018-08-13 13:48:47 +02:00
parent 674ef668f1
commit bb78426ca8
20 changed files with 366 additions and 25 deletions

View file

@ -0,0 +1,22 @@
// 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.
#![feature(const_panic)]
fn main() {}
const Z: () = panic!("cheese");
//~^ ERROR this constant cannot be used
const Y: () = unreachable!();
//~^ ERROR this constant cannot be used
const X: () = unimplemented!();
//~^ ERROR this constant cannot be used

View file

@ -0,0 +1,33 @@
error: this constant cannot be used
--> $DIR/const_panic.rs:15:1
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:15:15
|
= note: #[deny(const_err)] on by default
= 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: this constant cannot be used
--> $DIR/const_panic.rs:18:1
|
LL | const Y: () = unreachable!();
| ^^^^^^^^^^^^^^--------------^
| |
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:18:15
|
= 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: this constant cannot be used
--> $DIR/const_panic.rs:21:1
|
LL | const X: () = unimplemented!();
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic.rs:21:15
|
= 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 3 previous errors

View file

@ -0,0 +1,22 @@
// 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.
#![no_std]
#![crate_type = "lib"]
#![feature(const_panic)]
const Z: () = panic!("cheese");
//~^ ERROR this constant cannot be used
const Y: () = unreachable!();
//~^ ERROR this constant cannot be used
const X: () = unimplemented!();
//~^ ERROR this constant cannot be used

View file

@ -0,0 +1,33 @@
error: this constant cannot be used
--> $DIR/const_panic_libcore.rs:15:1
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore.rs:15:15
|
= note: #[deny(const_err)] on by default
= 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: this constant cannot be used
--> $DIR/const_panic_libcore.rs:18:1
|
LL | const Y: () = unreachable!();
| ^^^^^^^^^^^^^^--------------^
| |
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore.rs:18:15
|
= 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: this constant cannot be used
--> $DIR/const_panic_libcore.rs:21:1
|
LL | const X: () = unimplemented!();
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore.rs:21:15
|
= 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 3 previous errors

View file

@ -0,0 +1,35 @@
// 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.
#![crate_type = "bin"]
#![feature(lang_items)]
#![feature(panic_implementation)]
#![feature(const_panic)]
#![no_main]
#![no_std]
use core::panic::PanicInfo;
const Z: () = panic!("cheese");
//~^ ERROR this constant cannot be used
const Y: () = unreachable!();
//~^ ERROR this constant cannot be used
const X: () = unimplemented!();
//~^ ERROR this constant cannot be used
#[lang = "eh_personality"]
fn eh() {}
#[panic_implementation]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

View file

@ -0,0 +1,33 @@
error: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:20:1
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:20:15
|
= note: #[deny(const_err)] on by default
= 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: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:23:1
|
LL | const Y: () = unreachable!();
| ^^^^^^^^^^^^^^--------------^
| |
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:23:15
|
= 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: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:26:1
|
LL | const X: () = unimplemented!();
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:26:15
|
= 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 3 previous errors

View file

@ -0,0 +1,20 @@
// 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.
fn main() {}
const Z: () = panic!("cheese");
//~^ ERROR panicking in constants is unstable
const Y: () = unreachable!();
//~^ ERROR panicking in constants is unstable
const X: () = unimplemented!();
//~^ ERROR panicking in constants is unstable

View file

@ -0,0 +1,30 @@
error[E0658]: panicking in constants is unstable (see issue #51999)
--> $DIR/feature-gate-const_panic.rs:13:15
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_panic)] to the crate attributes to enable
= 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[E0658]: panicking in constants is unstable (see issue #51999)
--> $DIR/feature-gate-const_panic.rs:19:15
|
LL | const X: () = unimplemented!();
| ^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_panic)] to the crate attributes to enable
= 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[E0658]: panicking in constants is unstable (see issue #51999)
--> $DIR/feature-gate-const_panic.rs:16:15
|
LL | const Y: () = unreachable!();
| ^^^^^^^^^^^^^^
|
= help: add #![feature(const_panic)] to the crate attributes to enable
= 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 3 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -9,7 +9,7 @@
// except according to those terms.
static S : u64 = { { panic!("foo"); 0 } };
//~^ ERROR calls in statics are limited
//~^ ERROR panicking in statics is unstable
fn main() {
println!("{:?}", S);

View file

@ -1,11 +1,12 @@
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
error[E0658]: panicking in statics is unstable (see issue #51999)
--> $DIR/issue-32829.rs:11:22
|
LL | static S : u64 = { { panic!("foo"); 0 } };
| ^^^^^^^^^^^^^^
|
= help: add #![feature(const_panic)] to the crate attributes to enable
= 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 previous error
For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0658`.