3 #![feature(lint_reasons)]
5 #[warn(clippy::all, clippy::needless_borrow)]
6 #[allow(unused_variables, clippy::unnecessary_mut_passed)]
10 let _ = x(&a); // no warning
11 let _ = x(&&a); // warn
14 mut_ref(&mut b); // no warning
15 mut_ref(&mut &mut b); // warn
17 let s = &String::from("hi");
18 let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
19 let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
21 let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
22 h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
23 let garbl = match 42 {
57 let y: &mut i32 = &mut x;
58 let y: &mut i32 = &mut &mut x;
61 // Don't lint. Removing the borrow would move 'x'
68 let s = String::new();
69 // let _ = (&s).len();
70 // let _ = (&s).capacity();
71 // let _ = (&&s).capacity();
75 let x = &x as *const (i32, i32);
76 let _ = unsafe { (&*x).0 };
79 #[allow(clippy::needless_borrowed_reference)]
80 fn x(y: &i32) -> i32 {
84 fn mut_ref(y: &mut i32) {
88 fn f<T: Copy>(y: &T) -> T {
92 fn g(y: &[u8]) -> u8 {
98 impl<'a> Trait for &'a str {}
100 fn h(_: &dyn Trait) {}
103 fn check_expect_suppression() {
105 #[expect(clippy::needless_borrow)]