@@ -2,8 +2,11 @@ use std::fmt;
2
2
3
3
use clippy_utils:: diagnostics:: span_lint_and_help;
4
4
use rustc_ast:: ast:: { Expr , ExprKind , InlineAsmOptions } ;
5
- use rustc_lint:: { EarlyContext , EarlyLintPass , Lint } ;
5
+ use rustc_ast:: { InlineAsm , Item , ItemKind } ;
6
+ use rustc_lint:: { EarlyContext , EarlyLintPass , Lint , LintContext } ;
6
7
use rustc_session:: declare_lint_pass;
8
+ use rustc_span:: Span ;
9
+ use rustc_target:: asm:: InlineAsmArch ;
7
10
8
11
#[ derive( Clone , Copy , PartialEq , Eq ) ]
9
12
enum AsmStyle {
@@ -31,8 +34,14 @@ impl std::ops::Not for AsmStyle {
31
34
}
32
35
}
33
36
34
- fn check_expr_asm_syntax ( lint : & ' static Lint , cx : & EarlyContext < ' _ > , expr : & Expr , check_for : AsmStyle ) {
35
- if let ExprKind :: InlineAsm ( ref inline_asm) = expr. kind {
37
+ fn check_asm_syntax (
38
+ lint : & ' static Lint ,
39
+ cx : & EarlyContext < ' _ > ,
40
+ inline_asm : & InlineAsm ,
41
+ span : Span ,
42
+ check_for : AsmStyle ,
43
+ ) {
44
+ if matches ! ( cx. sess( ) . asm_arch, Some ( InlineAsmArch :: X86 | InlineAsmArch :: X86_64 ) ) {
36
45
let style = if inline_asm. options . contains ( InlineAsmOptions :: ATT_SYNTAX ) {
37
46
AsmStyle :: Att
38
47
} else {
@@ -43,7 +52,7 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr
43
52
span_lint_and_help (
44
53
cx,
45
54
lint,
46
- expr . span ,
55
+ span,
47
56
& format ! ( "{style} x86 assembly syntax used" ) ,
48
57
None ,
49
58
& format ! ( "use {} x86 assembly syntax" , !style) ,
@@ -89,7 +98,15 @@ declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]);
89
98
90
99
impl EarlyLintPass for InlineAsmX86IntelSyntax {
91
100
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
92
- check_expr_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, expr, AsmStyle :: Intel ) ;
101
+ if let ExprKind :: InlineAsm ( inline_asm) = & expr. kind {
102
+ check_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, inline_asm, expr. span , AsmStyle :: Intel ) ;
103
+ }
104
+ }
105
+
106
+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
107
+ if let ItemKind :: GlobalAsm ( inline_asm) = & item. kind {
108
+ check_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, inline_asm, item. span , AsmStyle :: Intel ) ;
109
+ }
93
110
}
94
111
}
95
112
@@ -130,6 +147,14 @@ declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]);
130
147
131
148
impl EarlyLintPass for InlineAsmX86AttSyntax {
132
149
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
133
- check_expr_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, expr, AsmStyle :: Att ) ;
150
+ if let ExprKind :: InlineAsm ( inline_asm) = & expr. kind {
151
+ check_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, inline_asm, expr. span , AsmStyle :: Att ) ;
152
+ }
153
+ }
154
+
155
+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
156
+ if let ItemKind :: GlobalAsm ( inline_asm) = & item. kind {
157
+ check_asm_syntax ( Self :: get_lints ( ) [ 0 ] , cx, inline_asm, item. span , AsmStyle :: Att ) ;
158
+ }
134
159
}
135
160
}
0 commit comments