diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-10 22:35:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-10 22:35:05 +0100 |
commit | a8a25863f6e1e6da94b60813b2daee73b55132f7 (patch) | |
tree | 1e2b90d4196867eb1326d19bac70be8a5847a26e /crates/profile/src/hprof.rs | |
parent | bd675c8a8bdd3fda239bee3d3f31acd8679655b9 (diff) | |
parent | c989287a34b8b27fa4880d27e698bd880631a794 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates/profile/src/hprof.rs')
0 files changed, 0 insertions, 0 deletions