From e65cefcf6f22cb482bcd2ae40c99f6baab8d99bc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 11:33:53 -0400 Subject: [PATCH] Propagate errors rather than using return_if_err --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/lib.rs | 1 + clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/methods/iter_overeager_cloned.rs | 3 +-- clippy_lints/src/needless_pass_by_ref_mut.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/operators/assign_op_pattern.rs | 4 ++-- clippy_lints/src/unwrap.rs | 4 ++-- clippy_utils/src/lib.rs | 1 + clippy_utils/src/sugg.rs | 4 +++- clippy_utils/src/usage.rs | 3 ++- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 6392ca13df1..6715de52649 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -104,7 +104,7 @@ fn check_fn( too_large_for_stack: self.too_large_for_stack, }; - ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body); + ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body).into_ok(); for node in v.set { span_lint_hir( diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2c44c3881aa..a8bfbbdd9ec 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -8,6 +8,7 @@ #![feature(never_type)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] +#![feature(unwrap_infallible)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow( diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 082c5977cbd..6b9ecf5f141 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -65,7 +65,7 @@ fn check_for_mutation( body.hir_id.owner.def_id, &mut delegate, ) - .walk_expr(body); + .walk_expr(body).into_ok(); delegate.mutation_span() } diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index d4c709de97f..a52d38790a2 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -9,7 +9,6 @@ use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty::{self, BorrowKind}; use rustc_span::sym; -use rustc_trait_selection::infer::TyCtxtInferExt; use super::ITER_OVEREAGER_CLONED; use crate::redundant_clone::REDUNDANT_CLONE; @@ -75,7 +74,7 @@ pub(super) fn check<'tcx>( closure.def_id, &mut delegate, ) - .consume_body(body); + .consume_body(body).into_ok(); let mut to_be_discarded = false; diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 5e786c1277a..9b852f52ea1 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -117,7 +117,7 @@ fn check_closures<'tcx>( .associated_body() .map(|(_, body_id)| hir.body(body_id)) { - euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body).into_ok(); } } } @@ -194,7 +194,7 @@ fn check_fn( async_closures: FxHashSet::default(), tcx: cx.tcx, }; - euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok(); let mut checked_closures = FxHashSet::default(); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 60523ae0d0e..0986571d0f2 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -133,7 +133,7 @@ fn check_fn( // function body. let MovedVariablesCtxt { moved_vars } = { let mut ctx = MovedVariablesCtxt::default(); - euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok(); ctx }; diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 6d617447bb5..910e584a7a0 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -119,7 +119,7 @@ fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} let mut s = S(HirIdSet::default()); let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); - v.consume_expr(e); + v.consume_expr(e).into_ok(); s.0 } @@ -144,6 +144,6 @@ fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} let mut s = S(HirIdSet::default()); let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); - v.consume_expr(e); + v.consume_expr(e).into_ok(); s.0 } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index aa5555d65f6..5b2841dcd83 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -256,8 +256,8 @@ fn visit_branch( cond.hir_id.owner.def_id, &mut delegate, ); - vis.walk_expr(cond); - vis.walk_expr(branch); + vis.walk_expr(cond).into_ok(); + vis.walk_expr(branch).into_ok(); if delegate.is_mutated { // if the variable is mutated, we don't know whether it can be unwrapped. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index a49414a058b..99d7aba2f7a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -7,6 +7,7 @@ #![feature(never_type)] #![feature(rustc_private)] #![feature(assert_matches)] +#![feature(unwrap_infallible)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow( diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 49b0eb05d2a..bf03c6c1601 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -830,7 +830,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti applicability: Applicability::MachineApplicable, }; - ExprUseVisitor::for_clippy(cx, def_id, &mut visitor).consume_body(closure_body); + ExprUseVisitor::for_clippy(cx, def_id, &mut visitor) + .consume_body(closure_body) + .into_ok(); if !visitor.suggestion_start.is_empty() { return Some(DerefClosure { diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index d0ab6d434aa..9abb4ef9b8d 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -21,7 +21,8 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> expr.hir_id.owner.def_id, &mut delegate, ) - .walk_expr(expr); + .walk_expr(expr) + .into_ok(); if delegate.skip { return None;