Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Dec 27, 2024
1 parent e8c91b8 commit 0aaedb8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/loops/never_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn never_loop_expr<'tcx>(
| ExprKind::UnsafeBinderCast(_, e, _) => never_loop_expr(cx, e, local_labels, main_loop_id),
ExprKind::Let(let_expr) => never_loop_expr(cx, let_expr.init, local_labels, main_loop_id),
ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(cx, es.iter(), local_labels, main_loop_id),
ExprKind::Use(expr, _) => never_loop_expr(cx, expr, local_labels, main_loop_id),
ExprKind::MethodCall(_, receiver, es, _) => {
never_loop_expr_all(cx, once(receiver).chain(es.iter()), local_labels, main_loop_id)
},
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/matches/manual_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
});
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(l), .. })) = e.kind {
match captures.get(l) {
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Value | CaptureKind::Use | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Ref(Mutability::Not)) if binding_ref_mutability == Mutability::Mut => {
return None;
},
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/option_if_let_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn try_get_option_occurrence<'tcx>(
.then_some(())
.and_then(|()| none_captures.get(local_id))
}) {
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Value | CaptureKind::Use | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,
Some(CaptureKind::Ref(Mutability::Not)) | None => (),
}
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Tup({elements})");
self.slice(elements, |e| self.expr(e));
},
ExprKind::Use(expr, _) => {
bind!(self, expr);
kind!("Use({expr})");
self.expr(expr);
},
ExprKind::Binary(op, left, right) => {
bind!(self, op, left, right);
kind!("Binary({op}, {left}, {right})");
Expand Down Expand Up @@ -489,6 +494,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}) => {
let capture_clause = match capture_clause {
CaptureBy::Value { .. } => "Value { .. }",
CaptureBy::Use { .. } => "Use { .. }",
CaptureBy::Ref => "Ref",
};

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
ExprKind::ConstBlock(_)
| ExprKind::Array(_)
| ExprKind::Tup(_)
| ExprKind::Use(..)
| ExprKind::Lit(_)
| ExprKind::Cast(..)
| ExprKind::Type(..)
Expand Down
5 changes: 5 additions & 0 deletions src/tools/clippy/clippy_utils/src/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ impl HirEqInterExpr<'_, '_, '_> {
&& over(lf, rf, |l, r| self.eq_expr_field(l, r))
},
(&ExprKind::Tup(l_tup), &ExprKind::Tup(r_tup)) => self.eq_exprs(l_tup, r_tup),
(&ExprKind::Use(l_expr, _), &ExprKind::Use(r_expr, _)) => self.eq_expr(l_expr, r_expr),
(&ExprKind::Type(le, lt), &ExprKind::Type(re, rt)) => self.eq_expr(le, re) && self.eq_ty(lt, rt),
(&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re),
(&ExprKind::Yield(le, _), &ExprKind::Yield(re, _)) => return self.eq_expr(le, re),
Expand Down Expand Up @@ -425,6 +426,7 @@ impl HirEqInterExpr<'_, '_, '_> {
| &ExprKind::Ret(..)
| &ExprKind::Struct(..)
| &ExprKind::Tup(..)
| &ExprKind::Use(..)
| &ExprKind::Type(..)
| &ExprKind::Unary(..)
| &ExprKind::Yield(..)
Expand Down Expand Up @@ -1033,6 +1035,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
ExprKind::Tup(tup) => {
self.hash_exprs(tup);
},
ExprKind::Use(expr, _) => {
self.hash_expr(expr);
},
ExprKind::Unary(lop, le) => {
std::mem::discriminant(&lop).hash(&mut self.s);
self.hash_expr(le);
Expand Down
10 changes: 7 additions & 3 deletions src/tools/clippy/clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ pub fn can_move_expr_to_closure_no_visit<'tcx>(
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CaptureKind {
Value,
Use,
Ref(Mutability),
}
impl CaptureKind {
Expand All @@ -1054,6 +1055,7 @@ impl std::ops::BitOr for CaptureKind {
fn bitor(self, rhs: Self) -> Self::Output {
match (self, rhs) {
(CaptureKind::Value, _) | (_, CaptureKind::Value) => CaptureKind::Value,
(CaptureKind::Use, _) | (_, CaptureKind::Use) => CaptureKind::Use,
(CaptureKind::Ref(Mutability::Mut), CaptureKind::Ref(_))
| (CaptureKind::Ref(_), CaptureKind::Ref(Mutability::Mut)) => CaptureKind::Ref(Mutability::Mut),
(CaptureKind::Ref(Mutability::Not), CaptureKind::Ref(Mutability::Not)) => CaptureKind::Ref(Mutability::Not),
Expand Down Expand Up @@ -1134,7 +1136,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
},
ExprKind::Let(let_expr) => {
let mutability = match pat_capture_kind(cx, let_expr.pat) {
CaptureKind::Value => Mutability::Not,
CaptureKind::Value | CaptureKind::Use => Mutability::Not,
CaptureKind::Ref(m) => m,
};
return CaptureKind::Ref(mutability);
Expand All @@ -1143,7 +1145,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
let mut mutability = Mutability::Not;
for capture in arms.iter().map(|arm| pat_capture_kind(cx, arm.pat)) {
match capture {
CaptureKind::Value => break,
CaptureKind::Value | CaptureKind::Use => break,
CaptureKind::Ref(Mutability::Mut) => mutability = Mutability::Mut,
CaptureKind::Ref(Mutability::Not) => (),
}
Expand All @@ -1153,7 +1155,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
_ => break,
},
Node::LetStmt(l) => match pat_capture_kind(cx, l.pat) {
CaptureKind::Value => break,
CaptureKind::Value | CaptureKind::Use => break,
capture @ CaptureKind::Ref(_) => return capture,
},
_ => break,
Expand Down Expand Up @@ -1208,6 +1210,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
if !self.locals.contains(&local_id) {
let capture = match capture.info.capture_kind {
UpvarCapture::ByValue => CaptureKind::Value,
// FIXME add a CaptureKind::Use
UpvarCapture::ByUse => CaptureKind::Use,
UpvarCapture::ByRef(kind) => match kind {
BorrowKind::Immutable => CaptureKind::Ref(Mutability::Not),
BorrowKind::UniqueImmutable | BorrowKind::Mutable => {
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl<'a> Sugg<'a> {
| ExprKind::Become(..)
| ExprKind::Struct(..)
| ExprKind::Tup(..)
| ExprKind::Use(..)
| ExprKind::Err(_)
| ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(get_snippet(expr.span)),
ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
Expand Down Expand Up @@ -223,6 +224,7 @@ impl<'a> Sugg<'a> {
| ast::ExprKind::Try(..)
| ast::ExprKind::TryBlock(..)
| ast::ExprKind::Tup(..)
| ast::ExprKind::Use(..)
| ast::ExprKind::Array(..)
| ast::ExprKind::While(..)
| ast::ExprKind::Await(..)
Expand Down
3 changes: 3 additions & 0 deletions src/tools/clippy/clippy_utils/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
helper(typeck, true, arg, f)?;
}
},
ExprKind::Use(expr, _) => {
helper(typeck, true, expr, f)?;
},
ExprKind::Index(borrowed, consumed, _)
| ExprKind::Assign(borrowed, consumed, _)
| ExprKind::AssignOp(_, borrowed, consumed) => {
Expand Down

0 comments on commit 0aaedb8

Please sign in to comment.