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 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 {
61 // Don't lint. Removing the borrow would move 'x'
65 let y: &mut i32 = match 0 {
66 // Lint here. The type given above triggers auto-borrow.
70 fn ref_mut_i32(_: &mut i32) {}
72 // Lint here. The type given above triggers auto-borrow.
76 // use 'x' after to make sure it's still usable in the fixed code.
79 let s = String::new();
80 // let _ = (&s).len();
81 // let _ = (&s).capacity();
82 // let _ = (&&s).capacity();
86 let x = &x as *const (i32, i32);
87 let _ = unsafe { (*x).0 };
96 (&()).foo(); // Don't lint. `()` doesn't implement `Foo`
102 impl Foo for &'_ i32 {
105 (&5).foo(); // Don't lint. `5` will call `<i32 as Foo>::foo`
114 impl FooRef for &'_ () {
117 (&&()).foo_ref(); // Don't lint. `&()` will call `<() as FooRef>::foo_ref`
120 impl From<S> for u32 {
121 fn from(s: S) -> Self {
125 impl From<&S> for u32 {
126 fn from(s: &S) -> Self {
132 #[allow(clippy::needless_borrowed_reference)]
133 fn x(y: &i32) -> i32 {
137 fn mut_ref(y: &mut i32) {
141 fn f<T: Copy>(y: &T) -> T {
145 fn g(y: &[u8]) -> u8 {
151 impl<'a> Trait for &'a str {}
153 fn h(_: &dyn Trait) {}
156 fn check_expect_suppression() {
158 #[expect(clippy::needless_borrow)]
172 fn calls_field(&self) -> T {
181 fn calls_mut_field(&mut self) -> T {