mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
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 https://github.com/rust-lang/rust/issues/88118
This commit is contained in:
commit
aa7aca3b95
@ -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);
|
||||
|
24
src/test/ui/closures/2229_closure_analysis/issue-88118-2.rs
Normal file
24
src/test/ui/closures/2229_closure_analysis/issue-88118-2.rs
Normal file
@ -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() {}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user