Skip to content

Commit 685d1c9

Browse files
committed
Change a per-module query to just run on the items it internally filters for
1 parent 7f50020 commit 685d1c9

File tree

6 files changed

+19
-38
lines changed

6 files changed

+19
-38
lines changed

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use rustc_middle::query::Providers;
5555
use rustc_middle::ty::{self, Ty, TyCtxt};
5656
use rustc_middle::{bug, span_bug};
5757
use rustc_session::config;
58-
use rustc_span::Span;
5958
use rustc_span::def_id::LocalDefId;
59+
use rustc_span::{Span, sym};
6060
use tracing::{debug, instrument};
6161
use typeck_root_ctxt::TypeckRootCtxt;
6262

@@ -170,6 +170,10 @@ fn typeck_with_inspect<'tcx>(
170170
.map(|(idx, ty)| fcx.normalize(arg_span(idx), ty)),
171171
);
172172

173+
if tcx.has_attr(def_id, sym::naked) {
174+
tcx.typeck_naked_fn(def_id, body);
175+
}
176+
173177
check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params());
174178
} else {
175179
let expected_type = if let Some(infer_ty) = infer_type_if_missing(&fcx, node) {

compiler/rustc_interface/src/passes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
960960
tcx.par_hir_for_each_module(|module| {
961961
tcx.ensure_ok().check_mod_loops(module);
962962
tcx.ensure_ok().check_mod_attrs(module);
963-
tcx.ensure_ok().check_mod_naked_functions(module);
964963
tcx.ensure_ok().check_mod_unstable_api_usage(module);
965964
});
966965
},

compiler/rustc_middle/src/hooks/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ declare_hooks! {
102102
/// Ensure the given scalar is valid for the given type.
103103
/// This checks non-recursive runtime validity.
104104
hook validate_scalar_in_layout(scalar: crate::ty::ScalarInt, ty: Ty<'tcx>) -> bool;
105+
106+
/// Naked fns can only have trivial binding patterns in arguments,
107+
/// may not actually use those arguments, and the body must consist of just
108+
/// a single asm statement.
109+
hook typeck_naked_fn(def_id: LocalDefId, body: &'tcx rustc_hir::Body<'tcx>) -> ();
105110
}
106111

107112
#[cold]

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,10 +1119,6 @@ rustc_queries! {
11191119
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
11201120
}
11211121

1122-
query check_mod_naked_functions(key: LocalModDefId) {
1123-
desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
1124-
}
1125-
11261122
query check_mod_privacy(key: LocalModDefId) {
11271123
desc { |tcx| "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) }
11281124
}

compiler/rustc_passes/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(try_blocks)]
1515
// tidy-alphabetical-end
1616

17-
use rustc_middle::query::Providers;
17+
use rustc_middle::util::Providers;
1818

1919
pub mod abi_test;
2020
mod check_attr;

compiler/rustc_passes/src/naked_functions.rs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,27 @@
11
//! Checks validity of naked functions.
22
33
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;
65
use rustc_hir::intravisit::Visitor;
76
use rustc_hir::{ExprKind, HirIdSet, StmtKind};
8-
use rustc_middle::query::Providers;
97
use rustc_middle::span_bug;
108
use rustc_middle::ty::TyCtxt;
9+
use rustc_middle::util::Providers;
1110
use rustc_span::{Span, sym};
1211

1312
use crate::errors::{
1413
NakedFunctionsAsmBlock, NakedFunctionsMustNakedAsm, NoPatterns, ParamsNotAllowed,
1514
};
1615

1716
pub(crate) fn provide(providers: &mut Providers) {
18-
*providers = Providers { check_mod_naked_functions, ..*providers };
17+
providers.hooks.typeck_naked_fn = typeck_naked_fn;
1918
}
2019

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);
4825
}
4926

5027
/// Checks that parameters don't use patterns. Mirrors the checks for function declarations.

0 commit comments

Comments
 (0)