1 // FIXME: run-rustfix waiting on multi-span suggestions
2 
3 #![warn(clippy::ref_binding_to_reference)]
4 #![allow(clippy::needless_borrowed_reference)]
5 
f1(_: &str)6 fn f1(_: &str) {}
7 macro_rules! m2 {
8     ($e:expr) => {
9         f1(*$e)
10     };
11 }
12 macro_rules! m3 {
13     ($i:ident) => {
14         Some(ref $i)
15     };
16 }
17 
18 #[allow(dead_code)]
main()19 fn main() {
20     let x = String::new();
21 
22     // Ok, the pattern is from a macro
23     let _: &&String = match Some(&x) {
24         m3!(x) => x,
25         None => return,
26     };
27 
28     // Err, reference to a &String
29     let _: &&String = match Some(&x) {
30         Some(ref x) => x,
31         None => return,
32     };
33 
34     // Err, reference to a &String
35     let _: &&String = match Some(&x) {
36         Some(ref x) => {
37             f1(x);
38             f1(*x);
39             x
40         },
41         None => return,
42     };
43 
44     // Err, reference to a &String
45     match Some(&x) {
46         Some(ref x) => m2!(x),
47         None => return,
48     }
49 
50     // Err, reference to a &String
51     let _ = |&ref x: &&String| {
52         let _: &&String = x;
53     };
54 }
55 
56 // Err, reference to a &String
f2<'a>(&ref x: &&'a String) -> &'a String57 fn f2<'a>(&ref x: &&'a String) -> &'a String {
58     let _: &&String = x;
59     *x
60 }
61 
62 trait T1 {
63     // Err, reference to a &String
f(&ref x: &&String)64     fn f(&ref x: &&String) {
65         let _: &&String = x;
66     }
67 }
68 
69 struct S;
70 impl T1 for S {
71     // Err, reference to a &String
f(&ref x: &&String)72     fn f(&ref x: &&String) {
73         let _: &&String = x;
74     }
75 }
76