Skip to content

Commit 25cf36a

Browse files
committed
clean-up
- move tests to `ui-toml/`, since they all use `clippy.toml` - remove the trait test case from `ref_option.rs`, because it's already covered by `ref_option_traits.rs`
1 parent 9f02cbc commit 25cf36a

File tree

11 files changed

+58
-152
lines changed

11 files changed

+58
-152
lines changed

clippy_lints/src/functions/ref_option.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ use crate::functions::REF_OPTION;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_trait_impl_item;
44
use clippy_utils::source::snippet;
5-
use clippy_utils::ty::is_type_diagnostic_item;
5+
use clippy_utils::ty::option_arg_ty;
66
use rustc_errors::Applicability;
7-
use rustc_hir as hir;
87
use rustc_hir::intravisit::FnKind;
9-
use rustc_hir::{FnDecl, HirId};
8+
use rustc_hir::{self as hir, FnDecl, HirId};
109
use rustc_lint::LateContext;
11-
use rustc_middle::ty::{self, GenericArgKind, Mutability, Ty};
10+
use rustc_middle::ty::{self, Mutability, Ty};
11+
use rustc_span::Span;
1212
use rustc_span::def_id::LocalDefId;
13-
use rustc_span::{Span, sym};
1413

15-
fn check_ty<'a>(cx: &LateContext<'a>, param: &rustc_hir::Ty<'a>, param_ty: Ty<'a>, fixes: &mut Vec<(Span, String)>) {
14+
fn check_ty<'a>(cx: &LateContext<'a>, param: &hir::Ty<'a>, param_ty: Ty<'a>, fixes: &mut Vec<(Span, String)>) {
1615
if let ty::Ref(_, opt_ty, Mutability::Not) = param_ty.kind()
17-
&& is_type_diagnostic_item(cx, *opt_ty, sym::Option)
18-
&& let ty::Adt(_, opt_gen_args) = opt_ty.kind()
19-
&& let [gen_arg] = opt_gen_args.as_slice()
20-
&& let GenericArgKind::Type(gen_ty) = gen_arg.kind()
16+
&& let Some(gen_ty) = option_arg_ty(cx, *opt_ty)
2117
&& !gen_ty.is_ref()
2218
// Need to gen the original spans, so first parsing mid, and hir parsing afterward
2319
&& let hir::TyKind::Ref(lifetime, hir::MutTy { ty, .. }) = param.kind
File renamed without changes.
File renamed without changes.

tests/ui/ref_option/ref_option.all.fixed renamed to tests/ui-toml/ref_option/ref_option.all.fixed

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@revisions: private all
2-
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
3-
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
2+
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/private
3+
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/all
44

55
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
66
#![warn(clippy::ref_option)]
@@ -11,11 +11,11 @@ fn opt_gen<T>(a: Option<&T>) {}
1111
//~^ ref_option
1212
fn opt_string(a: std::option::Option<&String>) {}
1313
//~^ ref_option
14-
fn ret_string<'a>(p: &'a str) -> Option<&'a u8> {
14+
fn ret_u8<'a>(p: &'a str) -> Option<&'a u8> {
1515
//~^ ref_option
1616
panic!()
1717
}
18-
fn ret_string_static() -> Option<&'static u8> {
18+
fn ret_u8_static() -> Option<&'static u8> {
1919
//~^ ref_option
2020
panic!()
2121
}
@@ -31,20 +31,6 @@ pub fn pub_opt_string(a: Option<&String>) {}
3131
pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
3232
//~[all]^ ref_option
3333

34-
pub trait PubTrait {
35-
fn pub_trait_opt(&self, a: Option<&Vec<u8>>);
36-
//~[all]^ ref_option
37-
fn pub_trait_ret(&self) -> Option<&Vec<u8>>;
38-
//~[all]^ ref_option
39-
}
40-
41-
trait PrivateTrait {
42-
fn trait_opt(&self, a: Option<&String>);
43-
//~^ ref_option
44-
fn trait_ret(&self) -> Option<&String>;
45-
//~^ ref_option
46-
}
47-
4834
pub struct PubStruct;
4935

