Skip to content
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

2229: Consume IfLet expr #89282

Merged
merged 2 commits into from
Sep 30, 2021
Merged
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
2 changes: 2 additions & 0 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {

if let Some(hir::Guard::If(ref e)) = arm.guard {
self.consume_expr(e)
} else if let Some(hir::Guard::IfLet(_, ref e)) = arm.guard {
self.consume_expr(e)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be an exhaustive match


self.consume_expr(&arm.body);
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/issue-88118-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// edition:2021
// run-pass
#![feature(if_let_guard)]
#[allow(unused_must_use)]
#[allow(dead_code)]

fn print_error_count(registry: &Registry) {
|x: &Registry| {
match &x {
Registry if let _ = registry.try_find_description() => { }
//~^ WARNING: irrefutable `if let` guard pattern
_ => {}
}
};
}

struct Registry;
impl Registry {
pub fn try_find_description(&self) {
unimplemented!()
}
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: irrefutable `if let` guard pattern
--> $DIR/issue-88118-2.rs:10:29
|
LL | Registry if let _ = registry.try_find_description() => { }
| ^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the guard is useless
= help: consider removing the guard and adding a `let` inside the match arm

warning: 1 warning emitted