mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
Remove check for #[cfg(test)]
This commit is contained in:
parent
b2856a763e
commit
bd2a5b2322
2 changed files with 5 additions and 33 deletions
|
@ -952,7 +952,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
))
|
||||
});
|
||||
store.register_late_pass(|_| Box::new(lines_filter_map_ok::LinesFilterMapOk));
|
||||
store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule::new()));
|
||||
store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule));
|
||||
// add lints here, do not remove this comment, it's used in `new_lint`
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use clippy_utils::{diagnostics::span_lint_and_note, is_in_cfg_test, is_in_test_function, is_test_module_or_function};
|
||||
use rustc_data_structures::sync::par_for_each_in;
|
||||
use rustc_hir::{intravisit::FnKind, Body, FnDecl, HirId, ItemKind, Mod};
|
||||
use clippy_utils::{diagnostics::span_lint_and_note, is_in_cfg_test, is_in_test_function};
|
||||
use rustc_hir::{intravisit::FnKind, Body, FnDecl};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{def_id::LocalDefId, Span};
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -43,35 +42,9 @@ declare_clippy_lint! {
|
|||
"The test function `my_cool_test` is outside the testing module `tests`."
|
||||
}
|
||||
|
||||
pub(crate) struct TestsOutsideTestModule {
|
||||
pub test_mod_exists: bool,
|
||||
}
|
||||
|
||||
impl TestsOutsideTestModule {
|
||||
pub fn new() -> Self {
|
||||
Self { test_mod_exists: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(TestsOutsideTestModule => [TESTS_OUTSIDE_TEST_MODULE]);
|
||||
declare_lint_pass!(TestsOutsideTestModule => [TESTS_OUTSIDE_TEST_MODULE]);
|
||||
|
||||
impl LateLintPass<'_> for TestsOutsideTestModule {
|
||||
fn check_mod(&mut self, cx: &LateContext<'_>, _: &Mod<'_>, _: HirId) {
|
||||
self.test_mod_exists = false;
|
||||
|
||||
// par_for_each_item uses Fn, while par_for_each_in uses FnMut
|
||||
par_for_each_in(cx.tcx.hir_crate_items(()).items(), |itemid| {
|
||||
let item = cx.tcx.hir().item(itemid);
|
||||
if_chain! {
|
||||
if matches!(item.kind, ItemKind::Mod(_));
|
||||
if is_test_module_or_function(cx.tcx, item);
|
||||
then {
|
||||
self.test_mod_exists = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn check_fn(
|
||||
&mut self,
|
||||
cx: &LateContext<'_>,
|
||||
|
@ -83,7 +56,6 @@ impl LateLintPass<'_> for TestsOutsideTestModule {
|
|||
) {
|
||||
if_chain! {
|
||||
if !matches!(kind, FnKind::Closure);
|
||||
if self.test_mod_exists;
|
||||
if is_in_test_function(cx.tcx, body.id().hir_id);
|
||||
if !is_in_cfg_test(cx.tcx, body.id().hir_id);
|
||||
then {
|
||||
|
|
Loading…
Reference in a new issue