Skip to content

Commit c9c6fa8

Browse files
bors[bot]yue4u
andauthored
Merge #10821
10821: fix: wrap `inline_call` and `inline_into_callers` if it inlines into the left side of a binary expression r=Veykril a=rainy-me close #10359 Co-authored-by: rainy-me <[email protected]>
2 parents 55b7a06 + ebffaa4 commit c9c6fa8

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

crates/ide_assists/src/handlers/inline_call.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,17 @@ fn inline(
407407

408408
match body.tail_expr() {
409409
Some(expr) if body.statements().next().is_none() => expr,
410-
_ => ast::Expr::BlockExpr(body),
410+
_ => match node
411+
.syntax()
412+
.parent()
413+
.and_then(ast::BinExpr::cast)
414+
.and_then(|bin_expr| bin_expr.lhs())
415+
{
416+
Some(lhs) if lhs.syntax() == node.syntax() => {
417+
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update()
418+
}
419+
_ => ast::Expr::BlockExpr(body),
420+
},
411421
}
412422
}
413423

@@ -1076,4 +1086,60 @@ fn main() {
10761086
"#,
10771087
);
10781088
}
1089+
1090+
#[test]
1091+
fn inline_callers_wrapped_in_parentheses() {
1092+
check_assist(
1093+
inline_into_callers,
1094+
r#"
1095+
fn foo$0() -> u32 {
1096+
let x = 0;
1097+
x
1098+
}
1099+
fn bar() -> u32 {
1100+
foo() + foo()
1101+
}
1102+
"#,
1103+
r#"
1104+
1105+
fn bar() -> u32 {
1106+
({
1107+
let x = 0;
1108+
x
1109+
}) + {
1110+
let x = 0;
1111+
x
1112+
}
1113+
}
1114+
"#,
1115+
)
1116+
}
1117+
1118+
#[test]
1119+
fn inline_call_wrapped_in_parentheses() {
1120+
check_assist(
1121+
inline_call,
1122+
r#"
1123+
fn foo() -> u32 {
1124+
let x = 0;
1125+
x
1126+
}
1127+
fn bar() -> u32 {
1128+
foo$0() + foo()
1129+
}
1130+
"#,
1131+
r#"
1132+
fn foo() -> u32 {
1133+
let x = 0;
1134+
x
1135+
}
1136+
fn bar() -> u32 {
1137+
({
1138+
let x = 0;
1139+
x
1140+
}) + foo()
1141+
}
1142+
"#,
1143+
)
1144+
}
10791145
}

0 commit comments

Comments
 (0)