Improve needless_borrowed_ref and update its stderr.

This commit is contained in:
Benoît CORTIER 2017-07-01 12:02:00 +02:00 committed by Oliver Schneider
parent 60ca61ee66
commit fe57fdd15e
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 54 additions and 10 deletions

View file

@ -8,13 +8,24 @@ fn main() {
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
// ^ should be linted
let mut var = 5;
let thingy = Some(&mut var);
if let Some(&mut ref v) = thingy {
let var = 3;
let thingy = Some(&var);
if let Some(&ref v) = thingy {
// ^ should be linted
}
let mut var2 = 5;
let thingy2 = Some(&mut var2);
if let Some(&mut ref mut v) = thingy2 {
// ^ should *not* be linted
// here, var is borrowed as immutable.
// v is borrowed as mutable.
*v = 10;
}
if let Some(&mut ref v) = thingy2 {
// ^ should *not* be linted
// here, v is borrowed as immutable.
// can't do that:
//*v = 10;
//*v = 15;
}
}

View file

@ -1,8 +1,41 @@
warning: this pattern takes a reference on something that is being de-referenced
--> needless_borrowed_ref.rs:7:35
error: this pattern takes a reference on something that is being de-referenced
--> examples/needless_borrowed_ref.rs:8:34
|
7 | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
| ^^^^^
8 | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
| ^^^^^^ help: try removing the `&ref` part and just keep `a`
|
= note: #[warn(needless_borrowed_reference)] on by default
= note: `-D needless-borrowed-reference` implied by `-D warnings`
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
error: this pattern takes a reference on something that is being de-referenced
--> examples/needless_borrowed_ref.rs:13:17
|
13 | if let Some(&ref v) = thingy {
| ^^^^^^ help: try removing the `&ref` part and just keep `v`
|
= note: `-D needless-borrowed-reference` implied by `-D warnings`
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
error: this pattern takes a reference on something that is being de-referenced
--> examples/needless_borrowed_ref.rs:42:27
|
42 | (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
| ^^^^^^ help: try removing the `&ref` part and just keep `k`
|
= note: `-D needless-borrowed-reference` implied by `-D warnings`
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
error: this pattern takes a reference on something that is being de-referenced
--> examples/needless_borrowed_ref.rs:42:38
|
42 | (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
| ^^^^^^ help: try removing the `&ref` part and just keep `k`
|
= note: `-D needless-borrowed-reference` implied by `-D warnings`
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
error: aborting due to previous error(s)
error: Could not compile `clippy_tests`.
To learn more, run the command again with --verbose.