Code action for inlining functions #5883
Replies: 3 comments 15 replies
-
|
Hello! When it would this be available? How would name collisions be handled? What about anonymous functions passed to the function? |
Beta Was this translation helpful? Give feedback.
-
|
Maybe for naming conflicts (from arguments, not anon fns), it could declare any conflicting arguments at the top of the inlined block. rust-analyzer does this for all arguments when inlining regardless of whether or not there is a naming conflict. e.g. after inlining fn main() {
let wibble = 42
let wabble = 10
wobble(wibble, wabble)
}
fn wobble(foo, bar) {
let wibble = 22
echo { wibble + foo + bar }
}becomes fn main() {
let wibble = 42
let wabble = 10
{
let foo = wibble
let wibble = 22
echo { wibble + foo + wabble }
}
} |
Beta Was this translation helpful? Give feedback.
-
|
rust-analyzer apparently just ignores the naming conflict problem with closures: let this = 5;
let _: Result<_, ()> = Ok(42).map(|num| num + this);becomes let this = 5;
let _: Result<_, ()> = {
let this = Ok(42);
match this {
Ok(t) => Ok((|num| num + this)(t)),
// Errors because `this` ^^^^ has a type of Result, not i32
Err(e) => Err(e),
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Related to #5808
Given a code like this:
It would be useful to produce the following output after running a code action:
This could be viewed as inlining
result.mapfunction's body since this is how it is defined:Beta Was this translation helpful? Give feedback.
All reactions