Skip to content

Commit 8054409

Browse files
committed
Avoid unnecessary arguments
1 parent f243e6f commit 8054409

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

clippy_lints/src/matches/significant_drop_in_scrutinee.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,21 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
115115
}
116116
}
117117

118-
fn get_type(&self, ex: &'tcx Expr<'_>) -> Ty<'tcx> {
119-
self.cx.typeck_results().expr_ty(ex)
120-
}
121-
122-
fn has_sig_drop_attr(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
118+
fn is_sig_drop_expr(&mut self, ex: &'tcx Expr<'_>) -> bool {
123119
self.seen_types.clear();
124-
self.has_sig_drop_attr_impl(cx, ty)
120+
self.has_sig_drop_attr(self.cx.typeck_results().expr_ty(ex))
125121
}
126122

127-
fn has_sig_drop_attr_impl(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
123+
fn has_sig_drop_attr(&mut self, ty: Ty<'tcx>) -> bool {
128124
if let Some(adt) = ty.ty_adt_def() {
129-
if get_attr(cx.sess(), cx.tcx.get_attrs_unchecked(adt.did()), "has_significant_drop").count() > 0 {
125+
if get_attr(
126+
self.cx.sess(),
127+
self.cx.tcx.get_attrs_unchecked(adt.did()),
128+
"has_significant_drop",
129+
)
130+
.count()
131+
> 0
132+
{
130133
return true;
131134
}
132135
}
@@ -139,8 +142,8 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
139142
rustc_middle::ty::Adt(adt, args) => {
140143
// if some field has significant drop,
141144
adt.all_fields()
142-
.map(|field| field.ty(cx.tcx, args))
143-
.any(|ty| self.has_sig_drop_attr(cx, ty))
145+
.map(|field| field.ty(self.cx.tcx, args))
146+
.any(|ty| self.has_sig_drop_attr(ty))
144147
// or if there is no generic lifetime and..
145148
// (to avoid false positive on `Ref<'a, MutexGuard<Foo>>`)
146149
|| (args
@@ -154,10 +157,10 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
154157
GenericArgKind::Type(ty) => Some(ty),
155158
_ => None,
156159
})
157-
.any(|ty| self.has_sig_drop_attr(cx, ty)))
160+
.any(|ty| self.has_sig_drop_attr(ty)))
158161
},
159-
rustc_middle::ty::Tuple(tys) => tys.iter().any(|ty| self.has_sig_drop_attr(cx, ty)),
160-
rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(cx, *ty),
162+
rustc_middle::ty::Tuple(tys) => tys.iter().any(|ty| self.has_sig_drop_attr(ty)),
163+
rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(*ty),
161164
_ => false,
162165
};
163166

@@ -240,7 +243,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
240243
if self.current_sig_drop.is_some() {
241244
return;
242245
}
243-
let ty = self.sig_drop_checker.get_type(expr);
246+
let ty = self.cx.typeck_results().expr_ty(expr);
244247
if ty.is_ref() {
245248
// We checked that the type was ref, so builtin_deref will return Some TypeAndMut,
246249
// but let's avoid any chance of an ICE
@@ -287,11 +290,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
287290

288291
impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
289292
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
290-
if !self.is_chain_end
291-
&& self
292-
.sig_drop_checker
293-
.has_sig_drop_attr(self.cx, self.sig_drop_checker.get_type(ex))
294-
{
293+
if !self.is_chain_end && self.sig_drop_checker.is_sig_drop_expr(ex) {
295294
self.has_significant_drop = true;
296295
return;
297296
}
@@ -395,10 +394,7 @@ fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'
395394

396395
impl<'a, 'tcx> Visitor<'tcx> for ArmSigDropHelper<'a, 'tcx> {
397396
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
398-
if self
399-
.sig_drop_checker
400-
.has_sig_drop_attr(self.sig_drop_checker.cx, self.sig_drop_checker.get_type(ex))
401-
{
397+
if self.sig_drop_checker.is_sig_drop_expr(ex) {
402398
self.found_sig_drop_spans.insert(ex.span);
403399
return;
404400
}

0 commit comments

Comments
 (0)