Skip to content

Commit e2d9b9a

Browse files
authored
fix: needless_option_as_deref FP in trait (#14210)
fixes #14148 Another case of #13077 and #8646 changelog: [`needless_option_as_deref`]: fix FP in trait
2 parents 437014b + c47746c commit e2d9b9a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clippy_utils/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use rustc_hir::{
107107
self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext,
108108
Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind,
109109
ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode, Param, Pat,
110-
PatExpr, PatExprKind, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind,
110+
PatExpr, PatExprKind, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitFn, TraitItem, TraitItemKind,
111111
TraitItemRef, TraitRef, TyKind, UnOp, def,
112112
};
113113
use rustc_lexer::{TokenKind, tokenize};
@@ -1505,6 +1505,10 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
15051505
| Node::ImplItem(&ImplItem {
15061506
kind: ImplItemKind::Fn(_, eid),
15071507
..
1508+
})
1509+
| Node::TraitItem(&TraitItem {
1510+
kind: TraitItemKind::Fn(_, TraitFn::Provided(eid)),
1511+
..
15081512
}) => match cx.tcx.hir().body(eid).value.kind {
15091513
ExprKind::Block(block, _) => Some(block),
15101514
_ => None,

tests/ui/needless_option_as_deref.fixed

+13
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ mod issue_non_copy_13077 {
7373
pub field: (),
7474
}
7575
}
76+
77+
mod issue14148 {
78+
pub trait SomeTrait {
79+
fn something(&self, mut maybe_side_effect: Option<&mut String>) {
80+
other(maybe_side_effect.as_deref_mut());
81+
other(maybe_side_effect);
82+
}
83+
}
84+
85+
fn other(_maybe_side_effect: Option<&mut String>) {
86+
unimplemented!()
87+
}
88+
}

tests/ui/needless_option_as_deref.rs

+13
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ mod issue_non_copy_13077 {
7373
pub field: (),
7474
}
7575
}
76+
77+
mod issue14148 {
78+
pub trait SomeTrait {
79+
fn something(&self, mut maybe_side_effect: Option<&mut String>) {
80+
other(maybe_side_effect.as_deref_mut());
81+
other(maybe_side_effect);
82+
}
83+
}
84+
85+
fn other(_maybe_side_effect: Option<&mut String>) {
86+
unimplemented!()
87+
}
88+
}

0 commit comments

Comments
 (0)