-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`asm!()` is forced to be wrapped inside unsafe. If there's no special treatment, the label blocks would also always be unsafe with no way of opting out.
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 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
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,23 @@ | ||
//@ only-x86_64 | ||
//@ needs-asm-support | ||
|
||
#![deny(unreachable_code)] | ||
#![feature(asm_goto)] | ||
|
||
use std::arch::asm; | ||
|
||
fn goto_fallthough() { | ||
unsafe { | ||
asm!( | ||
"/* {} */", | ||
label { | ||
core::hint::unreachable_unchecked(); | ||
//~^ ERROR [E0133] | ||
} | ||
) | ||
} | ||
} | ||
|
||
fn main() { | ||
goto_fallthough(); | ||
} |
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,14 @@ | ||
error[E0133]: call to unsafe function `unreachable_unchecked` is unsafe and requires unsafe function or block | ||
--> $DIR/goto-block-safe.rs:14:17 | ||
| | ||
LL | unsafe { | ||
| ------ items do not inherit unsafety from separate enclosing items | ||
... | ||
LL | core::hint::unreachable_unchecked(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |