Skip to content

Commit 452b474

Browse files
committed
Remove #[allow]s. Apply conversations from @Jarcho
1 parent 7c3c003 commit 452b474

17 files changed

+68
-95
lines changed

clippy_lints/src/functions/impl_trait_in_params.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,20 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
1111
{
1212
if let FnKind::ItemFn(ident, generics, _) = kind {
1313
for param in generics.params {
14-
if param.is_impl_trait()
15-
&& !param.name.ident().as_str().contains('<')
16-
&& !param.name.ident().as_str().contains('(')
17-
{
14+
if param.is_impl_trait() {
1815
// No generics with nested generics, and no generics like FnMut(x)
1916
span_lint_and_then(
2017
cx,
2118
IMPL_TRAIT_IN_PARAMS,
2219
param.span,
23-
&format!("'{}' in the function's parameters", param.name.ident().as_str()),
20+
"'`impl Trait` used as a function parameter'",
2421
|diag| {
2522
let next_letter = next_valid_letter(generics);
2623
if let Some(gen_span) = generics.span_for_param_suggestion() {
2724
diag.span_suggestion_with_style(
2825
gen_span,
29-
format!(
30-
"create a generic type here and replace that `{}` with `{}`",
31-
param.name.ident().as_str(),
32-
next_letter
33-
),
34-
", T: Trait",
26+
"add a type paremeter, `{}`: `{}`",
27+
format!(", {next_letter}: {}", &param.name.ident().as_str()[5..]),
3528
rustc_errors::Applicability::MaybeIncorrect,
3629
rustc_errors::SuggestionStyle::ShowAlways,
3730
);
@@ -46,12 +39,8 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
4639
ident.span.ctxt(),
4740
ident.span.parent(),
4841
),
49-
format!(
50-
"create a generic type here and replace that '{}' with `{}`",
51-
param.name.ident().as_str(),
52-
next_letter
53-
),
54-
"<T: Trait>",
42+
"add a type paremeter",
43+
format!("<{next_letter}: {}>", &param.name.ident().as_str()[5..]),
5544
rustc_errors::Applicability::MaybeIncorrect,
5645
rustc_errors::SuggestionStyle::ShowAlways,
5746
);

clippy_utils/src/ast_utils.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
//!
33
//! - The `eq_foobar` functions test for semantic equality but ignores `NodeId`s and `Span`s.
44
5-
#![allow(
6-
clippy::similar_names,
7-
clippy::wildcard_imports,
8-
clippy::enum_glob_use,
9-
clippy::impl_trait_in_params
10-
)]
5+
#![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)]
116

127
use crate::{both, over};
138
use rustc_ast::ptr::P;

clippy_utils/src/check_proc_macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(clippy::impl_trait_in_params)]
21
//! This module handles checking if the span given is from a proc-macro or not.
32
//!
43
//! Proc-macros are capable of setting the span of every token they output to a few possible spans.

clippy_utils/src/hir_utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(clippy::impl_trait_in_params)]
21
use crate::consts::constant_simple;
32
use crate::macros::macro_backtrace;
43
use crate::source::snippet_opt;

clippy_utils/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::similar_names, clippy::impl_trait_in_params)] // `expr` and `expn`
1+
#![allow(clippy::similar_names)] // `expr` and `expn`
22

33
use crate::is_path_diagnostic_item;
44
use crate::source::snippet_opt;

clippy_utils/src/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Utils for extracting, inspecting or transforming source code
22
3-
#![allow(clippy::module_name_repetitions, clippy::impl_trait_in_params)]
3+
#![allow(clippy::module_name_repetitions)]
44

55
use rustc_errors::Applicability;
66
use rustc_hir::{Expr, ExprKind};

tests/ui/borrow_box.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![deny(clippy::borrowed_box)]
22
#![allow(dead_code, unused_variables)]
3-
#![allow(
4-
clippy::uninlined_format_args,
5-
clippy::disallowed_names,
6-
clippy::impl_trait_in_params
7-
)]
3+
#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
84

95
use std::fmt::Display;
106

