diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2021-05-17 14:20:26 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2021-05-17 14:20:26 -0500 |
| commit | 8356c485a99890339022a7afd99fc13ae09e5805 (patch) | |
| tree | 55cd37161d7d1607dcb0ca62c621497d7d86c9f3 | |
| parent | b2270e1f459cbeb1b6f4281d230990a40fe993d8 (diff) | |
| download | rust-8356c485a99890339022a7afd99fc13ae09e5805.tar.gz rust-8356c485a99890339022a7afd99fc13ae09e5805.zip | |
Fix manual_unwrap_or FP deref reference
| -rw-r--r-- | clippy_lints/src/manual_unwrap_or.rs | 4 | ||||
| -rw-r--r-- | tests/ui/manual_unwrap_or.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/manual_unwrap_or.rs | 7 |
3 files changed, 15 insertions, 3 deletions
diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index d7e8d180f7e..2f579edd6ad 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -11,7 +11,6 @@ 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; @@ -72,9 +71,8 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk); if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; if path_to_local_id(unwrap_arm.body, binding_hir_id); + if cx.typeck_results().expr_adjustments(unwrap_arm.body).is_empty(); 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 { diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 1efecb0ba12..3717f962745 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -171,4 +171,11 @@ fn format_name(name: Option<&Rc<str>>) -> &str { } } +fn implicit_deref_ref() { + let _: &str = match Some(&"bye") { + None => "hi", + Some(s) => s, + }; +} + fn main() {} diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 95d585ad18a..989adde1f5b 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -213,4 +213,11 @@ fn format_name(name: Option<&Rc<str>>) -> &str { } } +fn implicit_deref_ref() { + let _: &str = match Some(&"bye") { + None => "hi", + Some(s) => s, + }; +} + fn main() {} |
