File tree Expand file tree Collapse file tree 7 files changed +59
-4
lines changed Expand file tree Collapse file tree 7 files changed +59
-4
lines changed Original file line number Diff line number Diff line change @@ -773,7 +773,7 @@ pub(super) fn expand_global_asm<'cx>(
773773 kind: ast:: VisibilityKind :: Inherited ,
774774 tokens: None ,
775775 } ,
776- span: ecx . with_def_site_ctxt ( sp ) ,
776+ span: sp ,
777777 tokens: None ,
778778 } ) ] )
779779 } else {
Original file line number Diff line number Diff line change @@ -72,8 +72,11 @@ lint_builtin_explicit_outlives = outlives requirements can be inferred
7272
7373lint_builtin_export_name_fn = declaration of a function with `export_name`
7474lint_builtin_export_name_method = declaration of a method with `export_name`
75-
7675lint_builtin_export_name_static = declaration of a static with `export_name`
76+
77+ lint_builtin_global_asm = usage of `core::arch::global_asm`
78+ lint_builtin_global_macro_unsafety = using this macro is unsafe even though it does not need an `unsafe` block
79+
7780lint_builtin_impl_unsafe_method = implementation of an `unsafe` method
7881
7982lint_builtin_incomplete_features = the feature `{ $name } ` is incomplete and may not be safe to use and/or cause compiler crashes
Original file line number Diff line number Diff line change @@ -393,6 +393,10 @@ impl EarlyLintPass for UnsafeCode {
393393 }
394394 }
395395
396+ ast:: ItemKind :: GlobalAsm ( ..) => {
397+ self . report_unsafe ( cx, it. span , BuiltinUnsafe :: GlobalAsm ) ;
398+ }
399+
396400 _ => { }
397401 }
398402 }
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ pub enum BuiltinUnsafe {
114114 DeclUnsafeMethod ,
115115 #[ diag( lint_builtin_impl_unsafe_method) ]
116116 ImplUnsafeMethod ,
117+ #[ diag( lint_builtin_global_asm) ]
118+ #[ note( lint_builtin_global_macro_unsafety) ]
119+ GlobalAsm ,
117120}
118121
119122#[ derive( LintDiagnostic ) ]
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ error[E0472]: inline assembly is unsupported on this target
99 |
1010LL | global_asm!("");
1111 | ^^^^^^^^^^^^^^^
12- |
13- = note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
1412
1513error: aborting due to 2 previous errors
1614
Original file line number Diff line number Diff line change 1+ //@ needs-asm-support
2+ #![ deny( unsafe_code) ]
3+
4+ use std:: arch:: global_asm;
5+
6+ #[ allow( unsafe_code) ]
7+ mod allowed_unsafe {
8+ std:: arch:: global_asm!( "" ) ;
9+ }
10+
11+ macro_rules! unsafe_in_macro {
12+ ( ) => {
13+ global_asm!( "" ) ; //~ ERROR: usage of `core::arch::global_asm`
14+ } ;
15+ }
16+
17+ global_asm ! ( "" ) ; //~ ERROR: usage of `core::arch::global_asm`
18+ unsafe_in_macro ! ( ) ;
19+
20+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: usage of `core::arch::global_asm`
2+ --> $DIR/lint-global-asm-as-unsafe.rs:17:1
3+ |
4+ LL | global_asm!("");
5+ | ^^^^^^^^^^^^^^^
6+ |
7+ = note: using this macro is unsafe even though it does not need an `unsafe` block
8+ note: the lint level is defined here
9+ --> $DIR/lint-global-asm-as-unsafe.rs:2:9
10+ |
11+ LL | #![deny(unsafe_code)]
12+ | ^^^^^^^^^^^
13+
14+ error: usage of `core::arch::global_asm`
15+ --> $DIR/lint-global-asm-as-unsafe.rs:13:9
16+ |
17+ LL | global_asm!("");
18+ | ^^^^^^^^^^^^^^^
19+ ...
20+ LL | unsafe_in_macro!();
21+ | ------------------ in this macro invocation
22+ |
23+ = note: using this macro is unsafe even though it does not need an `unsafe` block
24+ = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
25+
26+ error: aborting due to 2 previous errors
27+
You can’t perform that action at this time.
0 commit comments