Update needless_borrowed_ref lint example.

This commit is contained in:
Benoît CORTIER 2017-06-30 16:07:29 +02:00 committed by Oliver Schneider
parent b1d93a595c
commit d170e765de
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9

View File

@ -2,8 +2,36 @@
#![plugin(clippy)]
#[warn(needless_borrowed_reference)]
#[allow(unused_variables)]
fn main() {
let mut v = Vec::<String>::new();
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 {
// ^ should *not* be linted
// here, var is borrowed as immutable.
// can't do that:
//*v = 10;
}
}
#[allow(dead_code)]
enum Animal {
Cat(u64),
Dog(u64),
}
#[allow(unused_variables)]
#[allow(dead_code)]
fn foo(a: &Animal, b: &Animal) {
match (a, b) {
(&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
// ^ and ^ should *not* be linted
(&Animal::Dog(ref a), &Animal::Dog(_)) => ()
// ^ should *not* be linted
}
}