Skip to content

Commit 09f6027

Browse files
committed
Workaround of early exiting when ExprUseVisitor meets unresolved type var.
Add regression test for issue-87814 Set needs_to_read to true when typeck errors.
1 parent b6e334d commit 09f6027

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_typeck/src/expr_use_visitor.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
243243
let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self;
244244
let mut needs_to_be_read = false;
245245
for arm in arms.iter() {
246-
return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
246+
match mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
247247
match &pat.kind {
248248
PatKind::Binding(.., opt_sub_pat) => {
249249
// If the opt_sub_pat is None, than the binding does not count as
@@ -290,7 +290,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
290290
// examined
291291
}
292292
}
293-
}));
293+
}) {
294+
Ok(_) => (),
295+
Err(_) => {
296+
// If typeck failed, assume borrow is needed.
297+
needs_to_be_read = true;
298+
}
299+
}
294300
}
295301

296302
if needs_to_be_read {

src/test/ui/closures/issue-87814-1.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
fn main() {
3+
let mut schema_all = vec![];
4+
(0..42).for_each(|_x| match Err(()) as Result<(), _> {
5+
Ok(()) => schema_all.push(()),
6+
Err(_) => (),
7+
});
8+
}

src/test/ui/closures/issue-87814-2.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
#![feature(try_reserve)]
3+
4+
fn main() {
5+
let mut schema_all: (Vec<String>, Vec<String>) = (vec![], vec![]);
6+
7+
let _c = || match schema_all.0.try_reserve(1) as Result<(), _> {
8+
Ok(()) => (),
9+
Err(_) => (),
10+
};
11+
}

0 commit comments

Comments
 (0)