Skip to content

Commit 5be7048

Browse files
committed
Fix clippy
1 parent 77aaeca commit 5be7048

File tree

9 files changed

+27
-5
lines changed

9 files changed

+27
-5
lines changed

src/tools/clippy/clippy_lints/src/loops/never_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn never_loop_expr<'tcx>(
160160
| ExprKind::UnsafeBinderCast(_, e, _) => never_loop_expr(cx, e, local_labels, main_loop_id),
161161
ExprKind::Let(let_expr) => never_loop_expr(cx, let_expr.init, local_labels, main_loop_id),
162162
ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(cx, es.iter(), local_labels, main_loop_id),
163+
ExprKind::Use(expr, _) => never_loop_expr(cx, expr, local_labels, main_loop_id),
163164
ExprKind::MethodCall(_, receiver, es, _) => {
164165
never_loop_expr_all(cx, once(receiver).chain(es.iter()), local_labels, main_loop_id)
165166
},

src/tools/clippy/clippy_lints/src/matches/manual_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where
9999
});
100100
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(l), .. })) = e.kind {
101101
match captures.get(l) {
102-
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
102+
Some(CaptureKind::Value | CaptureKind::Use | CaptureKind::Ref(Mutability::Mut)) => return None,
103103
Some(CaptureKind::Ref(Mutability::Not)) if binding_ref_mutability == Mutability::Mut => {
104104
return None;
105105
},

src/tools/clippy/clippy_lints/src/option_if_let_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn try_get_option_occurrence<'tcx>(
177177
.then_some(())
178178
.and_then(|()| none_captures.get(local_id))
179179
}) {
180-
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
180+
Some(CaptureKind::Value | CaptureKind::Use | CaptureKind::Ref(Mutability::Mut)) => return None,
181181
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,
182182
Some(CaptureKind::Ref(Mutability::Not)) | None => (),
183183
}

