diff options
| author | bors <bors@rust-lang.org> | 2017-08-10 08:53:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-10 08:53:22 +0000 |
| commit | d21ec9b4efd1da012979b050bc0a0426fe45fcdf (patch) | |
| tree | b33492318dcad1da9a032327304bd1b972d2a947 /src/librustc_data_structures | |
| parent | 2ac5f7d249e29ee48737359e0e6dd9e59701a568 (diff) | |
| parent | 8f78d453ded152e95d66f113d24287f12c680a15 (diff) | |
| download | rust-d21ec9b4efd1da012979b050bc0a0426fe45fcdf.tar.gz rust-d21ec9b4efd1da012979b050bc0a0426fe45fcdf.zip | |
Auto merge of #43582 - ivanbakel:unused_mut_ref, r=arielb1
Fixed mutable vars being marked used when they weren't
#### NB : bootstrapping is slow on my machine, even with `keep-stage` - fixes for occurances in the current codebase are <s>in the pipeline</s> done. This PR is being put up for review of the fix of the issue.
Fixes #43526, Fixes #30280, Fixes #25049
### Issue
Whenever the compiler detected a mutable deref being used mutably, it marked an associated value as being used mutably as well. In the case of derefencing local variables which were mutable references, this incorrectly marked the reference itself being used mutably, instead of its contents - with the consequence of making the following code emit no warnings
```
fn do_thing<T>(mut arg : &mut T) {
... // don't touch arg - just deref it to access the T
}
```
### Fix
Make dereferences not be counted as a mutable use, but only when they're on borrows on local variables.
#### Why not on things other than local variables?
* Whenever you capture a variable in a closure, it gets turned into a hidden reference - when you use it in the closure, it gets dereferenced. If the closure uses the variable mutably, that is actually a mutable use of the thing being dereffed to, so it has to be counted.
* If you deref a mutable `Box` to access the contents mutably, you are using the `Box` mutably - so it has to be counted.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/array_vec.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/bitvec.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/indexed_vec.rs | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/src/librustc_data_structures/array_vec.rs b/src/librustc_data_structures/array_vec.rs index ced73e9e426..df660d08603 100644 --- a/src/librustc_data_structures/array_vec.rs +++ b/src/librustc_data_structures/array_vec.rs @@ -260,7 +260,7 @@ impl<'a, A: Array> Drop for Drain<'a, A> { let start = source_array_vec.len(); let tail = self.tail_start; { - let mut arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>]; + let arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>]; let src = arr.as_ptr().offset(tail as isize); let dst = arr.as_mut_ptr().offset(start as isize); ptr::copy(src, dst, self.tail_len); diff --git a/src/librustc_data_structures/bitvec.rs b/src/librustc_data_structures/bitvec.rs index ffcd25a4cdd..7fc59be780f 100644 --- a/src/librustc_data_structures/bitvec.rs +++ b/src/librustc_data_structures/bitvec.rs @@ -166,7 +166,7 @@ impl BitMatrix { pub fn add(&mut self, source: usize, target: usize) -> bool { let (start, _) = self.range(source); let (word, mask) = word_mask(target); - let mut vector = &mut self.vector[..]; + let vector = &mut self.vector[..]; let v1 = vector[start + word]; let v2 = v1 | mask; vector[start + word] = v2; diff --git a/src/librustc_data_structures/indexed_vec.rs b/src/librustc_data_structures/indexed_vec.rs index 29ac650aa70..1f44378c9e6 100644 --- a/src/librustc_data_structures/indexed_vec.rs +++ b/src/librustc_data_structures/indexed_vec.rs @@ -259,7 +259,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> { type IntoIter = slice::IterMut<'a, T>; #[inline] - fn into_iter(mut self) -> slice::IterMut<'a, T> { + fn into_iter(self) -> slice::IterMut<'a, T> { self.raw.iter_mut() } } |
