Skip to content

Commit bd2a5b2

Browse files
committed
Remove check for #[cfg(test)]
1 parent b2856a7 commit bd2a5b2

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
952952
))
953953
});
954954
store.register_late_pass(|_| Box::new(lines_filter_map_ok::LinesFilterMapOk));
955-
store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule::new()));
955+
store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule));
956956
// add lints here, do not remove this comment, it's used in `new_lint`
957957
}
958958

clippy_lints/src/tests_outside_test_module.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use clippy_utils::{diagnostics::span_lint_and_note, is_in_cfg_test, is_in_test_function, is_test_module_or_function};
2-
use rustc_data_structures::sync::par_for_each_in;
3-
use rustc_hir::{intravisit::FnKind, Body, FnDecl, HirId, ItemKind, Mod};
1+
use clippy_utils::{diagnostics::span_lint_and_note, is_in_cfg_test, is_in_test_function};
2+
use rustc_hir::{intravisit::FnKind, Body, FnDecl};
43
use rustc_lint::{LateContext, LateLintPass};
5-
use rustc_session::{declare_tool_lint, impl_lint_pass};
4+
use rustc_session::{declare_lint_pass, declare_tool_lint};
65
use rustc_span::{def_id::LocalDefId, Span};
76

87
declare_clippy_lint! {
@@ -43,35 +42,9 @@ declare_clippy_lint! {
4342
"The test function `my_cool_test` is outside the testing module `tests`."
4443
}
4544

46-
pub(crate) struct TestsOutsideTestModule {
47-
pub test_mod_exists: bool,
48-
}
49-
50-
impl TestsOutsideTestModule {
51-
pub fn new() -> Self {
52-
Self { test_mod_exists: false }
53-
}
54-
}
55-
56-
impl_lint_pass!(TestsOutsideTestModule => [TESTS_OUTSIDE_TEST_MODULE]);
45+
declare_lint_pass!(TestsOutsideTestModule => [TESTS_OUTSIDE_TEST_MODULE]);
5746

5847
impl LateLintPass<'_> for TestsOutsideTestModule {
59-
fn check_mod(&mut self, cx: &LateContext<'_>, _: &Mod<'_>, _: HirId) {
60-
self.test_mod_exists = false;
61-
62-
// par_for_each_item uses Fn, while par_for_each_in uses FnMut
63-
par_for_each_in(cx.tcx.hir_crate_items(()).items(), |itemid| {
64-
let item = cx.tcx.hir().item(itemid);
65-
if_chain! {
66-
if matches!(item.kind, ItemKind::Mod(_));
67-
if is_test_module_or_function(cx.tcx, item);
68-
then {
69-
self.test_mod_exists = true;
70-
}
71-
}
72-
});
73-
}
74-
7548
fn check_fn(
7649
&mut self,
7750
cx: &LateContext<'_>,
@@ -83,7 +56,6 @@ impl LateLintPass<'_> for TestsOutsideTestModule {
8356
) {
8457
if_chain! {
8558
if !matches!(kind, FnKind::Closure);
86-
if self.test_mod_exists;
8759
if is_in_test_function(cx.tcx, body.id().hir_id);
8860
if !is_in_cfg_test(cx.tcx, body.id().hir_id);
8961
then {

0 commit comments

Comments
 (0)