11//! Checks validity of naked functions.
22
3- use rustc_abi:: ExternAbi ;
43use rustc_hir as hir;
54use rustc_hir:: def:: DefKind ;
65use rustc_hir:: def_id:: { LocalDefId , LocalModDefId } ;
@@ -10,12 +9,11 @@ use rustc_middle::hir::nested_filter::OnlyBodies;
109use rustc_middle:: query:: Providers ;
1110use rustc_middle:: span_bug;
1211use rustc_middle:: ty:: TyCtxt ;
13- use rustc_session:: lint:: builtin:: UNDEFINED_NAKED_FUNCTION_ABI ;
1412use rustc_span:: { Span , sym} ;
1513
1614use crate :: errors:: {
1715 NakedAsmOutsideNakedFn , NakedFunctionsAsmBlock , NakedFunctionsMustNakedAsm , NoPatterns ,
18- ParamsNotAllowed , UndefinedNakedFunctionAbi ,
16+ ParamsNotAllowed ,
1917} ;
2018
2119pub ( crate ) fn provide ( providers : & mut Providers ) {
@@ -29,26 +27,21 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
2927 continue ;
3028 }
3129
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) {
3331 hir:: Node :: Item ( hir:: Item {
34- kind : hir:: ItemKind :: Fn { sig, body : body_id, .. } ,
35- ..
32+ kind : hir:: ItemKind :: Fn { body : body_id, .. } , ..
3633 } )
3734 | 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) ) ,
3936 ..
4037 } )
4138 | 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) ,
4541 _ => continue ,
4642 } ;
4743
48- let body = tcx. hir_body ( body_id) ;
49-
5044 if tcx. has_attr ( def_id, sym:: naked) {
51- check_abi ( tcx, def_id, fn_header. abi ) ;
5245 check_no_patterns ( tcx, body. params ) ;
5346 check_no_parameters_use ( tcx, body) ;
5447 check_asm ( tcx, def_id, body) ;
@@ -60,20 +53,6 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
6053 }
6154}
6255
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-
7756/// Checks that parameters don't use patterns. Mirrors the checks for function declarations.
7857fn check_no_patterns ( tcx : TyCtxt < ' _ > , params : & [ hir:: Param < ' _ > ] ) {
7958 for param in params {
0 commit comments