diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-05 11:04:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-05 11:04:58 +0000 |
commit | 5c10f2f705d6757b9821387a5be759789b7ee480 (patch) | |
tree | 961570d2245c2e62ce7f20c2437fe5d8abb92166 /crates/assists/src/tests | |
parent | 4bc1ed7d592819bf2a29f7be376e0c09f190c345 (diff) | |
parent | 7b4b4ef02681053299dda5111c0d4b0113e29224 (diff) |
Merge #7131
7131: Created an assist for inlining a function's body into its caller r=matklad a=Michael-F-Bryan
This introduces an `inline_function` assist which will convert code like this:
```rust
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() {
let x = add<|>(1, 2);
}
```
Into something like this:
```rust
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() {
let x = {
let a = 1;
let b = 2;
a + b
};
}
```
Fixes #6863.
Co-authored-by: Michael-F-Bryan <[email protected]>
Diffstat (limited to 'crates/assists/src/tests')
-rw-r--r-- | crates/assists/src/tests/generated.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 85e3c6742..b15352cf3 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs | |||
@@ -531,6 +531,29 @@ fn foo() -> i32 { 42i32 } | |||
531 | } | 531 | } |
532 | 532 | ||
533 | #[test] | 533 | #[test] |
534 | fn doctest_inline_function() { | ||
535 | check_doc_test( | ||
536 | "inline_function", | ||
537 | r#####" | ||
538 | fn add(a: u32, b: u32) -> u32 { a + b } | ||
539 | fn main() { | ||
540 | let x = add<|>(1, 2); | ||
541 | } | ||
542 | "#####, | ||
543 | r#####" | ||
544 | fn add(a: u32, b: u32) -> u32 { a + b } | ||
545 | fn main() { | ||
546 | let x = { | ||
547 | let a = 1; | ||
548 | let b = 2; | ||
549 | a + b | ||
550 | }; | ||
551 | } | ||
552 | "#####, | ||
553 | ) | ||
554 | } | ||
555 | |||
556 | #[test] | ||
534 | fn doctest_inline_local_variable() { | 557 | fn doctest_inline_local_variable() { |
535 | check_doc_test( | 558 | check_doc_test( |
536 | "inline_local_variable", | 559 | "inline_local_variable", |