5036
impl PubStruct {
Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
2-
--> tests/ui/ref_option/ref_option.rs:8:1
2+
--> tests/ui-toml/ref_option/ref_option.rs:8:1
33
|
44
LL | fn opt_u8(a: &Option<u8>) {}
55
| ^^^^^^^^^^^^^-----------^^^^
@@ -10,26 +10,26 @@ LL | fn opt_u8(a: &Option<u8>) {}
1010
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
1111

1212
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
13-
--> tests/ui/ref_option/ref_option.rs:10:1
13+
--> tests/ui-toml/ref_option/ref_option.rs:10:1
1414
|
1515
LL | fn opt_gen<T>(a: &Option<T>) {}
1616
| ^^^^^^^^^^^^^^^^^----------^^^^
1717
| |
1818
| help: change this to: `Option<&T>`
1919

2020
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
21-
--> tests/ui/ref_option/ref_option.rs:12:1
21+
--> tests/ui-toml/ref_option/ref_option.rs:12:1
2222
|
2323
LL | fn opt_string(a: &std::option::Option<String>) {}
2424
| ^^^^^^^^^^^^^^^^^----------------------------^^^^
2525
| |
2626
| help: change this to: `std::option::Option<&String>`
2727

2828
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
29-
--> tests/ui/ref_option/ref_option.rs:14:1
29+
--> tests/ui-toml/ref_option/ref_option.rs:14:1
3030
|
31-
LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> {
32-
| ^ -------------- help: change this to: `Option<&'a u8>`
31+
LL | fn ret_u8<'a>(p: &'a str) -> &'a Option<u8> {
32+
| ^ -------------- help: change this to: `Option<&'a u8>`
3333
| _|
3434
| |
3535
LL | |
@@ -38,10 +38,10 @@ LL | | }
3838
| |_^
3939

4040
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
41-
--> tests/ui/ref_option/ref_option.rs:18:1
41+
--> tests/ui-toml/ref_option/ref_option.rs:18:1
4242
|
43-
LL | fn ret_string_static() -> &'static Option<u8> {
44-
| ^ ------------------- help: change this to: `Option<&'static u8>`
43+
LL | fn ret_u8_static() -> &'static Option<u8> {
44+
| ^ ------------------- help: change this to: `Option<&'static u8>`
4545
| _|
4646
| |
4747
LL | |
@@ -50,7 +50,7 @@ LL | | }
5050
| |_^
5151

5252
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
53-
--> tests/ui/ref_option/ref_option.rs:22:1
53+
--> tests/ui-toml/ref_option/ref_option.rs:22:1
5454
|
5555
LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,7 +62,7 @@ LL + fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
6262
|
6363

6464
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
65-
--> tests/ui/ref_option/ref_option.rs:24:1
65+
--> tests/ui-toml/ref_option/ref_option.rs:24:1
6666
|
6767
LL | fn ret_box<'a>() -> &'a Option<Box<u8>> {
6868
| ^ ------------------- help: change this to: `Option<&'a Box<u8>>`
@@ -74,15 +74,15 @@ LL | | }
7474
| |_^
7575

7676
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
77-
--> tests/ui/ref_option/ref_option.rs:29:1
77+
--> tests/ui-toml/ref_option/ref_option.rs:29:1
7878
|
7979
LL | pub fn pub_opt_string(a: &Option<String>) {}
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^
8181
| |
8282
| help: change this to: `Option<&String>`
8383

8484
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
85-
--> tests/ui/ref_option/ref_option.rs:31:1
85+
--> tests/ui-toml/ref_option/ref_option.rs:31:1
8686
|
8787
LL | pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
8888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -94,47 +94,15 @@ LL + pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
9494
|
9595

