-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #52011 - oli-obk:dont_you_hate_it_too_when_everything_p…
…anics_constantly, r=eddyb Allow panicking with string literal messages inside constants r? @eddyb cc #51999 we can't implement things like `panic!("foo: {}", x)` right now because we can't call trait methods (most notably `Display::fmt`) inside constants. Also most of these impls probably have loops and conditions, so it's messy anyway. But hey `panic!("foo")` works at least. cc @japaric got any test ideas for `#![no_std]`?
- Loading branch information
Showing
20 changed files
with
368 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.