-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Panic within a panic causes illegal instruction SIGILL #53814
Comments
The real MVP @mgattozzi realized what the problem was in a second. The display impl panics within the panic in the test and that's what causes the problem. Here's an even more minimal reproduction: use std::fmt;
pub struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
panic!()
}
}
#[test]
fn something() {
panic!("{}", Foo);
}
I guess you could say I did a good job writing this issue given that someone was able to take a cursory look at it and figure out so much. Sorry I didn't catch it myself! 😆 |
I'm going to close this issue because I think this is expected behaviour. I totally misunderstood the bug and thought it was happening during compilation. Sorry about that folks! 😨 Looks like it's time for me to go to bed. 😴 |
See first comment for an even smaller example of the issue. Thanks @mgattozzi for the insight that led to that!
I was integrating
NonZeroU8
into some code when I ran into an illegal instruction error that looks like this:I spent a really long time trying to narrow this down and I got down to the following contrived example: (Rust Playground)
This probably looks like super weird code that no one would ever write, but this started from some real code I promise. 😆
The key part of this code is:
The illegal instruction error occurs whenever that
0
is any value less than or equal to zero. You may be asking yourself "How do you make a u8 literal less than zero?" Well you don't. Rust protects you from that. The thing that Rust doesn't protect you from is this: (Rust Playground)The variable
x
will be-1
and the code will produce the same illegal instruction error.Some weird things to note about this:
cargo run
. The failure is oncargo test
.Display
. Inlining does NOT produce the error:The text was updated successfully, but these errors were encountered: