-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Allow Abort
terminators in all const-contexts
#77512
Changes from 3 commits
98a2292
a5f0831
14c3705
25fdbaf
fe97990
6ae1da3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(unwind_attributes, const_panic)] | ||
|
||
#[unwind(aborts)] | ||
const fn foo() { | ||
panic!() //~ evaluation of constant value failed | ||
RalfJung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const _: () = foo(); //~ any use of this value will cause an error | ||
ecstatic-morse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fn main() { | ||
let _ = foo(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/unwind-abort.rs:5:5 | ||
| | ||
LL | panic!() | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:5:5 | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/unwind-abort.rs:8:15 | ||
| | ||
LL | const _: () = foo(); | ||
| --------------^^^^^- | ||
| | | ||
| referenced constant has errors | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// check-pass | ||
|
||
#![feature(unwind_attributes, const_panic)] | ||
|
||
// `#[unwind(aborts)]` is okay for a `const fn`. We don't unwind in const-eval anyways. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add two tests? Our test suite is already huge.^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One is check-pass, the other fails to compile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see that, I just do not understand their respective purpose. Specifically, "consts/unwind-abort" does not even run any CTFE, and the other test already checks that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 I'm happy with the test coverage in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to understand what My concern is not too little coverage; my concern is unnecessarily growing the number of UI tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to split up passing and failing tests when possible. One is solely a test of const-checking and involves no const-eval, the other is a sanity check to ensure that the CTFE engine doesn't do anything weird when evaluating something with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this unnecessarily leads to an excessive number of tests in our UI test suite that is already so big that it becomes hard to run the entire thing, but whatever. Could you add comments to these tests explaining what they are meant to test? |
||
#[unwind(aborts)] | ||
const fn foo() { | ||
panic!() | ||
} | ||
|
||
const fn bar() { | ||
foo(); | ||
} | ||
|
||
fn main() { | ||
bar(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here saying that
Abort
terminators are only used for#[unwind(aborts)]
and since CTFE does not unwind, they are thus unreachable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could just
span_bug
here actually. AFAICT, there are onlyAbort
s in "cleanup" blocks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea but does not replace a comment. :)