-
Notifications
You must be signed in to change notification settings - Fork 13.4k
check that first arg to panic!()
in const is &str
#80734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
// This is a separate test from `issue-66693.rs` because array lengths are evaluated | ||
// in a separate stage before `const`s and `statics` and so the error below is hit and | ||
// the compiler exits before generating errors for the others. | ||
|
||
#![feature(const_panic)] | ||
|
||
fn main() { | ||
let _ = [0i32; panic!(2f32)]; | ||
//~^ ERROR: argument to `panic!()` in a const context must have type `&str` | ||
|
||
// ensure that conforming panics are handled correctly | ||
let _ = [false; panic!()]; | ||
//~^ ERROR: evaluation of constant value failed | ||
|
||
// typechecking halts before getting to this one | ||
let _ = ['a', panic!("panic in array len")]; | ||
} |
This file contains hidden or 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,19 @@ | ||
error: argument to `panic!()` in a const context must have type `&str` | ||
--> $DIR/issue-66693-panic-in-array-len.rs:8:20 | ||
| | ||
LL | let _ = [0i32; panic!(2f32)]; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/issue-66693-panic-in-array-len.rs:12:21 | ||
| | ||
LL | let _ = [false; panic!()]; | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-66693-panic-in-array-len.rs:12:21 | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
This file contains hidden or 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,24 @@ | ||
// Tests that the compiler does not ICE when const-evaluating a `panic!()` invocation with a | ||
// non-`&str` argument. | ||
|
||
#![feature(const_panic)] | ||
|
||
const _: () = panic!(1); | ||
//~^ ERROR: argument to `panic!()` in a const context must have type `&str` | ||
|
||
static _FOO: () = panic!(true); | ||
//~^ ERROR: argument to `panic!()` in a const context must have type `&str` | ||
|
||
const fn _foo() { | ||
panic!(&1); //~ ERROR: argument to `panic!()` in a const context must have type `&str` | ||
} | ||
|
||
// ensure that conforming panics don't cause an error | ||
const _: () = panic!(); | ||
static _BAR: () = panic!("panic in static"); | ||
|
||
const fn _bar() { | ||
panic!("panic in const fn"); | ||
} | ||
|
||
fn main() {} |
This file contains hidden or 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,26 @@ | ||
error: argument to `panic!()` in a const context must have type `&str` | ||
--> $DIR/issue-66693.rs:13:5 | ||
| | ||
LL | panic!(&1); | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: argument to `panic!()` in a const context must have type `&str` | ||
--> $DIR/issue-66693.rs:6:15 | ||
| | ||
LL | const _: () = panic!(1); | ||
| ^^^^^^^^^ | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: argument to `panic!()` in a const context must have type `&str` | ||
--> $DIR/issue-66693.rs:9:19 | ||
| | ||
LL | static _FOO: () = panic!(true); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
struct Bug([u8; panic!(1)]); //~ ERROR panicking in constants is unstable | ||
// Note: non-`&str` panic arguments gained a separate error in PR #80734 | ||
// which is why this doesn't match the issue | ||
struct Bug([u8; panic!("panic")]); //~ ERROR panicking in constants is unstable | ||
|
||
fn main() {} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.