Skip to content

Commit 8701020

Browse files
committed
2229: Consume IfLet expr
1 parent ac8dd1b commit 8701020

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

compiler/rustc_typeck/src/expr_use_visitor.rs

+2
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);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition:2021
2+
#![feature(if_let_guard)]
3+
4+
fn print_error_count(registry: &Registry) {
5+
|x: &Registry| {
6+
match &x {
7+
Registry if let _ = registry.try_find_description() => { }
8+
//~^ WARNING: irrefutable `if let` guard pattern
9+
_ => {}
10+
}
11+
};
12+
}
13+
14+
struct Registry;
15+
impl Registry {
16+
pub fn try_find_description(&self) {
17+
unimplemented!()
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: irrefutable `if let` guard pattern
2+
--> $DIR/issue-88118-2.rs:7: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+
error[E0507]: cannot move out of `*registry` which is behind a shared reference
12+
--> $DIR/issue-88118-2.rs:7:33
13+
|
14+
LL | Registry if let _ = registry.try_find_description() => { }
15+
| ^^^^^^^^ move occurs because `*registry` has type `Registry`, which does not implement the `Copy` trait
16+
17+
error: aborting due to previous error; 1 warning emitted
18+
19+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)