src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
426426
kind!("Tup({elements})");
427427
self.slice(elements, |e| self.expr(e));
428428
},
429+
ExprKind::Use(expr, _) => {
430+
bind!(self, expr);
431+
kind!("Use({expr})");
432+
self.expr(expr);
433+
},
429434
ExprKind::Binary(op, left, right) => {
430435
bind!(self, op, left, right);
431436
kind!("Binary({op}, {left}, {right})");
@@ -488,6 +493,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
488493
}) => {
489494
let capture_clause = match capture_clause {
490495
CaptureBy::Value { .. } => "Value { .. }",
496+
CaptureBy::Use { .. } => "Use { .. }",
491497
CaptureBy::Ref => "Ref",
492498
};
493499

src/tools/clippy/clippy_utils/src/eager_or_lazy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
291291
ExprKind::ConstBlock(_)
292292
| ExprKind::Array(_)
293293
| ExprKind::Tup(_)
294+
| ExprKind::Use(..)
294295
| ExprKind::Lit(_)
295296
| ExprKind::Cast(..)
296297
| ExprKind::Type(..)

src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ impl HirEqInterExpr<'_, '_, '_> {
393393
&& over(lf, rf, |l, r| self.eq_expr_field(l, r))
394394
},
395395
(&ExprKind::Tup(l_tup), &ExprKind::Tup(r_tup)) => self.eq_exprs(l_tup, r_tup),
396+
(&ExprKind::Use(l_expr, _), &ExprKind::Use(r_expr, _)) => self.eq_expr(l_expr, r_expr),
396397
(&ExprKind::Type(le, lt), &ExprKind::Type(re, rt)) => self.eq_expr(le, re) && self.eq_ty(lt, rt),
397398
(&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re),
398399
(&ExprKind::Yield(le, _), &ExprKind::Yield(re, _)) => return self.eq_expr(le, re),
@@ -425,6 +426,7 @@ impl HirEqInterExpr<'_, '_, '_> {
425426
| &ExprKind::Ret(..)
426427
| &ExprKind::Struct(..)
427428
| &ExprKind::Tup(..)
429+
| &ExprKind::Use(..)
428430
| &ExprKind::Type(..)
429431
| &ExprKind::Unary(..)
430432
| &ExprKind::Yield(..)
@@ -1050,6 +1052,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
10501052
ExprKind::Tup(tup) => {
10511053
self.hash_exprs(tup);
10521054
},
1055+
ExprKind::Use(expr, _) => {
1056+
self.hash_expr(expr);
1057+
},
10531058
ExprKind::Unary(lop, le) => {
10541059
std::mem::discriminant(&lop).hash(&mut self.s);
10551060
self.hash_expr(le);

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ pub fn can_move_expr_to_closure_no_visit<'tcx>(
10591059
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10601060
pub enum CaptureKind {
10611061
Value,
1062+
Use,
10621063
Ref(Mutability),
10631064
}
10641065
impl CaptureKind {
@@ -1071,6 +1072,7 @@ impl std::ops::BitOr for CaptureKind {
10711072
fn bitor(self, rhs: Self) -> Self::Output {
10721073
match (self, rhs) {
10731074
(CaptureKind::Value, _) | (_, CaptureKind::Value) => CaptureKind::Value,
1075+
(CaptureKind::Use, _) | (_, CaptureKind::Use) => CaptureKind::Use,
10741076
(CaptureKind::Ref(Mutability::Mut), CaptureKind::Ref(_))
10751077
| (CaptureKind::Ref(_), CaptureKind::Ref(Mutability::Mut)) => CaptureKind::Ref(Mutability::Mut),
10761078
(CaptureKind::Ref(Mutability::Not), CaptureKind::Ref(Mutability::Not)) => CaptureKind::Ref(Mutability::Not),
@@ -1151,7 +1153,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
11511153
},
11521154
ExprKind::Let(let_expr) => {
11531155
let mutability = match pat_capture_kind(cx, let_expr.pat) {
1154-
CaptureKind::Value => Mutability::Not,
1156+
CaptureKind::Value | CaptureKind::Use => Mutability::Not,
11551157
CaptureKind::Ref(m) => m,
11561158
};
11571159
return CaptureKind::Ref(mutability);
@@ -1160,7 +1162,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
11601162
let mut mutability = Mutability::Not;
11611163
for capture in arms.iter().map(|arm| pat_capture_kind(cx, arm.pat)) {
11621164
match capture {
1163-
CaptureKind::Value => break,
1165+
CaptureKind::Value | CaptureKind::Use => break,
11641166
CaptureKind::Ref(Mutability::Mut) => mutability = Mutability::Mut,
11651167
CaptureKind::Ref(Mutability::Not) => (),
11661168
}
@@ -1170,7 +1172,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
11701172
_ => break,
11711173
},
11721174
Node::LetStmt(l) => match pat_capture_kind(cx, l.pat) {
1173-
CaptureKind::Value => break,
1175+
CaptureKind::Value | CaptureKind::Use => break,
11741176
capture @ CaptureKind::Ref(_) => return capture,
11751177
},
11761178
_ => break,
@@ -1225,6 +1227,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
12251227
if !self.locals.contains(&local_id) {
12261228
let capture = match capture.info.capture_kind {
12271229
UpvarCapture::ByValue => CaptureKind::Value,
1230+
// FIXME add a CaptureKind::Use
1231+
UpvarCapture::ByUse => CaptureKind::Use,
12281232
UpvarCapture::ByRef(kind) => match kind {
12291233
BorrowKind::Immutable => CaptureKind::Ref(Mutability::Not),
12301234
BorrowKind::UniqueImmutable | BorrowKind::Mutable => {

src/tools/clippy/clippy_utils/src/sugg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<'a> Sugg<'a> {
151151
| ExprKind::Become(..)
152152
| ExprKind::Struct(..)
153153
| ExprKind::Tup(..)
154+
| ExprKind::Use(..)
154155
| ExprKind::Err(_)
155156
| ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(get_snippet(expr.span)),
156157
ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
@@ -223,6 +224,7 @@ impl<'a> Sugg<'a> {
223224
| ast::ExprKind::Try(..)
224225
| ast::ExprKind::TryBlock(..)
225226
| ast::ExprKind::Tup(..)
227+
| ast::ExprKind::Use(..)
226228
| ast::ExprKind::Array(..)
227229
| ast::ExprKind::While(..)
228230
| ast::ExprKind::Await(..)

src/tools/clippy/clippy_utils/src/visitors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
648648
helper(typeck, true, arg, f)?;
649649
}
650650
},
651+
ExprKind::Use(expr, _) => {
652+
helper(typeck, true, expr, f)?;
653+
},
651654
ExprKind::Index(borrowed, consumed, _)
652655
| ExprKind::Assign(borrowed, consumed, _)
653656
| ExprKind::AssignOp(_, borrowed, consumed) => {

0 commit comments

Comments
 (0)