Skip to content

Commit a78a15c

Browse files
committed
Avoid unnecessary arguments
1 parent a032189 commit a78a15c

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

clippy_lints/src/matches/significant_drop_in_scrutinee.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,25 @@ 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)
118+
fn is_sig_drop_expr(&mut self, ex: &'tcx Expr<'_>) -> bool {
119+
self.has_sig_drop_attr(self.cx.typeck_results().expr_ty(ex))
120120
}
121121

122-
fn has_sig_drop_attr(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
122+
fn has_sig_drop_attr(&mut self, ty: Ty<'tcx>) -> bool {
123123
self.seen_types.clear();
124-
self.has_sig_drop_attr_impl(cx, ty)
124+
self.has_sig_drop_attr_impl(ty)
125125
}
126126

127-
fn has_sig_drop_attr_impl(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
127+
fn has_sig_drop_attr_impl(&mut self, ty: Ty<'tcx>) -> bool {
128128
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 {
129+
if get_attr(
130+
self.cx.sess(),
131+
self.cx.tcx.get_attrs_unchecked(adt.did()),
132+
"has_significant_drop",
133+
)
134+
.count()
135+
> 0
136+
{
130137
return true;
131138
}
132139
}
@@ -139,8 +146,8 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
139146
rustc_middle::ty::Adt(adt, args) => {
140147
// if some field has significant drop,
141148
adt.all_fields()
142-
.map(|field| field.ty(cx.tcx, args))
143-
.any(|ty| self.has_sig_drop_attr(cx, ty))
149+
.map(|field| field.ty(self.cx.tcx, args))
150+
.any(|ty| self.has_sig_drop_attr_impl(ty))
144151
// or if there is no generic lifetime and..
145152
// (to avoid false positive on `Ref<'a, MutexGuard<Foo>>`)
146153
|| (args
@@ -154,10 +161,10 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
154161
GenericArgKind::Type(ty) => Some(ty),
155162
_ => None,
156163
})
157-
.any(|ty| self.has_sig_drop_attr(cx, ty)))
164+
.any(|ty| self.has_sig_drop_attr_impl(ty)))
158165
},
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),
166+
rustc_middle::ty::Tuple(tys) => tys.iter().any(|ty| self.has_sig_drop_attr_impl(ty)),
167+
rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr_impl(*ty),
161168
_ => false,
162169
};
163170

@@ -240,7 +247,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
240247
if self.current_sig_drop.is_some() {
241248
return;
242249
}
243-
let ty = self.sig_drop_checker.get_type(expr);
250+
let ty = self.cx.typeck_results().expr_ty(expr);
244251
if ty.is_ref() {
245252
// We checked that the type was ref, so builtin_deref will return Some TypeAndMut,
246253
// but let's avoid any chance of an ICE
@@ -287,11 +294,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
287294

288295
impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
289296
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-
{
297+
if !self.is_chain_end && self.sig_drop_checker.is_sig_drop_expr(ex) {
295298
self.has_significant_drop = true;
296299
return;
297300
}
@@ -395,10 +398,7 @@ fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'
395398

396399
impl<'a, 'tcx> Visitor<'tcx> for ArmSigDropHelper<'a, 'tcx> {
397400
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-
{
401+
if self.sig_drop_checker.is_sig_drop_expr(ex) {
402402
self.found_sig_drop_spans.insert(ex.span);
403403
return;
404404
}

0 commit comments

Comments
 (0)