Skip to content

Commit ada51f2

Browse files
bors[bot]VanneveljVeykril
authored
Merge #11195 #11202
11195: Correctly pass through reference modifiers when extracting a variable r=Veykril a=Vannevelj Fixes #10034 This will parse the field expression and look at whether it is marked `&` or `&mut` and include a modifier if appropriate. The original issue only mentions `&mut params` but I've found that this issue also occurs for `&mut locals` as well as `&params` and `&locals` so I've also added tests for them. I'd definitely be interested in hearing where I can make my code more idiomatic for Rust. 11202: fix: Fix `apply_demorgan` assist hanging for certain binary expressions r=Veykril a=Veykril Fixes #10963 bors r+ Co-authored-by: Jeroen Vannevel <[email protected]> Co-authored-by: Lukas Wirth <[email protected]>
3 parents 735b542 + 035a373 + b92ed11 commit ada51f2

File tree

2 files changed

+366
-5
lines changed

2 files changed

+366
-5
lines changed

crates/ide_assists/src/handlers/apply_demorgan.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
4242

4343
// Walk up the tree while we have the same binary operator
4444
while let Some(parent_expr) = expr.syntax().parent().and_then(ast::BinExpr::cast) {
45-
if let Some(parent_op) = expr.op_kind() {
46-
if parent_op == op {
47-
expr = parent_expr
45+
match expr.op_kind() {
46+
Some(parent_op) if parent_op == op => {
47+
expr = parent_expr;
4848
}
49+
_ => break,
4950
}
5051
}
5152

@@ -220,4 +221,14 @@ fn f() { !(S <= S || S < S) }
220221
cov_mark::check!(demorgan_double_parens);
221222
check_assist(apply_demorgan, "fn f() { (x ||$0 x) }", "fn f() { !(!x && !x) }")
222223
}
224+
225+
// https://github.com/rust-analyzer/rust-analyzer/issues/10963
226+
#[test]
227+
fn demorgan_doesnt_hang() {
228+
check_assist(
229+
apply_demorgan,
230+
"fn f() { 1 || 3 &&$0 4 || 5 }",
231+
"fn f() { !(!1 || !3 || !4) || 5 }",
232+
)
233+
}
223234
}

0 commit comments

Comments
 (0)