1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
//@aux-build:../../ui/auxiliary/proc_macros.rs
//@revisions: private all
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/private
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/all
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
#![warn(clippy::ref_option)]
fn opt_u8(a: Option<&u8>) {}
//~^ ref_option
fn opt_gen<T>(a: Option<&T>) {}
//~^ ref_option
fn opt_string(a: std::option::Option<&String>) {}
//~^ ref_option
fn ret_u8<'a>(p: &'a str) -> Option<&'a u8> {
//~^ ref_option
panic!()
}
fn ret_u8_static() -> Option<&'static u8> {
//~^ ref_option
panic!()
}
fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
//~^ ref_option
fn ret_box<'a>() -> Option<&'a Box<u8>> {
//~^ ref_option
panic!()
}
pub fn pub_opt_string(a: Option<&String>) {}
//~[all]^ ref_option
pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
//~[all]^ ref_option
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: Option<&()>) {}
//~[all]^ ref_option
pub fn pub_opt_ret(&self) -> Option<&String> {
//~[all]^ ref_option
panic!()
}
fn private_opt_params(&self, a: Option<&()>) {}
//~^ ref_option
fn private_opt_ret(&self) -> Option<&String> {
//~^ ref_option
panic!()
}
}
// valid, don't change
fn mut_u8(a: &mut Option<u8>) {}
pub fn pub_mut_u8(a: &mut Option<String>) {}
// might be good to catch in the future
fn mut_u8_ref(a: &mut &Option<u8>) {}
pub fn pub_mut_u8_ref(a: &mut &Option<String>) {}
fn lambdas() {
// Not handled for now, not sure if we should
let x = |a: &Option<String>| {};
let x = |a: &Option<String>| -> &Option<String> { panic!() };
}
pub mod external {
proc_macros::external!(
fn opt_u8(a: &Option<u8>) {}
fn ret_u8<'a>(p: &'a str) -> &'a Option<u8> {
panic!()
}
pub fn pub_opt_u8(a: &Option<u8>) {}
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: &Option<()>) {}
pub fn pub_opt_ret(&self) -> &Option<String> {
panic!()
}
fn private_opt_params(&self, a: &Option<()>) {}
fn private_opt_ret(&self) -> &Option<String> {
panic!()
}
}
);
}
pub mod proc_macros {
proc_macros::with_span!(
span
fn opt_u8(a: &Option<u8>) {}
fn ret_u8<'a>(p: &'a str) -> &'a Option<u8> {
panic!()
}
pub fn pub_opt_u8(a: &Option<u8>) {}
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: &Option<()>) {}
pub fn pub_opt_ret(&self) -> &Option<String> {
panic!()
}
fn private_opt_params(&self, a: &Option<()>) {}
fn private_opt_ret(&self) -> &Option<String> {
panic!()
}
}
);
}
fn main() {}
|