Skip to content

Commit dc8d64d

Browse files
committed
feat: offer 'add_braces' on bin-expr assignment
Example --- ```rust fn foo() { let x; x =$0 n + 100; } ``` **Before this PR** Assist not applicable **After this PR** ```rust fn foo() { let x; x = { n + 100 }; } ```
1 parent 9bff35b commit dc8d64d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • src/tools/rust-analyzer/crates/ide-assists/src/handlers

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn get_replacement_node(ctx: &AssistContext<'_>) -> Option<(ParentType, ast::Exp
8484
match parent {
8585
ast::LetStmt(it) => it.initializer()?,
8686
ast::LetExpr(it) => it.expr()?,
87+
ast::BinExpr(it) => it.rhs()?,
8788
ast::Static(it) => it.body()?,
8889
ast::Const(it) => it.body()?,
8990
_ => return None,
@@ -192,6 +193,22 @@ fn foo() {
192193
n + 100
193194
};
194195
}
196+
"#,
197+
);
198+
199+
check_assist(
200+
add_braces,
201+
r#"
202+
fn foo() {
203+
if let x =$0 n + 100 {}
204+
}
205+
"#,
206+
r#"
207+
fn foo() {
208+
if let x = {
209+
n + 100
210+
} {}
211+
}
195212
"#,
196213
);
197214
}

0 commit comments

Comments
 (0)