Skip to content

Commit 6d61bda

Browse files
committed
Use is_in_test in more places.
1 parent 4c44b4e commit 6d61bda

File tree

6 files changed

+12
-23
lines changed

6 files changed

+12
-23
lines changed

clippy_lints/src/functions/impl_trait_in_params.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::is_in_test_function;
2+
use clippy_utils::is_in_test;
33

44
use rustc_hir as hir;
55
use rustc_hir::intravisit::FnKind;
@@ -41,7 +41,7 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_
4141
pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: &'tcx Body<'_>, hir_id: HirId) {
4242
if let FnKind::ItemFn(_, generics, _) = kind
4343
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
44-
&& !is_in_test_function(cx.tcx, hir_id)
44+
&& !is_in_test(cx.tcx, hir_id)
4545
{
4646
for param in generics.params {
4747
if param.is_impl_trait() {
@@ -59,7 +59,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
5959
&& of_trait.is_none()
6060
&& let body = cx.tcx.hir().body(body_id)
6161
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
62-
&& !is_in_test_function(cx.tcx, impl_item.hir_id())
62+
&& !is_in_test(cx.tcx, impl_item.hir_id())
6363
{
6464
for param in impl_item.generics.params {
6565
if param.is_impl_trait() {
@@ -75,7 +75,7 @@ pub(super) fn check_trait_item(cx: &LateContext<'_>, trait_item: &TraitItem<'_>,
7575
&& let hir::Node::Item(item) = cx.tcx.parent_hir_node(trait_item.hir_id())
7676
// ^^ (Will always be a trait)
7777
&& !item.vis_span.is_empty() // Is public
78-
&& !is_in_test_function(cx.tcx, trait_item.hir_id())
78+
&& !is_in_test(cx.tcx, trait_item.hir_id())
7979
{
8080
for param in trait_item.generics.params {
8181
if param.is_impl_trait() {

clippy_lints/src/incompatible_msrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::msrvs::Msrv;
22
use clippy_utils::diagnostics::span_lint;
3-
use clippy_utils::is_in_test_function;
3+
use clippy_utils::is_in_test;
44
use rustc_attr::{StabilityLevel, StableSince};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_hir::{Expr, ExprKind, HirId};
@@ -88,7 +88,7 @@ impl IncompatibleMsrv {
8888
return;
8989
}
9090
let version = self.get_def_id_version(cx.tcx, def_id);
91-
if self.msrv.meets(version) || is_in_test_function(cx.tcx, node) {
91+
if self.msrv.meets(version) || is_in_test(cx.tcx, node) {
9292
return;
9393
}
9494
if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind {

clippy_lints/src/methods/unwrap_expect_used.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::ty::{is_never_like, is_type_diagnostic_item};
3-
use clippy_utils::{is_in_cfg_test, is_in_test_function, is_lint_allowed};
3+
use clippy_utils::{is_in_test, is_lint_allowed};
44
use rustc_hir::Expr;
55
use rustc_lint::{LateContext, Lint};
66
use rustc_middle::ty;
@@ -61,7 +61,7 @@ pub(super) fn check(
6161

6262
let method_suffix = if is_err { "_err" } else { "" };
6363

64-
if allow_unwrap_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) {
64+
if allow_unwrap_in_tests && is_in_test(cx.tcx, expr.hir_id) {
6565
return;
6666
}
6767

clippy_lints/src/missing_assert_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::is_in_test;
23
use clippy_utils::macros::{find_assert_args, find_assert_eq_args, root_macro_call_first_node, PanicExpn};
3-
use clippy_utils::{is_in_cfg_test, is_in_test_function};
44
use rustc_hir::Expr;
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingAssertMessage {
6262
};
6363

6464
// This lint would be very noisy in tests, so just ignore if we're in test context
65-
if is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id) {
65+
if is_in_test(cx.tcx, expr.hir_id) {
6666
return;
6767
}
6868

clippy_lints/src/write.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
2+
use clippy_utils::is_in_test;
23
use clippy_utils::macros::{format_arg_removal_span, root_macro_call_first_node, FormatArgsStorage, MacroCall};
34
use clippy_utils::source::{expand_past_previous_comma, snippet_opt};
4-
use clippy_utils::{is_in_cfg_test, is_in_test_function};
55
use rustc_ast::token::LitKind;
66
use rustc_ast::{
77
FormatArgPosition, FormatArgPositionKind, FormatArgs, FormatArgsPiece, FormatOptions, FormatPlaceholder,
@@ -297,8 +297,7 @@ impl<'tcx> LateLintPass<'tcx> for Write {
297297
.as_ref()
298298
.map_or(false, |crate_name| crate_name == "build_script_build");
299299

300-
let allowed_in_tests = self.allow_print_in_tests
301-
&& (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id));
300+
let allowed_in_tests = self.allow_print_in_tests && is_in_test(cx.tcx, expr.hir_id);
302301
match diag_name {
303302
sym::print_macro | sym::println_macro if !allowed_in_tests => {
304303
if !is_build_script {

clippy_utils/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,16 +2625,6 @@ pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
26252625
.any(|attr| attr.has_name(sym::cfg))
26262626
}
26272627

2628-
/// Checks whether item either has `test` attribute applied, or
2629-
/// is a module with `test` in its name.
2630-
///
2631-
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
2632-
pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
2633-
is_in_test_function(tcx, item.hir_id())
2634-
|| matches!(item.kind, ItemKind::Mod(..))
2635-
&& item.ident.name.as_str().split('_').any(|a| a == "test" || a == "tests")
2636-
}
2637-
26382628
/// Walks up the HIR tree from the given expression in an attempt to find where the value is
26392629
/// consumed.
26402630
///

0 commit comments

Comments
 (0)