Uh oh!
There was an error while loading. Please reload this page.
Allow panicking with string literal messages inside constants - #52011
Conversation
This comment has been minimized.
This comment has been minimized.
70760f5 to
a26713aComparerust-highfive
commented
Jul 3, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
oli-obk
commented
Jul 3, 2018
lol... uhm... there's a This seems very fragile (like if an |
rust-highfive
commented
Jul 3, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
japaric
commented
Jul 5, 2018
@oli-obk I would test this both in rlib context and in binary context as the later requires the panic_impl lang item. The tests would look like this: #![no_std]#![crate_type = "lib"]constZ:() = panic!("cheese");constY:() = unreachable!();constX:() = unimplemented!();#![crate_type = "bin"]#![feature(lang_items)]#![feature(panic_implementation)]#![no_main]#![no_std]use core::panic::PanicInfo;constZ:() = panic!("cheese");constY:() = unreachable!();constX:() = unimplemented!();#[lang = "eh_personality"]fneh(){}#[panic_implementation]fnpanic(_info:&PanicInfo) -> ! {loop{}}
|
oli-obk
commented
Jul 6, 2018
I already had it implemented. I just failed at building the test cases |
rust-highfive
commented
Jul 6, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
957ea32 to
203453aComparerust-highfive
commented
Jul 6, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
203453a to
180df96Comparebors
commented
Jul 11, 2018
☔ The latest upstream changes (presumably #51702) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
You want to use Symbol for msg and file.
There was a problem hiding this comment.
... and intern to Symbol here, without allocating a copy of the string slice!
There was a problem hiding this comment.
Oh, because the original value also came from a symbol? Or for making cloning the error cheap?
There was a problem hiding this comment.
This appears to require no feature-gate - I don't think this should be insta-stable. Or is it impossible to feature-gate because panic! has allow_internal_unstable?
There was a problem hiding this comment.
Curious. I should be able to work around this easily. Maybe const stability of const fns should not be allowed to be circumvented by rustc macros?
There was a problem hiding this comment.
I tried. I have no idea how this test is still passing. We seem to be having a stability hole.
There was a problem hiding this comment.
"evaluated" doesn't feel right in user output. Maybe mimick the runtime output and say:
panicked at 'cheese', $DIR/const_panic_libcore.rs:14:15
There was a problem hiding this comment.
I had that. Our test suite is not able to cope with that because it greps for panicked at and reports a compiler panic. Once the test suite is adjusted, I can fix the message
There was a problem hiding this comment.
Maybe something like const panic at 'cheese' instead?
There was a problem hiding this comment.
Why not just change the test suite to search for ' panicked at ', i.e. take advantage of the fact that there should be a non-space character before the space before "panicked"?
There was a problem hiding this comment.
Once #52197 is merged we don't need any more text hacks. I'll just wait for that
eddyb
commented
Jul 12, 2018
cc @alexcrichton@nikomatsakis on #52011 (comment) (insta-stable feature) |
180df96 to
188e451Comparekennytm
commented
Jul 14, 2018
(For easy checking: this PR is blocked on #52197.) |
bors
commented
Jul 15, 2018
☔ The latest upstream changes (presumably #52318) made this pull request unmergeable. Please resolve the merge conflicts. |
188e451 to
6633df0Compareoli-obk
commented
Jul 19, 2018
Unblocked and fixed |
emilyalbini
commented
Jul 23, 2018
Ping from triage @eddyb! This PR needs your review. |
emilyalbini
commented
Jul 30, 2018
Failure log: |
bors
commented
Aug 19, 2018
⌛ Testing commit 768ffb714d0ebab8faa9ff6d97307219615016ca with merge 741e7c3c07a2b4a7630b9c35516eec4105991fca... |
bors
commented
Aug 19, 2018
💔 Test failed - status-appveyor |
A lang item is not defined. Same error as #52011 (comment). Details ---- [ui] ui\const-eval\const_panic_libcore_main.rs stdout ----
diff of stderr:
- 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: language item required, but not found: `eh_unwind_resume`
11 - 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+ error: aborting due to previous error
33 34 |
bors
commented
Aug 20, 2018
☔ The latest upstream changes (presumably #52953) made this pull request unmergeable. Please resolve the merge conflicts. |
768ffb7 to
0db77ddCompare0db77dd to
bd6ae6aCompareoli-obk
commented
Aug 22, 2018
rebased and added lang item to test @bors r=eddyb |
bors
commented
Aug 22, 2018
📌 Commit bd6ae6a has been approved by |
| } else { | ||
| bug!("panic arg is not a str") | ||
| } | ||
| } |
There was a problem hiding this comment.
We have that same code in miri...^^
bors
commented
Aug 22, 2018
…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]`?
bors
commented
Aug 23, 2018
☀️ Test successful - status-appveyor, status-travis |
r? @eddyb
cc #51999
we can't implement things like
panic!("foo: {}", x)right now because we can't call trait methods (most notablyDisplay::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]?