|
1 | 1 | //! Checks validity of naked functions.
|
2 | 2 |
|
3 | 3 | use rustc_hir as hir;
|
4 |
| -use rustc_hir::def::DefKind; |
5 |
| -use rustc_hir::def_id::{LocalDefId, LocalModDefId}; |
| 4 | +use rustc_hir::def_id::LocalDefId; |
6 | 5 | use rustc_hir::intravisit::Visitor;
|
7 | 6 | use rustc_hir::{ExprKind, HirIdSet, StmtKind};
|
8 |
| -use rustc_middle::query::Providers; |
9 | 7 | use rustc_middle::span_bug;
|
10 | 8 | use rustc_middle::ty::TyCtxt;
|
| 9 | +use rustc_middle::util::Providers; |
11 | 10 | use rustc_span::{Span, sym};
|
12 | 11 |
|
13 | 12 | use crate::errors::{
|
14 | 13 | NakedFunctionsAsmBlock, NakedFunctionsMustNakedAsm, NoPatterns, ParamsNotAllowed,
|
15 | 14 | };
|
16 | 15 |
|
17 | 16 | pub(crate) fn provide(providers: &mut Providers) {
|
18 |
| - *providers = Providers { check_mod_naked_functions, ..*providers }; |
| 17 | + providers.hooks.typeck_naked_fn = typeck_naked_fn; |
19 | 18 | }
|
20 | 19 |
|
21 |
| -fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { |
22 |
| - let items = tcx.hir_module_items(module_def_id); |
23 |
| - for def_id in items.definitions() { |
24 |
| - if !matches!(tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn) { |
25 |
| - continue; |
26 |
| - } |
27 |
| - |
28 |
| - let body = match tcx.hir_node_by_def_id(def_id) { |
29 |
| - hir::Node::Item(hir::Item { |
30 |
| - kind: hir::ItemKind::Fn { body: body_id, .. }, .. |
31 |
| - }) |
32 |
| - | hir::Node::TraitItem(hir::TraitItem { |
33 |
| - kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(body_id)), |
34 |
| - .. |
35 |
| - }) |
36 |
| - | hir::Node::ImplItem(hir::ImplItem { |
37 |
| - kind: hir::ImplItemKind::Fn(_, body_id), .. |
38 |
| - }) => tcx.hir_body(*body_id), |
39 |
| - _ => continue, |
40 |
| - }; |
41 |
| - |
42 |
| - if tcx.has_attr(def_id, sym::naked) { |
43 |
| - check_no_patterns(tcx, body.params); |
44 |
| - check_no_parameters_use(tcx, body); |
45 |
| - check_asm(tcx, def_id, body); |
46 |
| - } |
47 |
| - } |
| 20 | +fn typeck_naked_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) { |
| 21 | + debug_assert!(tcx.has_attr(def_id, sym::naked)); |
| 22 | + check_no_patterns(tcx, body.params); |
| 23 | + check_no_parameters_use(tcx, body); |
| 24 | + check_asm(tcx, def_id, body); |
48 | 25 | }
|
49 | 26 |
|
50 | 27 | /// Checks that parameters don't use patterns. Mirrors the checks for function declarations.
|
|
0 commit comments