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.
12 #[allow(clippy::trivially_copy_pass_by_ref)]
13 fn x(y: &i32) -> i32 {
17 #[warn(clippy::all, clippy::needless_borrow)]
18 #[allow(unused_variables)]
23 let s = &String::from("hi");
24 let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
25 let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
27 let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
28 h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
29 if let Some(ref cake) = Some(&5) {}
30 let garbl = match 42 {
34 &&a // FIXME: this should lint, too
41 fn f<T: Copy>(y: &T) -> T {
45 fn g(y: &[u8]) -> u8 {
51 impl<'a> Trait for &'a str {}
54 #[warn(clippy::needless_borrow)]
57 let mut v = Vec::<String>::new();
58 let _ = v.iter_mut().filter(|&ref a| a.is_empty());
59 let _ = v.iter().filter(|&ref a| a.is_empty());
61 let _ = v.iter().filter(|&a| a.is_empty());
65 #[warn(clippy::needless_borrow)]