mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-26 22:50:56 +00:00
Improve needless_borrowed_ref and update its stderr.
This commit is contained in:
parent
60ca61ee66
commit
fe57fdd15e
2 changed files with 54 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue