1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
15 #[allow(clippy::trivially_copy_pass_by_ref)]
16 fn x(y: &i32) -> i32 {
20 #[warn(clippy::all, clippy::needless_borrow)]
21 #[allow(unused_variables)]
26 let s = &String::from("hi");
27 let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
28 let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
30 let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
31 h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
32 if let Some(ref cake) = Some(&5) {}
33 let garbl = match 42 {
37 &&a // FIXME: this should lint, too
44 fn f<T:Copy>(y: &T) -> T {
48 fn g(y: &[u8]) -> u8 {
54 impl<'a> Trait for &'a str {}
57 #[warn(clippy::needless_borrow)]
60 let mut v = Vec::<String>::new();
61 let _ = v.iter_mut().filter(|&ref a| a.is_empty());
62 let _ = v.iter().filter(|&ref a| a.is_empty());
64 let _ = v.iter().filter(|&a| a.is_empty());
68 #[warn(clippy::needless_borrow)]