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.
Rollup merge of rust-lang#121318 - kadiwa4:no_assembly_in_supposedly_…
…safe_code, r=Nilstrieb Trigger `unsafe_code` lint on invocations of `global_asm` `unsafe_code` already warns about things that don't involve the `unsafe` keyword, e.g. `#[no_mangle]`. This makes it warn on `core::arch::global_asm` too. Fixes rust-lang#103078
- Loading branch information
Showing
7 changed files
with
59 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
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
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,20 @@ | ||
//@ needs-asm-support | ||
#![deny(unsafe_code)] | ||
|
||
use std::arch::global_asm; | ||
|
||
#[allow(unsafe_code)] | ||
mod allowed_unsafe { | ||
std::arch::global_asm!(""); | ||
} | ||
|
||
macro_rules! unsafe_in_macro { | ||
() => { | ||
global_asm!(""); //~ ERROR: usage of `core::arch::global_asm` | ||
}; | ||
} | ||
|
||
global_asm!(""); //~ ERROR: usage of `core::arch::global_asm` | ||
unsafe_in_macro!(); | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
tests/ui/lint/unsafe_code/lint-global-asm-as-unsafe.stderr
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,27 @@ | ||
error: usage of `core::arch::global_asm` | ||
--> $DIR/lint-global-asm-as-unsafe.rs:17:1 | ||
| | ||
LL | global_asm!(""); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: using this macro is unsafe even though it does not need an `unsafe` block | ||
note: the lint level is defined here | ||
--> $DIR/lint-global-asm-as-unsafe.rs:2:9 | ||
| | ||
LL | #![deny(unsafe_code)] | ||
| ^^^^^^^^^^^ | ||
|
||
error: usage of `core::arch::global_asm` | ||
--> $DIR/lint-global-asm-as-unsafe.rs:13:9 | ||
| | ||
LL | global_asm!(""); | ||
| ^^^^^^^^^^^^^^^ | ||
... | ||
LL | unsafe_in_macro!(); | ||
| ------------------ in this macro invocation | ||
| | ||
= note: using this macro is unsafe even though it does not need an `unsafe` block | ||
= note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|