1
1
//! Checks validity of naked functions.
2
2
3
- use rustc_abi:: ExternAbi ;
4
3
use rustc_hir as hir;
5
4
use rustc_hir:: def:: DefKind ;
6
5
use rustc_hir:: def_id:: { LocalDefId , LocalModDefId } ;
@@ -10,12 +9,11 @@ use rustc_middle::hir::nested_filter::OnlyBodies;
10
9
use rustc_middle:: query:: Providers ;
11
10
use rustc_middle:: span_bug;
12
11
use rustc_middle:: ty:: TyCtxt ;
13
- use rustc_session:: lint:: builtin:: UNDEFINED_NAKED_FUNCTION_ABI ;
14
12
use rustc_span:: { Span , sym} ;
15
13
16
14
use crate :: errors:: {
17
15
NakedAsmOutsideNakedFn , NakedFunctionsAsmBlock , NakedFunctionsMustNakedAsm , NoPatterns ,
18
- ParamsNotAllowed , UndefinedNakedFunctionAbi ,
16
+ ParamsNotAllowed ,
19
17
} ;
20
18
21
19
pub ( crate ) fn provide ( providers : & mut Providers ) {
@@ -29,26 +27,21 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
29
27
continue ;
30
28
}
31
29
32
- let ( fn_header , body_id ) = match tcx. hir_node_by_def_id ( def_id) {
30
+ let body = match tcx. hir_node_by_def_id ( def_id) {
33
31
hir:: Node :: Item ( hir:: Item {
34
- kind : hir:: ItemKind :: Fn { sig, body : body_id, .. } ,
35
- ..
32
+ kind : hir:: ItemKind :: Fn { body : body_id, .. } , ..
36
33
} )
37
34
| hir:: Node :: TraitItem ( hir:: TraitItem {
38
- kind : hir:: TraitItemKind :: Fn ( sig , hir:: TraitFn :: Provided ( body_id) ) ,
35
+ kind : hir:: TraitItemKind :: Fn ( _ , hir:: TraitFn :: Provided ( body_id) ) ,
39
36
..
40
37
} )
41
38
| hir:: Node :: ImplItem ( hir:: ImplItem {
42
- kind : hir:: ImplItemKind :: Fn ( sig, body_id) ,
43
- ..
44
- } ) => ( sig. header , * body_id) ,
39
+ kind : hir:: ImplItemKind :: Fn ( _, body_id) , ..
40
+ } ) => tcx. hir_body ( * body_id) ,
45
41
_ => continue ,
46
42
} ;
47
43
48
- let body = tcx. hir_body ( body_id) ;
49
-
50
44
if tcx. has_attr ( def_id, sym:: naked) {
51
- check_abi ( tcx, def_id, fn_header. abi ) ;
52
45
check_no_patterns ( tcx, body. params ) ;
53
46
check_no_parameters_use ( tcx, body) ;
54
47
check_asm ( tcx, def_id, body) ;
@@ -60,20 +53,6 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
60
53
}
61
54
}
62
55
63
- /// Checks that function uses non-Rust ABI.
64
- fn check_abi ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , abi : ExternAbi ) {
65
- if abi == ExternAbi :: Rust {
66
- let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
67
- let span = tcx. def_span ( def_id) ;
68
- tcx. emit_node_span_lint (
69
- UNDEFINED_NAKED_FUNCTION_ABI ,
70
- hir_id,
71
- span,
72
- UndefinedNakedFunctionAbi ,
73
- ) ;
74
- }
75
- }
76
-
77
56
/// Checks that parameters don't use patterns. Mirrors the checks for function declarations.
78
57
fn check_no_patterns ( tcx : TyCtxt < ' _ > , params : & [ hir:: Param < ' _ > ] ) {
79
58
for param in params {
0 commit comments