forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
unreachable!()
override macro + new tests (rust-lang#1372)
My latest change to handling panic messages actually broke `unreachable` macro. The main issue was the wrong position of a parenthesis and the fact that we didn't have tests that covered that specific case of the macro. One thing I haven't figured out yet is how to trigger an error if the user code uses edition 2021+ and has the following construct: ```rust let msg = "blah"; panic!(msg); ``` This is actually an error in 2021+, but the macro override that we perform accepts that no matter the edition.
- Loading branch information
Showing
3 changed files
with
54 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Failed Checks: internal error: entered unreachable code: msg | ||
Failed Checks: internal error: entered unreachable code: | ||
Failed Checks: internal error: entered unreachable code: Error message | ||
Failed Checks: internal error: entered unreachable code: "Unreachable message with arg {}", "str" | ||
Failed Checks: internal error: entered unreachable code: "{}", msg | ||
|
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,15 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that our macro override supports different types of messages. | ||
#[kani::proof] | ||
fn check_unreachable() { | ||
let msg = "Oops."; | ||
match kani::any::<u8>() { | ||
0 => unreachable!(), | ||
1 => unreachable!("Error message"), | ||
2 => unreachable!("Unreachable message with arg {}", "str"), | ||
3 => unreachable!("{}", msg), | ||
_ => unreachable!(msg), | ||
} | ||
} |