File tree 7 files changed +59
-4
lines changed
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>(
773
773
kind: ast:: VisibilityKind :: Inherited ,
774
774
tokens: None ,
775
775
} ,
776
- span: ecx . with_def_site_ctxt ( sp ) ,
776
+ span: sp ,
777
777
tokens: None ,
778
778
} ) ] )
779
779
} else {
Original file line number Diff line number Diff line change @@ -72,8 +72,11 @@ lint_builtin_explicit_outlives = outlives requirements can be inferred
72
72
73
73
lint_builtin_export_name_fn = declaration of a function with `export_name`
74
74
lint_builtin_export_name_method = declaration of a method with `export_name`
75
-
76
75
lint_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
+
77
80
lint_builtin_impl_unsafe_method = implementation of an `unsafe` method
78
81
79
82
lint_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 {
393
393
}
394
394
}
395
395
396
+ ast:: ItemKind :: GlobalAsm ( ..) => {
397
+ self . report_unsafe ( cx, it. span , BuiltinUnsafe :: GlobalAsm ) ;
398
+ }
399
+
396
400
_ => { }
397
401
}
398
402
}
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ pub enum BuiltinUnsafe {
114
114
DeclUnsafeMethod ,
115
115
#[ diag( lint_builtin_impl_unsafe_method) ]
116
116
ImplUnsafeMethod ,
117
+ #[ diag( lint_builtin_global_asm) ]
118
+ #[ note( lint_builtin_global_macro_unsafety) ]
119
+ GlobalAsm ,
117
120
}
118
121
119
122
#[ 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
9
9
|
10
10
LL | global_asm!("");
11
11
| ^^^^^^^^^^^^^^^
12
- |
13
- = note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
14
12
15
13
error: aborting due to 2 previous errors
16
14
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