rust/crates
bors[bot] a8a25863f6
Merge #8436
8436: Fix extract function's mutability of variables outliving the body r=matklad a=brandondong

**Reproduction:**
```rust
fn main() {
    let mut k = 1;
    let mut j = 2;
    j += 1;
    k += j;
}
```
1. Select the first to third lines of the main function. Use the "Extract into function" code assist.
2. The output is the following which does not compile because the outlived variable `k` is declared as immutable:
```rust
fn main() {
    let (k, j) = fun_name();
    k += j;
}

fn fun_name() -> (i32, i32) {
    let mut k = 1;
    let mut j = 2;
    j += 1;
    (k, j)
}
```
3. We would instead expect the output to be:
```rust
fn main() {
    let (mut k, j) = fun_name();
    k += j;
}
```

**Fix:**
- Instead of declaring outlived variables as immutable unconditionally, check for any mutable usages outside of the extracted function.

Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-04-10 21:35:05 +00:00
..
base_db Adjust fixture docs a bit 2021-04-06 21:42:27 +03:00
cfg Make ast_to_token_tree infallible 2021-04-04 01:46:45 +02:00
flycheck
hir Improve indexing of impls 2021-04-09 11:21:31 +02:00
hir_def Avoid an unnecessary collect 2021-04-09 22:52:13 +02:00
hir_expand Revert "Rewrite #[derive] removal to be based on AST" 2021-04-10 20:30:28 +02:00
hir_ty Respect test style guidelines in tests::traits 2021-04-10 18:03:27 +02:00
ide Let's try testing for "is not quadratic" condition 2021-04-10 12:43:07 +03:00
ide_assists Merge #8436 2021-04-10 21:35:05 +00:00
ide_completion Use CompletionTextEdit::InsertAndReplace if supported by the client 2021-04-08 15:21:27 +02:00
ide_db Avoid O(n²) when constructing AttrSourceMap 2021-04-06 22:25:44 +02:00
ide_ssr
mbe Make ast_to_token_tree infallible 2021-04-04 01:46:45 +02:00
parser
paths Clearer naming 2021-04-06 16:22:26 +03:00
proc_macro_api
proc_macro_srv
proc_macro_test
profile
project_model feat: show errors from cargo metadata and initial cargo check in the status bar 2021-04-06 18:08:05 +03:00
rust-analyzer Merge #8410 2021-04-10 13:07:46 +00: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 Update crates 2021-04-07 11:39:33 -04:00
test_utils Let's try testing for "is not quadratic" condition 2021-04-10 12:43:07 +03:00
text_edit
toolchain
tt
vfs Avoid duplicating VfsPath in vfs::path_interner::PathInterner by using an IndexSet 2021-04-06 16:03:57 +03:00
vfs-notify