Skip to content

Commit 2270ff4

Browse files
committed
clippy_lint: Add test cases
1 parent b41b38c commit 2270ff4

File tree

2 files changed

+91
-10
lines changed

2 files changed

+91
-10
lines changed

tests/ui/ref_option_ref.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
#![allow(unused)]
22
#![warn(clippy::ref_option_ref)]
33

4-
type OptRefU32<'a> = &'a Option<&'a u32>;
5-
type OptRef<'a, T> = &'a Option<&'a T>;
4+
static THRESHOLD: i32 = 10;
5+
static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
6+
const CONST_THRESHOLD: &i32 = &10;
7+
const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD);
8+
9+
type RefOptRefU32<'a> = &'a Option<&'a u32>;
10+
type RefOptRef<'a, T> = &'a Option<&'a T>;
11+
12+
fn foo(data: &Option<&u32>) {}
13+
14+
fn bar(data: &u32) -> &Option<&u32> {
15+
&None
16+
}
17+
18+
struct StructRef<'a> {
19+
data: &'a Option<&'a u32>,
20+
}
21+
22+
struct StructTupleRef<'a>(u32, &'a Option<&'a u32>);
23+
24+
enum EnumRef<'a> {
25+
Variant1(u32),
26+
Variant2(&'a Option<&'a u32>),
27+
}
28+
29+
trait RefOptTrait {
30+
type A;
31+
fn foo(&self, _: Self::A);
32+
}
33+
34+
impl RefOptTrait for u32 {
35+
type A = &'static Option<&'static Self>;
36+
37+
fn foo(&self, _: Self::A) {}
38+
}
639

740
fn main() {
841
let x: &Option<&u32> = &None;

tests/ui/ref_option_ref.stderr

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
11
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
2-
--> $DIR/ref_option_ref.rs:4:22
2+
--> $DIR/ref_option_ref.rs:5:23
33
|
4-
LL | type OptRefU32<'a> = &'a Option<&'a u32>;
5-
| ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>`
4+
LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
5+
| ^^^^^^^^^^^^^ help: try: `Option<&i32>`
66
|
77
= note: `-D clippy::ref-option-ref` implied by `-D warnings`
88

99
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
10-
--> $DIR/ref_option_ref.rs:5:22
10+
--> $DIR/ref_option_ref.rs:7:18
1111
|
12-
LL | type OptRef<'a, T> = &'a Option<&'a T>;
13-
| ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>`
12+
LL | const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD);
13+
| ^^^^^^^^^^^^^ help: try: `Option<&i32>`
1414

1515
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
16-
--> $DIR/ref_option_ref.rs:8:12
16+
--> $DIR/ref_option_ref.rs:9:25
17+
|
18+
LL | type RefOptRefU32<'a> = &'a Option<&'a u32>;
19+
| ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>`
20+
21+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
22+
--> $DIR/ref_option_ref.rs:10:25
23+
|
24+
LL | type RefOptRef<'a, T> = &'a Option<&'a T>;
25+
| ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>`
26+
27+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
28+
--> $DIR/ref_option_ref.rs:12:14
29+
|
30+
LL | fn foo(data: &Option<&u32>) {}
31+
| ^^^^^^^^^^^^^ help: try: `Option<&u32>`
32+
33+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
34+
--> $DIR/ref_option_ref.rs:14:23
35+
|
36+
LL | fn bar(data: &u32) -> &Option<&u32> {
37+
| ^^^^^^^^^^^^^ help: try: `Option<&u32>`
38+
39+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
40+
--> $DIR/ref_option_ref.rs:19:11
41+
|
42+
LL | data: &'a Option<&'a u32>,
43+
| ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>`
44+
45+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
46+
--> $DIR/ref_option_ref.rs:22:32
47+
|
48+
LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>);
49+
| ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>`
50+
51+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
52+
--> $DIR/ref_option_ref.rs:26:14
53+
|
54+
LL | Variant2(&'a Option<&'a u32>),
55+
| ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>`
56+
57+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
58+
--> $DIR/ref_option_ref.rs:35:14
59+
|
60+
LL | type A = &'static Option<&'static Self>;
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>`
62+
63+
error: since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>
64+
--> $DIR/ref_option_ref.rs:41:12
1765
|
1866
LL | let x: &Option<&u32> = &None;
1967
| ^^^^^^^^^^^^^ help: try: `Option<&u32>`
2068

21-
error: aborting due to 3 previous errors
69+
error: aborting due to 11 previous errors
2270

0 commit comments

Comments
 (0)