Skip to content

Commit

Permalink
Swap type checked expression
Browse files Browse the repository at this point in the history
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()`)
  • Loading branch information
b-ncMN committed Apr 10, 2022
1 parent a6ab6f4 commit e1830d0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/option_take_on_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use rustc_span::sym;

use super::OPTION_TAKE_ON_TEMPORARY;

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

0 comments on commit e1830d0

Please sign in to comment.