]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/ref_option_ref.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / ref_option_ref.rs
CommitLineData
f20569fa
XL
1#![allow(unused)]
2#![warn(clippy::ref_option_ref)]
3
4// This lint is not tagged as run-rustfix because automatically
5// changing the type of a variable would also means changing
6// all usages of this variable to match and This is not handled
7// by this lint.
8
9static THRESHOLD: i32 = 10;
10static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
11const CONST_THRESHOLD: &i32 = &10;
cdc7bbd5 12const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD);
f20569fa
XL
13
14type RefOptRefU32<'a> = &'a Option<&'a u32>;
15type RefOptRef<'a, T> = &'a Option<&'a T>;
16
17fn foo(data: &Option<&u32>) {}
18
19fn bar(data: &u32) -> &Option<&u32> {
20 &None
21}
22
23struct StructRef<'a> {
24 data: &'a Option<&'a u32>,
25}
26
27struct StructTupleRef<'a>(u32, &'a Option<&'a u32>);
28
29enum EnumRef<'a> {
30 Variant1(u32),
31 Variant2(&'a Option<&'a u32>),
32}
33
34trait RefOptTrait {
35 type A;
36 fn foo(&self, _: Self::A);
37}
38
39impl RefOptTrait for u32 {
40 type A = &'static Option<&'static Self>;
41
42 fn foo(&self, _: Self::A) {}
43}
44
45fn main() {
46 let x: &Option<&u32> = &None;
47}