Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aa7aca3

Browse files
committedSep 30, 2021
Auto merge of #89282 - sexxi-goose:fix-88118, r=nikomatsakis
2229: Consume IfLet expr When using the IfLet guard feature, we can ICE when attempting to resolve PlaceBuilders. For pattern matching, we currently don't consume the IfLet expression when "visiting" the arms leading us to not "read" all variables and hence not being able to resolve them. r? `@nikomatsakis` Closes #88118
2 parents 6dc08b9 + d0e2b60 commit aa7aca3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎compiler/rustc_typeck/src/expr_use_visitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
619619

620620
if let Some(hir::Guard::If(ref e)) = arm.guard {
621621
self.consume_expr(e)
622+
} else if let Some(hir::Guard::IfLet(_, ref e)) = arm.guard {
623+
self.consume_expr(e)
622624
}
623625

624626
self.consume_expr(&arm.body);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// edition:2021
2+
// run-pass
3+
#![feature(if_let_guard)]
4+
#[allow(unused_must_use)]
5+
#[allow(dead_code)]
6+
7+
fn print_error_count(registry: &Registry) {
8+
|x: &Registry| {
9+
match &x {
10+
Registry if let _ = registry.try_find_description() => { }
11+
//~^ WARNING: irrefutable `if let` guard pattern
12+
_ => {}
13+
}
14+
};
15+
}
16+
17+
struct Registry;
18+
impl Registry {
19+
pub fn try_find_description(&self) {
20+
unimplemented!()
21+
}
22+
}
23+
24+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: irrefutable `if let` guard pattern
2+
--> $DIR/issue-88118-2.rs:10:29
3+
|
4+
LL | Registry if let _ = registry.try_find_description() => { }
5+
| ^
6+
|
7+
= note: `#[warn(irrefutable_let_patterns)]` on by default
8+
= note: this pattern will always match, so the guard is useless
9+
= help: consider removing the guard and adding a `let` inside the match arm
10+
11+
warning: 1 warning emitted
12+

0 commit comments

Comments
 (0)
Please sign in to comment.