2020-10-13 20:13:54 +00:00
|
|
|
#![allow(unused)]
|
2020-10-12 21:58:59 +00:00
|
|
|
#![warn(clippy::ref_option_ref)]
|
2023-07-27 11:40:22 +00:00
|
|
|
//@no-rustfix
|
2020-10-26 21:50:13 +00:00
|
|
|
// This lint is not tagged as run-rustfix because automatically
|
|
|
|
// changing the type of a variable would also means changing
|
|
|
|
// all usages of this variable to match and This is not handled
|
|
|
|
// by this lint.
|
|
|
|
|
2020-10-15 19:56:56 +00:00
|
|
|
static THRESHOLD: i32 = 10;
|
|
|
|
static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
|
|
|
//~| NOTE: `-D clippy::ref-option-ref` implied by `-D warnings`
|
2020-10-15 19:56:56 +00:00
|
|
|
const CONST_THRESHOLD: &i32 = &10;
|
2021-04-02 21:35:32 +00:00
|
|
|
const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
|
|
|
|
type RefOptRefU32<'a> = &'a Option<&'a u32>;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
type RefOptRef<'a, T> = &'a Option<&'a T>;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
|
|
|
|
fn foo(data: &Option<&u32>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
|
|
|
|
fn bar(data: &u32) -> &Option<&u32> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
&None
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StructRef<'a> {
|
|
|
|
data: &'a Option<&'a u32>,
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to
|
2020-10-15 19:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct StructTupleRef<'a>(u32, &'a Option<&'a u32>);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt
|
2020-10-15 19:56:56 +00:00
|
|
|
|
|
|
|
enum EnumRef<'a> {
|
|
|
|
Variant1(u32),
|
|
|
|
Variant2(&'a Option<&'a u32>),
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to
|
2020-10-15 19:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trait RefOptTrait {
|
|
|
|
type A;
|
|
|
|
fn foo(&self, _: Self::A);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RefOptTrait for u32 {
|
|
|
|
type A = &'static Option<&'static Self>;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to
|
2020-10-15 19:56:56 +00:00
|
|
|
|
|
|
|
fn foo(&self, _: Self::A) {}
|
|
|
|
}
|
2020-10-13 20:13:54 +00:00
|
|
|
|
2020-10-12 21:58:59 +00:00
|
|
|
fn main() {
|
|
|
|
let x: &Option<&u32> = &None;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to
|
2020-10-12 21:58:59 +00:00
|
|
|
}
|
2022-10-21 11:48:41 +00:00
|
|
|
|
|
|
|
fn issue9682(arg: &Option<&mut String>) {
|
|
|
|
// Should not lint, as the inner ref is mutable making it non `Copy`
|
|
|
|
println!("{arg:?}");
|
|
|
|
}
|