mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 19:12:50 +00:00
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 <github@yue.coffee>
This commit is contained in:
commit
c9c6fa8f56
@ -407,7 +407,17 @@ fn inline(
|
||||
|
||||
match body.tail_expr() {
|
||||
Some(expr) if body.statements().next().is_none() => expr,
|
||||
_ => ast::Expr::BlockExpr(body),
|
||||
_ => match node
|
||||
.syntax()
|
||||
.parent()
|
||||
.and_then(ast::BinExpr::cast)
|
||||
.and_then(|bin_expr| bin_expr.lhs())
|
||||
{
|
||||
Some(lhs) if lhs.syntax() == node.syntax() => {
|
||||
make::expr_paren(ast::Expr::BlockExpr(body)).clone_for_update()
|
||||
}
|
||||
_ => ast::Expr::BlockExpr(body),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1076,4 +1086,60 @@ fn main() {
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_callers_wrapped_in_parentheses() {
|
||||
check_assist(
|
||||
inline_into_callers,
|
||||
r#"
|
||||
fn foo$0() -> u32 {
|
||||
let x = 0;
|
||||
x
|
||||
}
|
||||
fn bar() -> u32 {
|
||||
foo() + foo()
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
|
||||
fn bar() -> u32 {
|
||||
({
|
||||
let x = 0;
|
||||
x
|
||||
}) + {
|
||||
let x = 0;
|
||||
x
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_call_wrapped_in_parentheses() {
|
||||
check_assist(
|
||||
inline_call,
|
||||
r#"
|
||||
fn foo() -> u32 {
|
||||
let x = 0;
|
||||
x
|
||||
}
|
||||
fn bar() -> u32 {
|
||||
foo$0() + foo()
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
fn foo() -> u32 {
|
||||
let x = 0;
|
||||
x
|
||||
}
|
||||
fn bar() -> u32 {
|
||||
({
|
||||
let x = 0;
|
||||
x
|
||||
}) + foo()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user