Skip to content

Commit 8356c48

Browse files
committed
Fix manual_unwrap_or FP deref reference
1 parent b2270e1 commit 8356c48

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clippy_lints/src/manual_unwrap_or.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::{Arm, Expr, ExprKind, PatKind};
1111
use rustc_lint::LintContext;
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_middle::lint::in_external_macro;
14-
use rustc_middle::ty::adjustment::Adjust;
1514
use rustc_session::{declare_lint_pass, declare_tool_lint};
1615
use rustc_span::sym;
1716

@@ -72,9 +71,8 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
7271
if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
7372
if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind;
7473
if path_to_local_id(unwrap_arm.body, binding_hir_id);
74+
if cx.typeck_results().expr_adjustments(unwrap_arm.body).is_empty();
7575
if !contains_return_break_continue_macro(or_arm.body);
76-
if !cx.typeck_results().expr_adjustments(unwrap_arm.body).iter()
77-
.any(|a| matches!(a.kind, Adjust::Deref(Some(..))));
7876
then {
7977
Some(or_arm)
8078
} else {

tests/ui/manual_unwrap_or.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,11 @@ fn format_name(name: Option<&Rc<str>>) -> &str {
171171
}
172172
}
173173

174+
fn implicit_deref_ref() {
175+
let _: &str = match Some(&"bye") {
176+
None => "hi",
177+
Some(s) => s,
178+
};
179+
}
180+
174181
fn main() {}

tests/ui/manual_unwrap_or.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,11 @@ fn format_name(name: Option<&Rc<str>>) -> &str {
213213
}
214214
}
215215

216+
fn implicit_deref_ref() {
217+
let _: &str = match Some(&"bye") {
218+
None => "hi",
219+
Some(s) => s,
220+
};
221+
}
222+
216223
fn main() {}

0 commit comments

Comments
 (0)