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

fix: Don't skip closure captures after let-else #15625

Merged
merged 4 commits into from
Sep 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/hir-ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,13 @@ impl InferenceContext<'_> {
Statement::Let { pat, type_ref: _, initializer, else_branch } => {
if let Some(else_branch) = else_branch {
self.consume_expr(*else_branch);
if let Some(initializer) = initializer {
self.consume_expr(*initializer);
}
return;
}
if let Some(initializer) = initializer {
self.walk_expr(*initializer);
if else_branch.is_some() {
self.consume_expr(*initializer);
} else {
self.walk_expr(*initializer);
}
if let Some(place) = self.place_of_expr(*initializer) {
self.consume_with_pat(place, *pat);
}
Expand Down
14 changes: 14 additions & 0 deletions crates/hir-ty/src/layout/tests/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,17 @@ fn ellipsis_pattern() {
}
}
}

#[test]
fn regression_15623() {
size_and_align_expr! {
let a = 2;
let b = 3;
let c = 5;
move || {
let 0 = a else { return b; };
let y = c;
y
}
}
}
23 changes: 23 additions & 0 deletions crates/ide-diagnostics/src/handlers/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,29 @@ fn f() {
loop {}
for _ in 0..2 {}
}
"#,
);
}

#[test]
fn regression_15623() {
check_diagnostics(
r#"
//- minicore: fn

struct Foo;

impl Foo {
fn needs_mut(&mut self) {}
}

fn foo(mut foo: Foo) {
let mut call_me = || {
let 0 = 1 else { return };
foo.needs_mut();
};
call_me();
}
"#,
);
}
Expand Down