tests/ui/borrow_box.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
2-
--> $DIR/borrow_box.rs:24:14
2+
--> $DIR/borrow_box.rs:20:14
33
|
44
LL | let foo: &Box<bool>;
55
| ^^^^^^^^^^ help: try: `&bool`
@@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
14-
--> $DIR/borrow_box.rs:28:10
14+
--> $DIR/borrow_box.rs:24:10
1515
|
1616
LL | foo: &'a Box<bool>,
1717
| ^^^^^^^^^^^^^ help: try: `&'a bool`
1818

1919
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
20-
--> $DIR/borrow_box.rs:32:17
20+
--> $DIR/borrow_box.rs:28:17
2121
|
2222
LL | fn test4(a: &Box<bool>);
2323
| ^^^^^^^^^^ help: try: `&bool`
2424

2525
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
26-
--> $DIR/borrow_box.rs:98:25
26+
--> $DIR/borrow_box.rs:94:25
2727
|
2828
LL | pub fn test14(_display: &Box<dyn Display>) {}
2929
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
3030

3131
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
32-
--> $DIR/borrow_box.rs:99:25
32+
--> $DIR/borrow_box.rs:95:25
3333
|
3434
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
3636

3737
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
38-
--> $DIR/borrow_box.rs:100:29
38+
--> $DIR/borrow_box.rs:96:29
3939
|
4040
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
4242

4343
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
44-
--> $DIR/borrow_box.rs:102:25
44+
--> $DIR/borrow_box.rs:98:25
4545
|
4646
LL | pub fn test17(_display: &Box<impl Display>) {}
4747
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
4848

4949
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
50-
--> $DIR/borrow_box.rs:103:25
50+
--> $DIR/borrow_box.rs:99:25
5151
|
5252
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
5454

5555
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
56-
--> $DIR/borrow_box.rs:104:29
56+
--> $DIR/borrow_box.rs:100:29
5757
|
5858
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
6060

6161
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
62-
--> $DIR/borrow_box.rs:109:25
62+
--> $DIR/borrow_box.rs:105:25
6363
|
6464
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`

tests/ui/eta.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
clippy::no_effect,
88
clippy::option_map_unit_fn,
99
clippy::redundant_closure_call,
10-
clippy::uninlined_format_args,
11-
clippy::impl_trait_in_params
10+
clippy::uninlined_format_args
1211
)]
1312

1413
use std::path::{Path, PathBuf};

tests/ui/eta.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
clippy::no_effect,
88
clippy::option_map_unit_fn,
99
clippy::redundant_closure_call,
10-
clippy::uninlined_format_args,
11-
clippy::impl_trait_in_params
10+
clippy::uninlined_format_args
1211
)]
1312

1413
use std::path::{Path, PathBuf};

tests/ui/eta.stderr

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,159 @@
11
error: redundant closure
2-
--> $DIR/eta.rs:29:27
2+
--> $DIR/eta.rs:28:27
33
|
44
LL | let a = Some(1u8).map(|a| foo(a));
55
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
66
|
77
= note: `-D clippy::redundant-closure` implied by `-D warnings`
88

99
error: redundant closure
10-
--> $DIR/eta.rs:33:40
10+
--> $DIR/eta.rs:32:40
1111
|
1212
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
1313
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
1414

1515
error: redundant closure
16-
--> $DIR/eta.rs:34:35
16+
--> $DIR/eta.rs:33:35
1717
|
1818
LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
1919
| ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2`
2020

