mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
Auto merge of #7233 - giraffate:fix_manual_unwrap_or_fp_with_deref_coercion, r=flip1995
Fix a `manual_unwrap_or` FP with deref coercion Fix https://github.com/rust-lang/rust-clippy/issues/7228. changelog: Fix a [`manual_unwrap_or`] FP with deref coercion
This commit is contained in:
commit
cec8d95729
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
@ -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() {}
|
||||
|
@ -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() {}
|
||||
|
Loading…
Reference in New Issue
Block a user