diff options
| author | A4-Tacks <wdsjxhno1001@163.com> | 2025-09-18 20:00:31 +0800 |
|---|---|---|
| committer | A4-Tacks <wdsjxhno1001@163.com> | 2025-09-18 20:00:31 +0800 |
| commit | 1a56d279b8dee896dd46552806686fac513336a7 (patch) | |
| tree | 95bb8bdc5da986bfd105f3efd46a32e68eb363bf | |
| parent | bb7cdc25d48f18667056adcb2380630b7d3b9f0b (diff) | |
| download | rust-1a56d279b8dee896dd46552806686fac513336a7.tar.gz rust-1a56d279b8dee896dd46552806686fac513336a7.zip | |
Fix applicable after l_curly for replace_is_method_with_if_let_method
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs index 5ef8ba46b9e..f507cae1bb0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs @@ -31,6 +31,9 @@ pub(crate) fn replace_is_method_with_if_let_method( ast::Expr::MethodCallExpr(call) => call, _ => return None, }; + if ctx.offset() > if_expr.then_branch()?.stmt_list()?.l_curly_token()?.text_range().end() { + return None; + } let name_ref = call_expr.name_ref()?; match name_ref.text().as_str() { @@ -191,4 +194,19 @@ fn main() { "#, ); } + + #[test] + fn replace_is_some_with_if_let_some_not_applicable_after_l_curly() { + check_assist_not_applicable( + replace_is_method_with_if_let_method, + r#" +fn main() { + let x = Some(1); + if x.is_some() { + ()$0 + } +} +"#, + ); + } } |