2121
error: redundant closure
22-
--> $DIR/eta.rs:35:26
22+
--> $DIR/eta.rs:34:26
2323
|
2424
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
2525
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below`
2626

2727
error: redundant closure
28-
--> $DIR/eta.rs:42:27
28+
--> $DIR/eta.rs:41:27
2929
|
3030
LL | let e = Some(1u8).map(|a| generic(a));
3131
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
3232

3333
error: redundant closure
34-
--> $DIR/eta.rs:88:51
34+
--> $DIR/eta.rs:87:51
3535
|
3636
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
3737
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
3838
|
3939
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
4040

4141
error: redundant closure
42-
--> $DIR/eta.rs:89:51
42+
--> $DIR/eta.rs:88:51
4343
|
4444
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
4545
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
4646

4747
error: redundant closure
48-
--> $DIR/eta.rs:91:42
48+
--> $DIR/eta.rs:90:42
4949
|
5050
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
5151
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
5252

5353
error: redundant closure
54-
--> $DIR/eta.rs:95:29
54+
--> $DIR/eta.rs:94:29
5555
|
5656
LL | let e = Some("str").map(|s| s.to_string());
5757
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
5858

5959
error: redundant closure
60-
--> $DIR/eta.rs:96:27
60+
--> $DIR/eta.rs:95:27
6161
|
6262
LL | let e = Some('a').map(|s| s.to_uppercase());
6363
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
6464

6565
error: redundant closure
66-
--> $DIR/eta.rs:98:65
66+
--> $DIR/eta.rs:97:65
6767
|
6868
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
7070

7171
error: redundant closure
72-
--> $DIR/eta.rs:161:22
72+
--> $DIR/eta.rs:160:22
7373
|
7474
LL | requires_fn_once(|| x());
7575
| ^^^^^^ help: replace the closure with the function itself: `x`
7676

7777
error: redundant closure
78-
--> $DIR/eta.rs:168:27
78+
--> $DIR/eta.rs:167:27
7979
|
8080
LL | let a = Some(1u8).map(|a| foo_ptr(a));
8181
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
8282

8383
error: redundant closure
84-
--> $DIR/eta.rs:173:27
84+
--> $DIR/eta.rs:172:27
8585
|
8686
LL | let a = Some(1u8).map(|a| closure(a));
8787
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
8888

8989
error: redundant closure
90-
--> $DIR/eta.rs:205:28
90+
--> $DIR/eta.rs:204:28
9191
|
9292
LL | x.into_iter().for_each(|x| add_to_res(x));
9393
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
9494

9595
error: redundant closure
96-
--> $DIR/eta.rs:206:28
96+
--> $DIR/eta.rs:205:28
9797
|
9898
LL | y.into_iter().for_each(|x| add_to_res(x));
9999
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
100100

101101
error: redundant closure
102-
--> $DIR/eta.rs:207:28
102+
--> $DIR/eta.rs:206:28
103103
|
104104
LL | z.into_iter().for_each(|x| add_to_res(x));
105105
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res`
106106

107107
error: redundant closure
108-
--> $DIR/eta.rs:214:21
108+
--> $DIR/eta.rs:213:21
109109
|
110110
LL | Some(1).map(|n| closure(n));
111111
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`
112112

113113
error: redundant closure
114-
--> $DIR/eta.rs:218:21
114+
--> $DIR/eta.rs:217:21
115115
|
116116
LL | Some(1).map(|n| in_loop(n));
117117
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
118118

119119
error: redundant closure
120-
--> $DIR/eta.rs:311:18
120+
--> $DIR/eta.rs:310:18
121121
|
122122
LL | takes_fn_mut(|| f());
123123
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
124124

125125
error: redundant closure
126-
--> $DIR/eta.rs:314:19
126+
--> $DIR/eta.rs:313:19
127127
|
128128
LL | takes_fn_once(|| f());
129129
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
130130

131131
error: redundant closure
132-
--> $DIR/eta.rs:318:26
132+
--> $DIR/eta.rs:317:26
133133
|
134134
LL | move || takes_fn_mut(|| f_used_once())
135135
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
136136

137137
error: redundant closure
138-
--> $DIR/eta.rs:330:19
138+
--> $DIR/eta.rs:329:19
139139
|
140140
LL | array_opt.map(|a| a.as_slice());
141141
| ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice`
142142

143143
error: redundant closure
144-
--> $DIR/eta.rs:333:19
144+
--> $DIR/eta.rs:332:19
145145
|
146146
LL | slice_opt.map(|s| s.len());
147147
| ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len`
148148

149149
error: redundant closure
150-
--> $DIR/eta.rs:336:17
150+
--> $DIR/eta.rs:335:17
151151
|
152152
LL | ptr_opt.map(|p| p.is_null());
153153
| ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null`
154154

155155
error: redundant closure
156-
--> $DIR/eta.rs:340:17
156+
--> $DIR/eta.rs:339:17
157157
|
158158
LL | dyn_opt.map(|d| d.method_on_dyn());
159159
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`

0 commit comments

Comments
 (0)