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:: hir:: nested_filter:: OnlyBodies ;
10
9
use rustc_middle:: query:: Providers ;
11
10
use rustc_middle:: ty:: TyCtxt ;
@@ -15,9 +14,8 @@ use rustc_span::{BytePos, Span};
15
14
use rustc_target:: spec:: abi:: Abi ;
16
15
17
16
use crate :: errors:: {
18
- NakedAsmOutsideNakedFn , NakedFunctionsAsmBlock , NakedFunctionsAsmOptions ,
19
- NakedFunctionsMustNakedAsm , NakedFunctionsOperands , NoPatterns , ParamsNotAllowed ,
20
- UndefinedNakedFunctionAbi ,
17
+ NakedAsmOutsideNakedFn , NakedFunctionsAsmBlock , NakedFunctionsMustNakedAsm , NoPatterns ,
18
+ ParamsNotAllowed , UndefinedNakedFunctionAbi ,
21
19
} ;
22
20
23
21
pub ( crate ) fn provide ( providers : & mut Providers ) {
@@ -119,7 +117,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
119
117
120
118
/// Checks that function body contains a single inline assembly block.
121
119
fn check_asm < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , body : & ' tcx hir:: Body < ' tcx > ) {
122
- let mut this = CheckInlineAssembly { tcx , items : Vec :: new ( ) } ;
120
+ let mut this = CheckInlineAssembly { items : Vec :: new ( ) } ;
123
121
this. visit_body ( body) ;
124
122
if let [ ( ItemKind :: NakedAsm | ItemKind :: Err , _) ] = this. items [ ..] {
125
123
// Ok.
@@ -165,8 +163,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
165
163
}
166
164
}
167
165
168
- struct CheckInlineAssembly < ' tcx > {
169
- tcx : TyCtxt < ' tcx > ,
166
+ struct CheckInlineAssembly {
170
167
items : Vec < ( ItemKind , Span ) > ,
171
168
}
172
169
@@ -178,8 +175,8 @@ enum ItemKind {
178
175
Err ,
179
176
}
180
177
181
- impl < ' tcx > CheckInlineAssembly < ' tcx > {
182
- fn check_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > , span : Span ) {
178
+ impl CheckInlineAssembly {
179
+ fn check_expr < ' tcx > ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > , span : Span ) {
183
180
match expr. kind {
184
181
ExprKind :: ConstBlock ( ..)
185
182
| ExprKind :: Array ( ..)
@@ -220,7 +217,6 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
220
217
}
221
218
rustc_ast:: AsmMacro :: NakedAsm => {
222
219
self . items . push ( ( ItemKind :: NakedAsm , span) ) ;
223
- self . check_inline_asm ( asm, span) ;
224
220
}
225
221
rustc_ast:: AsmMacro :: GlobalAsm => {
226
222
// not allowed in this position
@@ -237,42 +233,9 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
237
233
}
238
234
}
239
235
}
240
-
241
- fn check_inline_asm ( & self , asm : & ' tcx hir:: InlineAsm < ' tcx > , span : Span ) {
242
- let unsupported_operands: Vec < Span > = asm
243
- . operands
244
- . iter ( )
245
- . filter_map ( |& ( ref op, op_sp) | match op {
246
- InlineAsmOperand :: Const { .. }
247
- | InlineAsmOperand :: SymFn { .. }
248
- | InlineAsmOperand :: SymStatic { .. } => None ,
249
- InlineAsmOperand :: In { .. }
250
- | InlineAsmOperand :: Out { .. }
251
- | InlineAsmOperand :: InOut { .. }
252
- | InlineAsmOperand :: SplitInOut { .. }
253
- | InlineAsmOperand :: Label { .. } => Some ( op_sp) ,
254
- } )
255
- . collect ( ) ;
256
- if !unsupported_operands. is_empty ( ) {
257
- self . tcx . dcx ( ) . emit_err ( NakedFunctionsOperands { unsupported_operands } ) ;
258
- }
259
-
260
- let unsupported_options = asm. options . difference ( InlineAsmOptions :: NAKED_OPTIONS ) ;
261
- if !unsupported_options. is_empty ( ) {
262
- self . tcx . dcx ( ) . emit_err ( NakedFunctionsAsmOptions {
263
- span,
264
- unsupported_options : unsupported_options
265
- . human_readable_names ( )
266
- . into_iter ( )
267
- . map ( |name| format ! ( "`{name}`" ) )
268
- . collect :: < Vec < _ > > ( )
269
- . join ( ", " ) ,
270
- } ) ;
271
- }
272
- }
273
236
}
274
237
275
- impl < ' tcx > Visitor < ' tcx > for CheckInlineAssembly < ' tcx > {
238
+ impl < ' tcx > Visitor < ' tcx > for CheckInlineAssembly {
276
239
fn visit_stmt ( & mut self , stmt : & ' tcx hir:: Stmt < ' tcx > ) {
277
240
match stmt. kind {
278
241
StmtKind :: Item ( ..) => { }
0 commit comments