1
1
//! Checks validity of naked functions.
2
2
3
- use rustc_ast:: InlineAsmOptions ;
4
3
use rustc_hir as hir;
5
4
use rustc_hir:: def:: DefKind ;
6
5
use rustc_hir:: def_id:: { LocalDefId , LocalModDefId } ;
7
6
use rustc_hir:: intravisit:: Visitor ;
8
- use rustc_hir:: { ExprKind , HirIdSet , InlineAsmOperand , StmtKind } ;
7
+ use rustc_hir:: { ExprKind , HirIdSet , StmtKind } ;
9
8
use rustc_middle:: query:: Providers ;
10
9
use rustc_middle:: ty:: TyCtxt ;
11
10
use rustc_session:: lint:: builtin:: UNDEFINED_NAKED_FUNCTION_ABI ;
@@ -14,8 +13,8 @@ use rustc_span::{BytePos, Span};
14
13
use rustc_target:: spec:: abi:: Abi ;
15
14
16
15
use crate :: errors:: {
17
- NakedFunctionsAsmBlock , NakedFunctionsAsmOptions , NakedFunctionsMustNakedAsm ,
18
- NakedFunctionsOperands , NoPatterns , ParamsNotAllowed , UndefinedNakedFunctionAbi ,
16
+ NakedFunctionsAsmBlock , NakedFunctionsMustNakedAsm , NoPatterns , ParamsNotAllowed ,
17
+ UndefinedNakedFunctionAbi ,
19
18
} ;
20
19
21
20
pub ( crate ) fn provide ( providers : & mut Providers ) {
@@ -114,7 +113,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
114
113
115
114
/// Checks that function body contains a single inline assembly block.
116
115
fn check_asm < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , body : & ' tcx hir:: Body < ' tcx > ) {
117
- let mut this = CheckInlineAssembly { tcx , items : Vec :: new ( ) } ;
116
+ let mut this = CheckInlineAssembly { items : Vec :: new ( ) } ;
118
117
this. visit_body ( body) ;
119
118
if let [ ( ItemKind :: NakedAsm | ItemKind :: Err , _) ] = this. items [ ..] {
120
119
// Ok.
@@ -160,8 +159,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
160
159
}
161
160
}
162
161
163
- struct CheckInlineAssembly < ' tcx > {
164
- tcx : TyCtxt < ' tcx > ,
162
+ struct CheckInlineAssembly {
165
163
items : Vec < ( ItemKind , Span ) > ,
166
164
}
167
165
@@ -173,8 +171,8 @@ enum ItemKind {
173
171
Err ,
174
172
}
175
173
176
- impl < ' tcx > CheckInlineAssembly < ' tcx > {
177
- fn check_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > , span : Span ) {
174
+ impl CheckInlineAssembly {
175
+ fn check_expr < ' tcx > ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > , span : Span ) {
178
176
match expr. kind {
179
177
ExprKind :: ConstBlock ( ..)
180
178
| ExprKind :: Array ( ..)
@@ -215,7 +213,6 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
215
213
}
216
214
rustc_ast:: AsmMacro :: NakedAsm => {
217
215
self . items . push ( ( ItemKind :: NakedAsm , span) ) ;
218
- self . check_inline_asm ( asm, span) ;
219
216
}
220
217
rustc_ast:: AsmMacro :: GlobalAsm => {
221
218
// not allowed in this position
@@ -232,42 +229,9 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
232
229
}
233
230
}
234
231
}
235
-
236
- fn check_inline_asm ( & self , asm : & ' tcx hir:: InlineAsm < ' tcx > , span : Span ) {
237
- let unsupported_operands: Vec < Span > = asm
238
- . operands
239
- . iter ( )
240
- . filter_map ( |& ( ref op, op_sp) | match op {
241
- InlineAsmOperand :: Const { .. }
242
- | InlineAsmOperand :: SymFn { .. }
243
- | InlineAsmOperand :: SymStatic { .. } => None ,
244
- InlineAsmOperand :: In { .. }
245
- | InlineAsmOperand :: Out { .. }
246
- | InlineAsmOperand :: InOut { .. }
247
- | InlineAsmOperand :: SplitInOut { .. }
248
- | InlineAsmOperand :: Label { .. } => Some ( op_sp) ,
249
- } )
250
- . collect ( ) ;
251
- if !unsupported_operands. is_empty ( ) {
252
- self . tcx . dcx ( ) . emit_err ( NakedFunctionsOperands { unsupported_operands } ) ;
253
- }
254
-
255
- let unsupported_options = asm. options . difference ( InlineAsmOptions :: NAKED_OPTIONS ) ;
256
- if !unsupported_options. is_empty ( ) {
257
- self . tcx . dcx ( ) . emit_err ( NakedFunctionsAsmOptions {
258
- span,
259
- unsupported_options : unsupported_options
260
- . human_readable_names ( )
261
- . into_iter ( )
262
- . map ( |name| format ! ( "`{name}`" ) )
263
- . collect :: < Vec < _ > > ( )
264
- . join ( ", " ) ,
265
- } ) ;
266
- }
267
- }
268
232
}
269
233
270
- impl < ' tcx > Visitor < ' tcx > for CheckInlineAssembly < ' tcx > {
234
+ impl < ' tcx > Visitor < ' tcx > for CheckInlineAssembly {
271
235
fn visit_stmt ( & mut self , stmt : & ' tcx hir:: Stmt < ' tcx > ) {
272
236
match stmt. kind {
273
237
StmtKind :: Item ( ..) => { }
0 commit comments