Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22759 from Wilfred/fix/syntax-factory-mapping-unwraps
Fix crashes in assists due to .unwrap() calls in SyntaxFactory
A4-Tacks 3 weeks ago
parent 1649637 · parent 0da74dd · commit cac0779
-rw-r--r--crates/ide-assists/src/handlers/convert_closure_to_fn.rs19
-rw-r--r--crates/ide-assists/src/handlers/unwrap_branch.rs19
-rw-r--r--crates/syntax/src/ast/make.rs21
3 files changed, 57 insertions, 2 deletions
diff --git a/crates/ide-assists/src/handlers/convert_closure_to_fn.rs b/crates/ide-assists/src/handlers/convert_closure_to_fn.rs
index e6d31b9660..c9f5e0a4fb 100644
--- a/crates/ide-assists/src/handlers/convert_closure_to_fn.rs
+++ b/crates/ide-assists/src/handlers/convert_closure_to_fn.rs
@@ -739,6 +739,25 @@ fn main() {
}
#[test]
+ fn handles_closures_with_unannotated_rest_patterns() {
+ check_assist(
+ convert_closure_to_fn,
+ r#"
+fn main() {
+ let closure = |$0..| ();
+}
+"#,
+ r#"
+fn main() {
+ fn closure(..: _) {
+ ()
+ }
+}
+"#,
+ );
+ }
+
+ #[test]
fn multiple_capture_usages() {
check_assist(
convert_closure_to_fn,
diff --git a/crates/ide-assists/src/handlers/unwrap_branch.rs b/crates/ide-assists/src/handlers/unwrap_branch.rs
index a582af4e2c..bc296b05d4 100644
--- a/crates/ide-assists/src/handlers/unwrap_branch.rs
+++ b/crates/ide-assists/src/handlers/unwrap_branch.rs
@@ -832,6 +832,25 @@ fn main() {
}
#[test]
+ fn regression_22759() {
+ check_assist(
+ unwrap_branch,
+ r#"
+fn main() {
+ match () {
+ () $0=> let x = (),
+ }
+}
+"#,
+ r#"
+fn main() {
+ let x = ()
+}
+"#,
+ );
+ }
+
+ #[test]
fn simple_if_in_while_bad_cursor_position() {
check_assist_not_applicable(
unwrap_branch,
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 16fbf248ec..9017bae474 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -565,7 +565,17 @@ pub fn async_move_block_expr(
}
pub fn tail_only_block_expr(tail_expr: ast::Expr) -> ast::BlockExpr {
- ast_from_text(&format!("fn f() {{ {tail_expr} }}"))
+ quote! {
+ BlockExpr {
+ StmtList {
+ ['{']
+ " "
+ #tail_expr
+ " "
+ ['}']
+ }
+ }
+ }
}
/// Ideally this function wouldn't exist since it involves manual indenting.
@@ -1043,7 +1053,14 @@ pub fn untyped_param(pat: ast::Pat) -> ast::Param {
}
pub fn param(pat: ast::Pat, ty: ast::Type) -> ast::Param {
- ast_from_text(&format!("fn f({pat}: {ty}) {{ }}"))
+ quote! {
+ Param {
+ #pat
+ [:]
+ " "
+ #ty
+ }
+ }
}
pub fn self_param() -> ast::SelfParam {