2 // FIXME: run-rustfix waiting on multi-span suggestions
4 #![warn(clippy::needless_borrow)]
5 #![allow(clippy::needless_borrowed_reference)]
18 macro_rules! if_chain {
19 (if $e:expr; $($rest:tt)*) => {
25 (if let $p:pat = $e:expr; $($rest:tt)*) => {
38 let x = String::new();
40 // Ok, reference to a String.
41 let _: &String = match Some(x.clone()) {
46 // Ok, reference to a &mut String
47 let _: &&mut String = match Some(&mut x.clone()) {
52 // Ok, the pattern is from a macro
53 let _: &String = match Some(&x) {
58 // Err, reference to a &String
59 let _: &String = match Some(&x) {
64 // Err, reference to a &String.
65 let _: &String = match Some(&x) {
70 // Err, reference to a &String
71 let _: &String = match Some(&x) {
80 // Err, reference to a &String
82 Some(ref x) => m1!(x),
86 // Err, reference to a &String
87 let _ = |&ref x: &&String| {
91 // Err, reference to a &String
100 // Err, reference to a &u32. Don't suggest adding a reference to the field access.
101 let _: u32 = match Some(&x) {
110 // Err, reference to &u32.
111 let _: &u32 = match E::A(&0) {
112 E::A(ref x) | E::B(ref x) => *x,
115 // Err, reference to &String.
118 if let Some(ref x) = Some(&String::new());
125 // Err, reference to a &String
126 fn f2<'a>(&ref x: &&'a String) -> &'a String {
132 // Err, reference to a &String
133 fn f(&ref x: &&String) {
140 // Err, reference to a &String
141 fn f(&ref x: &&String) {
146 // Ok - used to error due to rustc bug