2021-06-03 01:41:37 -05:00
|
|
|
// FIXME: run-rustfix waiting on multi-span suggestions
|
2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix
|
2022-06-06 04:51:36 -05:00
|
|
|
#![feature(lint_reasons)]
|
2021-06-03 01:41:37 -05:00
|
|
|
#![warn(clippy::ref_binding_to_reference)]
|
2022-01-28 13:54:28 -06:00
|
|
|
#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)]
|
2021-06-03 01:41:37 -05:00
|
|
|
|
|
|
|
fn f1(_: &str) {}
|
|
|
|
macro_rules! m2 {
|
|
|
|
($e:expr) => {
|
2021-07-29 09:52:35 -05:00
|
|
|
f1(*$e)
|
2021-06-03 01:41:37 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
macro_rules! m3 {
|
|
|
|
($i:ident) => {
|
|
|
|
Some(ref $i)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn main() {
|
|
|
|
let x = String::new();
|
|
|
|
|
|
|
|
// Ok, the pattern is from a macro
|
|
|
|
let _: &&String = match Some(&x) {
|
|
|
|
m3!(x) => x,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Err, reference to a &String
|
|
|
|
let _: &&String = match Some(&x) {
|
|
|
|
Some(ref x) => x,
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
|
|
|
//~| NOTE: `-D clippy::ref-binding-to-reference` implied by `-D warnings`
|
2021-06-03 01:41:37 -05:00
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Err, reference to a &String
|
|
|
|
let _: &&String = match Some(&x) {
|
|
|
|
Some(ref x) => {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
f1(x);
|
|
|
|
f1(*x);
|
|
|
|
x
|
|
|
|
},
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Err, reference to a &String
|
|
|
|
match Some(&x) {
|
|
|
|
Some(ref x) => m2!(x),
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
None => return,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Err, reference to a &String
|
|
|
|
let _ = |&ref x: &&String| {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
let _: &&String = x;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Err, reference to a &String
|
|
|
|
fn f2<'a>(&ref x: &&'a String) -> &'a String {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
let _: &&String = x;
|
|
|
|
*x
|
|
|
|
}
|
|
|
|
|
|
|
|
trait T1 {
|
|
|
|
// Err, reference to a &String
|
|
|
|
fn f(&ref x: &&String) {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
let _: &&String = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
impl T1 for S {
|
|
|
|
// Err, reference to a &String
|
|
|
|
fn f(&ref x: &&String) {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this pattern creates a reference to a reference
|
2021-06-03 01:41:37 -05:00
|
|
|
let _: &&String = x;
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 04:51:36 -05:00
|
|
|
|
|
|
|
fn check_expect_suppression() {
|
|
|
|
let x = String::new();
|
|
|
|
#[expect(clippy::ref_binding_to_reference)]
|
|
|
|
let _: &&String = match Some(&x) {
|
|
|
|
Some(ref x) => x,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
}
|