9696
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
97-
--> tests/ui/ref_option/ref_option.rs:35:5
98-
|
99-
LL | fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
100-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^
101-
| |
102-
| help: change this to: `Option<&Vec<u8>>`
103-
104-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
105-
--> tests/ui/ref_option/ref_option.rs:37:5
106-
|
107-
LL | fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
108-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^
109-
| |
110-
| help: change this to: `Option<&Vec<u8>>`
111-
112-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
113-
--> tests/ui/ref_option/ref_option.rs:42:5
114-
|
115-
LL | fn trait_opt(&self, a: &Option<String>);
116-
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
117-
| |
118-
| help: change this to: `Option<&String>`
119-
120-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
121-
--> tests/ui/ref_option/ref_option.rs:44:5
122-
|
123-
LL | fn trait_ret(&self) -> &Option<String>;
124-
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
125-
| |
126-
| help: change this to: `Option<&String>`
127-
128-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
129-
--> tests/ui/ref_option/ref_option.rs:51:5
97+
--> tests/ui-toml/ref_option/ref_option.rs:37:5
13098
|
13199
LL | pub fn pub_opt_params(&self, a: &Option<()>) {}
132100
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
133101
| |
134102
| help: change this to: `Option<&()>`
135103

136104
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
137-
--> tests/ui/ref_option/ref_option.rs:53:5
105+
--> tests/ui-toml/ref_option/ref_option.rs:39:5
138106
|
139107
LL | pub fn pub_opt_ret(&self) -> &Option<String> {
140108
| ^ --------------- help: change this to: `Option<&String>`
@@ -146,15 +114,15 @@ LL | | }
146114
| |_____^
147115

148116
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
149-
--> tests/ui/ref_option/ref_option.rs:58:5
117+
--> tests/ui-toml/ref_option/ref_option.rs:44:5
150118
|
151119
LL | fn private_opt_params(&self, a: &Option<()>) {}
152120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
153121
| |
154122
| help: change this to: `Option<&()>`
155123

156124
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
157-
--> tests/ui/ref_option/ref_option.rs:60:5
125+
--> tests/ui-toml/ref_option/ref_option.rs:46:5
158126
|
159127
LL | fn private_opt_ret(&self) -> &Option<String> {
160128
| ^ --------------- help: change this to: `Option<&String>`
@@ -165,5 +133,5 @@ LL | | panic!()
165133
LL | | }
166134
| |_____^
167135

168-
error: aborting due to 17 previous errors
136+
error: aborting due to 13 previous errors
169137

tests/ui/ref_option/ref_option.private.fixed renamed to tests/ui-toml/ref_option/ref_option.private.fixed

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@revisions: private all
2-
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
3-
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
2+
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/private
3+
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/ref_option/all
44

55
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
66
#![warn(clippy::ref_option)]
@@ -11,11 +11,11 @@ fn opt_gen<T>(a: Option<&T>) {}
1111
//~^ ref_option
1212
fn opt_string(a: std::option::Option<&String>) {}
1313
//~^ ref_option
14-
fn ret_string<'a>(p: &'a str) -> Option<&'a u8> {
14+
fn ret_u8<'a>(p: &'a str) -> Option<&'a u8> {
1515
//~^ ref_option
1616
panic!()
1717
}
18-
fn ret_string_static() -> Option<&'static u8> {
18+
fn ret_u8_static() -> Option<&'static u8> {
1919
//~^ ref_option
2020
panic!()
2121
}
@@ -31,20 +31,6 @@ pub fn pub_opt_string(a: &Option<String>) {}
3131
pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
3232
//~[all]^ ref_option
3333

34-
pub trait PubTrait {
35-
fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
36-
//~[all]^ ref_option
37-
fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
38-
//~[all]^ ref_option
39-
}
40-
41-
trait PrivateTrait {
42-
fn trait_opt(&self, a: Option<&String>);
43-
//~^ ref_option
44-
fn trait_ret(&self) -> Option<&String>;
45-
//~^ ref_option
46-
}
47-
4834
pub struct PubStruct;
4935

