Skip to content

Commit c697ec4

Browse files
Propagate errors rather than using return_if_err
1 parent fb298e8 commit c697ec4

File tree

16 files changed

+252
-208
lines changed

16 files changed

+252
-208
lines changed

Diff for: compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+206-186
Large diffs are not rendered by default.

Diff for: compiler/rustc_hir_typeck/src/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
252252
}
253253
}
254254

255-
euv::ExprUseVisitor::new(
255+
let _ = euv::ExprUseVisitor::new(
256256
&FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id),
257257
&mut delegate,
258258
)

Diff for: src/tools/clippy/clippy_lints/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
104104
too_large_for_stack: self.too_large_for_stack,
105105
};
106106

107-
ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body);
107+
ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body).into_ok();
108108

109109
for node in v.set {
110110
span_lint_hir(

Diff for: src/tools/clippy/clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(never_type)]
99
#![feature(rustc_private)]
1010
#![feature(stmt_expr_attributes)]
11+
#![feature(unwrap_infallible)]
1112
#![recursion_limit = "512"]
1213
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1314
#![allow(

Diff for: src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn check_for_mutation(
6565
body.hir_id.owner.def_id,
6666
&mut delegate,
6767
)
68-
.walk_expr(body);
68+
.walk_expr(body).into_ok();
6969

7070
delegate.mutation_span()
7171
}

Diff for: src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_lint::LateContext;
99
use rustc_middle::mir::{FakeReadCause, Mutability};
1010
use rustc_middle::ty::{self, BorrowKind};
1111
use rustc_span::sym;
12-
use rustc_trait_selection::infer::TyCtxtInferExt;
1312

1413
use super::ITER_OVEREAGER_CLONED;
1514
use crate::redundant_clone::REDUNDANT_CLONE;
@@ -75,7 +74,7 @@ pub(super) fn check<'tcx>(
7574
closure.def_id,
7675
&mut delegate,
7776
)
78-
.consume_body(body);
77+
.consume_body(body).into_ok();
7978

8079
let mut to_be_discarded = false;
8180

Diff for: src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn check_closures<'tcx>(
117117
.associated_body()
118118
.map(|(_, body_id)| hir.body(body_id))
119119
{
120-
euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body);
120+
euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body).into_ok();
121121
}
122122
}
123123
}
@@ -194,7 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
194194
async_closures: FxHashSet::default(),
195195
tcx: cx.tcx,
196196
};
197-
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body);
197+
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok();
198198

199199
let mut checked_closures = FxHashSet::default();
200200

Diff for: src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
133133
// function body.
134134
let MovedVariablesCtxt { moved_vars } = {
135135
let mut ctx = MovedVariablesCtxt::default();
136-
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body);
136+
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok();
137137
ctx
138138
};
139139

Diff for: src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
119119

120120
let mut s = S(HirIdSet::default());
121121
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
122-
v.consume_expr(e);
122+
v.consume_expr(e).into_ok();
123123
s.0
124124
}
125125

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

145145
let mut s = S(HirIdSet::default());
146146
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
147-
v.consume_expr(e);
147+
v.consume_expr(e).into_ok();
148148
s.0
149149
}

Diff for: src/tools/clippy/clippy_lints/src/unwrap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> {
256256
cond.hir_id.owner.def_id,
257257
&mut delegate,
258258
);
259-
vis.walk_expr(cond);
260-
vis.walk_expr(branch);
259+
vis.walk_expr(cond).into_ok();
260+
vis.walk_expr(branch).into_ok();
261261

262262
if delegate.is_mutated {
263263
// if the variable is mutated, we don't know whether it can be unwrapped.

Diff for: src/tools/clippy/clippy_utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(never_type)]
88
#![feature(rustc_private)]
99
#![feature(assert_matches)]
10+
#![feature(unwrap_infallible)]
1011
#![recursion_limit = "512"]
1112
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1213
#![allow(

Diff for: src/tools/clippy/clippy_utils/src/sugg.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
830830
applicability: Applicability::MachineApplicable,
831831
};
832832

833-
ExprUseVisitor::for_clippy(cx, def_id, &mut visitor).consume_body(closure_body);
833+
ExprUseVisitor::for_clippy(cx, def_id, &mut visitor)
834+
.consume_body(closure_body)
835+
.into_ok();
834836

835837
if !visitor.suggestion_start.is_empty() {
836838
return Some(DerefClosure {

Diff for: src/tools/clippy/clippy_utils/src/usage.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
2121
expr.hir_id.owner.def_id,
2222
&mut delegate,
2323
)
24-
.walk_expr(expr);
24+
.walk_expr(expr)
25+
.into_ok();
2526

2627
if delegate.skip {
2728
return None;

Diff for: tests/crashes/123901.rs

-8
This file was deleted.

Diff for: tests/ui/async-await/async-closures/ambiguous-arg.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ edition:2021
2+
3+
// Regression test for #123901. We previously ICE'd as we silently
4+
// swallowed an in the `ExprUseVisitor`.
5+
6+
#![feature(async_closure)]
7+
8+
pub fn test(test: &u64, temp: &u64) {
9+
async |check, a, b| {
10+
//~^ ERROR type annotations needed
11+
temp.abs_diff(12);
12+
};
13+
}
14+
15+
fn main() {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/ambiguous-arg.rs:9:25
3+
|
4+
LL | async |check, a, b| {
5+
| _________________________^
6+
LL | |
7+
LL | | temp.abs_diff(12);
8+
LL | | };
9+
| |_____^ cannot infer type
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)