Skip to content

Commit 189a794

Browse files
committed
Fix bind_unused_param applicable on closure
Example --- ```rust fn foo() { let _ = |$0x| 2; } ``` **Before this PR** ```rust fn foo() { let _ = x; let _ = |x| 2; } ``` **After this PR** Assist not applicable
1 parent b3e6363 commit 189a794

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/bind_unused_param.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
3333
return None;
3434
}
3535

36-
let func = param.syntax().ancestors().find_map(ast::Fn::cast)?;
36+
let func = param.syntax().ancestors().nth(2).and_then(ast::Fn::cast)?;
3737
let stmt_list = func.body()?.stmt_list()?;
3838
let l_curly_range = stmt_list.l_curly_token()?.text_range();
3939
let r_curly_range = stmt_list.r_curly_token()?.text_range();
@@ -176,6 +176,18 @@ fn foo(x: i32, $0y: i32) { y; }
176176
bind_unused_param,
177177
r#"
178178
fn foo($0_x: i32, y: i32) {}
179+
"#,
180+
);
181+
}
182+
183+
#[test]
184+
fn not_applicable_closure() {
185+
check_assist_not_applicable(
186+
bind_unused_param,
187+
r#"
188+
fn foo() {
189+
let _ = |$0x| 2;
190+
}
179191
"#,
180192
);
181193
}

0 commit comments

Comments
 (0)