Skip to content

Commit e1830d0

Browse files
committed
Swap type checked expression
Instead of type checking the entire expression (causing a false positive), only type check for a subset of the expression (the receiver of the matched function: `take()`)
1 parent a6ab6f4 commit e1830d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

clippy_lints/src/methods/option_take_on_temporary.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use rustc_span::sym;
88

99
use super::OPTION_TAKE_ON_TEMPORARY;
1010

11-
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
11+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, _expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
1212
// Checks if expression type is equal to sym::Option and if the expr is not a syntactic place
13-
if is_expr_option(cx, expr) && !expr.is_syntactic_place_expr() {
13+
if is_expr_option(cx, recv) && !recv.is_syntactic_place_expr() {
1414
let mut applicability = Applicability::MachineApplicable;
1515
span_lint_and_sugg(
1616
cx,
1717
OPTION_TAKE_ON_TEMPORARY,
18-
expr.span,
18+
recv.span,
1919
"Called `Option::take()` on a temporary value",
2020
"try",
2121
format!(

0 commit comments

Comments
 (0)