rust/crates
bors[bot] e7a8977358
Merge #8524 #8527
8524: Fix extract function with partial block selection r=matklad a=brandondong

**Reproduction:**
```rust
fn foo() {
    let n = 1;
    let mut v = $0n * n;$0
    v += 1;
}
```
1. Select the snippet ($0) and use the "Extract into function" assist.
2. Extracted function is incorrect and does not compile:
```rust
fn foo() {
    let n = 1;
    let mut v = fun_name(n);
    v += 1;
}

fn fun_name(n: i32) {}
```
3. Omitting the ending semicolon from the selection fixes the extracted function:
```rust
fn fun_name(n: i32) -> i32 {
    n * n
}
```

**Cause:**
- When `extraction_target` uses a block extraction (semicolon case) instead of an expression extraction (no semicolon case), the user selection is directly used as the TextRange.
- However, the existing function extraction logic for blocks requires that the TextRange spans from start to end of complete statements to work correctly.
- For example:
```rust
fn foo() {
    let m = 2;
    let n = 1;
    let mut v = m $0* n;
    let mut w = 3;$0
    v += 1;
    w += 1;
}
```
produces
```rust
fn foo() {
    let m = 2;
    let n = 1;
    let mut v = m let mut w = fun_name(n);
    v += 1;
    w += 1;
}

fn fun_name(n: i32) -> i32 {
    let mut w = 3;
    w
}
```
- The user selected TextRange is directly replaced by the function call which is now in the middle of another statement. The extracted function body only contains statements that were fully covered by the TextRange and so the `* n` code is deleted. The logic for calculating variable usage and outlived variables for the function parameters and return type respectively search within the TextRange and so do not include `m` or `v`.

**Fix:**
- Only extract full statements when using block extraction. If a user selected part of a statement, extract that full statement.

8527: Switch introduce_named_lifetime assist to use mutable syntax tree  r=matklad a=iDawer

This extends `GenericParamsOwnerEdit` trait with `get_or_create_generic_param_list` method

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-04-19 13:09:18 +00:00
..
base_db Add some more error messages to fixture failure cases 2021-04-17 21:34:14 +02:00
cfg Make ast_to_token_tree infallible 2021-04-04 01:46:45 +02:00
flycheck Bump cargo_metadata 2021-03-02 14:27:29 +02:00
hir hir_ty: deal with TypeRef::Macro in HirFormatter 2021-04-17 16:24:56 +02:00
hir_def Merge #8462 2021-04-19 13:01:30 +00:00
hir_expand Merge #8462 2021-04-19 13:01:30 +00:00
hir_ty Merge #8462 2021-04-19 13:01:30 +00:00
ide Check for rust doc code attributes like rustdoc does 2021-04-19 13:32:52 +02:00
ide_assists Merge #8524 #8527 2021-04-19 13:09:18 +00:00
ide_completion Exclude inherent traits from flyimports 2021-04-16 11:13:17 +03:00
ide_db Check for rust doc code attributes like rustdoc does 2021-04-19 13:32:52 +02:00
ide_ssr syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
mbe Merge #8560 2021-04-18 02:14:27 +00:00
parser hir_ty: Expand macros at type position 2021-04-17 16:24:56 +02:00
paths Clearer naming 2021-04-06 16:22:26 +03:00
proc_macro_api Trim down IPC json size 2021-03-24 15:01:37 +08:00
proc_macro_srv Fix parse u128 bug in proc-macro 2021-03-31 19:50:36 +08:00
proc_macro_test Add description for crates that will be published 2020-08-24 13:07:22 +02:00
profile internal: revive google_cpu_profile infra 2021-03-30 17:29:43 +03:00
project_model feat: avoid checking the whole project during initial loading 2021-04-12 15:29:31 +03:00
rust-analyzer Check for rust doc code attributes like rustdoc does 2021-04-19 13:32:52 +02:00
stdx feat: show errors from cargo metadata and initial cargo check in the status bar 2021-04-06 18:08:05 +03:00
syntax Merge #8524 #8527 2021-04-19 13:09:18 +00:00
test_utils internal: fix flakiness of accidentally quadratic test 2021-04-13 12:56:24 +03:00
text_edit Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
toolchain Add description for crates that will be published 2020-08-24 13:07:22 +02:00
tt a lot of clippy::style fixes 2021-03-21 16:15:41 +01:00
vfs Avoid duplicating VfsPath in vfs::path_interner::PathInterner by using an IndexSet 2021-04-06 16:03:57 +03:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00