5036
impl PubStruct {
Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
2-
--> tests/ui/ref_option/ref_option.rs:8:1
2+
--> tests/ui-toml/ref_option/ref_option.rs:8:1
33
|
44
LL | fn opt_u8(a: &Option<u8>) {}
55
| ^^^^^^^^^^^^^-----------^^^^
@@ -10,26 +10,26 @@ LL | fn opt_u8(a: &Option<u8>) {}
1010
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
1111

1212
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
13-
--> tests/ui/ref_option/ref_option.rs:10:1
13+
--> tests/ui-toml/ref_option/ref_option.rs:10:1
1414
|
1515
LL | fn opt_gen<T>(a: &Option<T>) {}
1616
| ^^^^^^^^^^^^^^^^^----------^^^^
1717
| |
1818
| help: change this to: `Option<&T>`
1919

2020
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
21-
--> tests/ui/ref_option/ref_option.rs:12:1
21+
--> tests/ui-toml/ref_option/ref_option.rs:12:1
2222
|
2323
LL | fn opt_string(a: &std::option::Option<String>) {}
2424
| ^^^^^^^^^^^^^^^^^----------------------------^^^^
2525
| |
2626
| help: change this to: `std::option::Option<&String>`
2727

2828
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
29-
--> tests/ui/ref_option/ref_option.rs:14:1
29+
--> tests/ui-toml/ref_option/ref_option.rs:14:1
3030
|
31-
LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> {
32-
| ^ -------------- help: change this to: `Option<&'a u8>`
31+
LL | fn ret_u8<'a>(p: &'a str) -> &'a Option<u8> {
32+
| ^ -------------- help: change this to: `Option<&'a u8>`
3333
| _|
3434
| |
3535
LL | |
@@ -38,10 +38,10 @@ LL | | }
3838
| |_^
3939

4040
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
41-
--> tests/ui/ref_option/ref_option.rs:18:1
41+
--> tests/ui-toml/ref_option/ref_option.rs:18:1
4242
|
43-
LL | fn ret_string_static() -> &'static Option<u8> {
44-
| ^ ------------------- help: change this to: `Option<&'static u8>`
43+
LL | fn ret_u8_static() -> &'static Option<u8> {
44+
| ^ ------------------- help: change this to: `Option<&'static u8>`
4545
| _|
4646
| |
4747
LL | |
@@ -50,7 +50,7 @@ LL | | }
5050
| |_^
5151

5252
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
53-
--> tests/ui/ref_option/ref_option.rs:22:1
53+
--> tests/ui-toml/ref_option/ref_option.rs:22:1
5454
|
5555
LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,7 +62,7 @@ LL + fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
6262
|
6363

6464
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
65-
--> tests/ui/ref_option/ref_option.rs:24:1
65+
--> tests/ui-toml/ref_option/ref_option.rs:24:1
6666
|
6767
LL | fn ret_box<'a>() -> &'a Option<Box<u8>> {
6868
| ^ ------------------- help: change this to: `Option<&'a Box<u8>>`
@@ -74,31 +74,15 @@ LL | | }
7474
| |_^
7575

7676
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
77-
--> tests/ui/ref_option/ref_option.rs:42:5
78-
|
79-
LL | fn trait_opt(&self, a: &Option<String>);
80-
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
81-
| |
82-
| help: change this to: `Option<&String>`
83-
84-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
85-
--> tests/ui/ref_option/ref_option.rs:44:5
86-
|
87-
LL | fn trait_ret(&self) -> &Option<String>;
88-
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
89-
| |
90-
| help: change this to: `Option<&String>`
91-
92-
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
93-
--> tests/ui/ref_option/ref_option.rs:58:5
77+
--> tests/ui-toml/ref_option/ref_option.rs:44:5
9478
|
9579
LL | fn private_opt_params(&self, a: &Option<()>) {}
9680
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
9781
| |
9882
| help: change this to: `Option<&()>`
9983

10084
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
101-
--> tests/ui/ref_option/ref_option.rs:60:5
85+
--> tests/ui-toml/ref_option/ref_option.rs:46:5
10286
|
10387
LL | fn private_opt_ret(&self) -> &Option<String> {
10488
| ^ --------------- help: change this to: `Option<&String>`
@@ -109,5 +93,5 @@ LL | | panic!()
10993
LL | | }
11094
| |_____^
11195

112-
error: aborting due to 11 previous errors
96+
error: aborting due to 9 previous errors
11397

0 commit comments

Comments
 (0)