Skip to content

Commit c47746c

Browse files
committed
fix: needless_option_as_deref FP in trait
1 parent 4129f5c commit c47746c

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
@@ -70,3 +70,16 @@ mod issue_non_copy_13077 {
7070
pub field: (),
7171
}
7272
}
73+
74+
mod issue14148 {
75+
pub trait SomeTrait {
76+
fn something(&self, mut maybe_side_effect: Option<&mut String>) {
77+
other(maybe_side_effect.as_deref_mut());
78+
other(maybe_side_effect);
79+
}
80+
}
81+
82+
fn other(_maybe_side_effect: Option<&mut String>) {
83+
unimplemented!()
84+
}
85+
}

tests/ui/needless_option_as_deref.rs

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

0 commit comments

Comments
 (0)