Skip to content

Commit 72e773f

Browse files
committed
Fix test function checker in [unwrap_used], [expect_used]
1 parent 8d08917 commit 72e773f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clippy_lints/src/methods/expect_used.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::is_in_cfg_test;
2+
use clippy_utils::{is_in_cfg_test, is_in_test_function};
33
use clippy_utils::ty::is_type_diagnostic_item;
44
use rustc_hir as hir;
55
use rustc_lint::LateContext;
@@ -27,7 +27,7 @@ pub(super) fn check(
2727

2828
let method = if is_err { "expect_err" } else { "expect" };
2929

30-
if allow_expect_in_tests && is_in_cfg_test(cx.tcx, expr.hir_id) {
30+
if allow_expect_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) {
3131
return;
3232
}
3333

clippy_lints/src/methods/unwrap_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_help;
22
use clippy_utils::ty::is_type_diagnostic_item;
3-
use clippy_utils::{is_in_cfg_test, is_lint_allowed};
3+
use clippy_utils::{is_in_cfg_test, is_in_test_function, is_lint_allowed};
44
use rustc_hir as hir;
55
use rustc_lint::LateContext;
66
use rustc_span::sym;
@@ -27,7 +27,7 @@ pub(super) fn check(
2727

2828
let method_suffix = if is_err { "_err" } else { "" };
2929

30-
if allow_unwrap_in_tests && is_in_cfg_test(cx.tcx, expr.hir_id) {
30+
if allow_unwrap_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) {
3131
return;
3232
}
3333

0 commit comments

Comments
 (0)