mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Add a test showing a false positive on needless_borrow
This commit is contained in:
parent
eb93058dd5
commit
866239b1a8
2 changed files with 21 additions and 4 deletions
|
@ -18,6 +18,15 @@ fn main() {
|
|||
let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
|
||||
h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
|
||||
if let Some(ref cake) = Some(&5) {}
|
||||
let garbl = match 42 {
|
||||
44 => &a,
|
||||
45 => {
|
||||
println!("foo");
|
||||
&&a // FIXME: this should lint, too
|
||||
},
|
||||
46 => &&a,
|
||||
_ => panic!(),
|
||||
};
|
||||
}
|
||||
|
||||
fn f<T:Copy>(y: &T) -> T {
|
||||
|
|
|
@ -19,13 +19,21 @@ error: this pattern creates a reference to a reference
|
|||
|
|
||||
= note: #[deny(needless_borrow)] implied by #[deny(clippy)]
|
||||
|
||||
warning: this pattern creates a reference to a reference
|
||||
--> $DIR/needless_borrow.rs:41:31
|
||||
error: this expression borrows a reference that is immediately dereferenced by the compiler
|
||||
--> $DIR/needless_borrow.rs:27:15
|
||||
|
|
||||
41 | let _ = v.iter().filter(|&ref a| a.is_empty());
|
||||
27 | 46 => &&a,
|
||||
| ^^^
|
||||
|
|
||||
= note: #[deny(needless_borrow)] implied by #[deny(clippy)]
|
||||
|
||||
warning: this pattern creates a reference to a reference
|
||||
--> $DIR/needless_borrow.rs:50:31
|
||||
|
|
||||
50 | let _ = v.iter().filter(|&ref a| a.is_empty());
|
||||
| ^^^^^
|
||||
|
|
||||
= note: #[warn(needless_borrow)] on by default
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue