Skip to content

Commit

Permalink
Auto merge of #7233 - giraffate:fix_manual_unwrap_or_fp_with_deref_co…
Browse files Browse the repository at this point in the history
…ercion, r=flip1995

Fix a `manual_unwrap_or` FP with deref coercion

Fix #7228.

changelog: Fix a [`manual_unwrap_or`] FP with deref coercion
  • Loading branch information
bors committed May 17, 2021
2 parents acdf43f + ebf065e commit 664eb85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clippy_lints/src/manual_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_hir::{Arm, Expr, ExprKind, PatKind};
use rustc_lint::LintContext;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::adjustment::Adjust;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;

Expand Down Expand Up @@ -87,6 +88,8 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind;
if path_to_local_id(unwrap_arm.body, binding_hir_id);
if !contains_return_break_continue_macro(or_arm.body);
if !cx.typeck_results().expr_adjustments(unwrap_arm.body).iter()
.any(|a| matches!(a.kind, Adjust::Deref(Some(..))));
then {
Some(or_arm)
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/manual_unwrap_or.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,12 @@ mod issue6965 {
}
}

use std::rc::Rc;
fn format_name(name: Option<&Rc<str>>) -> &str {
match name {
None => "<anon>",
Some(name) => name,
}
}

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/manual_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ mod issue6965 {
}
}

use std::rc::Rc;
fn format_name(name: Option<&Rc<str>>) -> &str {
match name {
None => "<anon>",
Some(name) => name,
}
}

fn main() {}

0 comments on commit 664eb85

Please sign in to comment.