1 // FIXME: run-rustfix waiting on multi-span suggestions
3 #![warn(clippy::needless_borrow)]
4 #![allow(clippy::needless_borrowed_reference)]
17 macro_rules! if_chain {
18 (if $e:expr; $($rest:tt)*) => {
24 (if let $p:pat = $e:expr; $($rest:tt)*) => {
37 let x = String::new();
39 // Ok, reference to a String.
40 let _: &String = match Some(x.clone()) {
45 // Ok, reference to a &mut String
46 let _: &&mut String = match Some(&mut x.clone()) {
51 // Ok, the pattern is from a macro
52 let _: &String = match Some(&x) {
57 // Err, reference to a &String
58 let _: &String = match Some(&x) {
63 // Err, reference to a &String.
64 let _: &String = match Some(&x) {
69 // Err, reference to a &String
70 let _: &String = match Some(&x) {
79 // Err, reference to a &String
81 Some(ref x) => m1!(x),
85 // Err, reference to a &String
86 let _ = |&ref x: &&String| {
90 // Err, reference to a &String
99 // Err, reference to a &u32. Don't suggest adding a reference to the field access.
100 let _: u32 = match Some(&x) {
109 // Err, reference to &u32.
110 let _: &u32 = match E::A(&0) {
111 E::A(ref x) | E::B(ref x) => *x,
114 // Err, reference to &String.
117 if let Some(ref x) = Some(&String::new());
124 // Err, reference to a &String
125 fn f2<'a>(&ref x: &&'a String) -> &'a String {
131 // Err, reference to a &String
132 fn f(&ref x: &&String) {
139 // Err, reference to a &String
140 fn f(&ref x: &&String) {
145 // Ok - used to error due to rustc bug