Skip to content

Commit

Permalink
Propagate errors rather than using return_if_err
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 12, 2024
1 parent fb298e8 commit c697ec4
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 208 deletions.
392 changes: 206 additions & 186 deletions compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

euv::ExprUseVisitor::new(
let _ = euv::ExprUseVisitor::new(
&FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id),
&mut delegate,
)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
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(
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_lint::LateContext;
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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
// 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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {

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
}

Expand All @@ -144,6 +144,6 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {

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
}
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> {
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.
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/tools/clippy/clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_utils/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions tests/crashes/123901.rs

This file was deleted.

15 changes: 15 additions & 0 deletions tests/ui/async-await/async-closures/ambiguous-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ edition:2021

// Regression test for #123901. We previously ICE'd as we silently
// swallowed an in the `ExprUseVisitor`.

#![feature(async_closure)]

pub fn test(test: &u64, temp: &u64) {
async |check, a, b| {
//~^ ERROR type annotations needed
temp.abs_diff(12);
};
}

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/async-await/async-closures/ambiguous-arg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0282]: type annotations needed
--> $DIR/ambiguous-arg.rs:9:25
|
LL | async |check, a, b| {
| _________________________^
LL | |
LL | | temp.abs_diff(12);
LL | | };
| |_____^ cannot infer type

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0282`.

0 comments on commit c697ec4

Please sign in to comment.