Skip to content

Fix early exiting when ExprUseVisitor meets unresolved type var #87879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self;
let mut needs_to_be_read = false;
for arm in arms.iter() {
return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
match mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
match &pat.kind {
PatKind::Binding(.., opt_sub_pat) => {
// If the opt_sub_pat is None, than the binding does not count as
Expand Down Expand Up @@ -290,7 +290,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
// examined
}
}
}));
}) {
Ok(_) => (),
Err(_) => {
// If typeck failed, assume borrow is needed.
needs_to_be_read = true;
}
}
}

if needs_to_be_read {
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/closures/issue-87814-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass
fn main() {
let mut schema_all = vec![];
(0..42).for_each(|_x| match Err(()) as Result<(), _> {
Ok(()) => schema_all.push(()),
Err(_) => (),
});
}
11 changes: 11 additions & 0 deletions src/test/ui/closures/issue-87814-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
#![feature(try_reserve)]

fn main() {
let mut schema_all: (Vec<String>, Vec<String>) = (vec![], vec![]);

let _c = || match schema_all.0.try_reserve(1) as Result<(), _> {
Ok(()) => (),
Err(_) => (),
};
}