Fix clippy
This commit is contained in:
parent
dcdfd551f0
commit
60b6470104
17 changed files with 44 additions and 5 deletions
|
|
@ -150,6 +150,8 @@ impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
if cmt.place.projections.is_empty() {
|
||||
if let PlaceBase::Local(lid) = cmt.place.base {
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ struct MutatePairDelegate<'a, 'tcx> {
|
|||
impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
|
||||
if bk == ty::BorrowKind::Mutable {
|
||||
if let PlaceBase::Local(id) = cmt.place.base {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -147,6 +147,8 @@ impl<'tcx> Delegate<'tcx> for MoveDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: BorrowKind) {}
|
||||
|
||||
fn mutate(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
|
|
|||
|
|
@ -396,6 +396,8 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn use_cloned(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, id: HirId, borrow: ty::BorrowKind) {
|
||||
self.prev_bind = None;
|
||||
|
|
|
|||
|
|
@ -326,6 +326,8 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
|
|||
self.move_common(cmt);
|
||||
}
|
||||
|
||||
fn use_cloned(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {}
|
||||
|
||||
fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
|||
}
|
||||
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
|
||||
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
|
|
@ -137,6 +138,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
|||
}
|
||||
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
|
||||
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,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 => (),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,8 @@ impl<'tcx> Delegate<'tcx> for MutationVisitor<'tcx> {
|
|||
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn fake_read(&mut self, _: &PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -426,6 +426,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})");
|
||||
|
|
@ -488,6 +493,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
|||
}) => {
|
||||
let capture_clause = match capture_clause {
|
||||
CaptureBy::Value { .. } => "Value { .. }",
|
||||
CaptureBy::Use { .. } => "Use { .. }",
|
||||
CaptureBy::Ref => "Ref",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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(..)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
@ -425,6 +426,7 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
| &ExprKind::Ret(..)
|
||||
| &ExprKind::Struct(..)
|
||||
| &ExprKind::Tup(..)
|
||||
| &ExprKind::Use(..)
|
||||
| &ExprKind::Type(..)
|
||||
| &ExprKind::Unary(..)
|
||||
| &ExprKind::Yield(..)
|
||||
|
|
@ -1053,6 +1055,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);
|
||||
|
|
|
|||
|
|
@ -1129,6 +1129,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 {
|
||||
|
|
@ -1141,6 +1142,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),
|
||||
|
|
@ -1220,7 +1222,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);
|
||||
|
|
@ -1229,7 +1231,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) => (),
|
||||
}
|
||||
|
|
@ -1239,7 +1241,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,
|
||||
|
|
@ -1294,6 +1296,7 @@ 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,
|
||||
UpvarCapture::ByUse => CaptureKind::Use,
|
||||
UpvarCapture::ByRef(kind) => match kind {
|
||||
BorrowKind::Immutable => CaptureKind::Ref(Mutability::Not),
|
||||
BorrowKind::UniqueImmutable | BorrowKind::Mutable => {
|
||||
|
|
|
|||
|
|
@ -147,6 +147,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),
|
||||
|
|
@ -217,6 +218,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(..)
|
||||
|
|
@ -835,6 +837,8 @@ impl<'tcx> DerefDelegate<'_, 'tcx> {
|
|||
impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
if let PlaceBase::Local(id) = cmt.place.base {
|
||||
let map = self.cx.tcx.hir();
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ impl MutVarsDelegate {
|
|||
impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
|
||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||
|
||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) {
|
||||
if bk == ty::BorrowKind::Mutable {
|
||||
self.update(cmt);
|
||||
|
|
|
|||
|
|
@ -648,6 +648,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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue