2229: Consume IfLet expr
This commit is contained in:
parent
ac8dd1b2f2
commit
87010206ad
@ -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)
|
||||
}
|
||||
|
||||
self.consume_expr(&arm.body);
|
||||
|
21
src/test/ui/closures/2229_closure_analysis/issue-88118-2.rs
Normal file
21
src/test/ui/closures/2229_closure_analysis/issue-88118-2.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// edition:2021
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
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() {}
|
@ -0,0 +1,19 @@
|
||||
warning: irrefutable `if let` guard pattern
|
||||
--> $DIR/issue-88118-2.rs:7: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
|
||||
|
||||
error[E0507]: cannot move out of `*registry` which is behind a shared reference
|
||||
--> $DIR/issue-88118-2.rs:7:33
|
||||
|
|
||||
LL | Registry if let _ = registry.try_find_description() => { }
|
||||
| ^^^^^^^^ move occurs because `*registry` has type `Registry`, which does not implement the `Copy` trait
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0507`.
|
Loading…
x
Reference in New Issue
Block a user