Skip to content

Commit

Permalink
Remove #[allow]s. Apply conversations from @Jarcho
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Jan 20, 2023
1 parent 7c3c003 commit 452b474
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 95 deletions.
23 changes: 6 additions & 17 deletions clippy_lints/src/functions/impl_trait_in_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,20 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
{
if let FnKind::ItemFn(ident, generics, _) = kind {
for param in generics.params {
if param.is_impl_trait()
&& !param.name.ident().as_str().contains('<')
&& !param.name.ident().as_str().contains('(')
{
if param.is_impl_trait() {
// No generics with nested generics, and no generics like FnMut(x)
span_lint_and_then(
cx,
IMPL_TRAIT_IN_PARAMS,
param.span,
&format!("'{}' in the function's parameters", param.name.ident().as_str()),
"'`impl Trait` used as a function parameter'",
|diag| {
let next_letter = next_valid_letter(generics);
if let Some(gen_span) = generics.span_for_param_suggestion() {
diag.span_suggestion_with_style(
gen_span,
format!(
"create a generic type here and replace that `{}` with `{}`",
param.name.ident().as_str(),
next_letter
),
", T: Trait",
"add a type paremeter, `{}`: `{}`",
format!(", {next_letter}: {}", &param.name.ident().as_str()[5..]),
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways,
);
Expand All @@ -46,12 +39,8 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
ident.span.ctxt(),
ident.span.parent(),
),
format!(
"create a generic type here and replace that '{}' with `{}`",
param.name.ident().as_str(),
next_letter
),
"<T: Trait>",
"add a type paremeter",
format!("<{next_letter}: {}>", &param.name.ident().as_str()[5..]),
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways,
);
Expand Down
7 changes: 1 addition & 6 deletions clippy_utils/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
//!
//! - The `eq_foobar` functions test for semantic equality but ignores `NodeId`s and `Span`s.

#![allow(
clippy::similar_names,
clippy::wildcard_imports,
clippy::enum_glob_use,
clippy::impl_trait_in_params
)]
#![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)]

use crate::{both, over};
use rustc_ast::ptr::P;
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/check_proc_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(clippy::impl_trait_in_params)]
//! This module handles checking if the span given is from a proc-macro or not.
//!
//! Proc-macros are capable of setting the span of every token they output to a few possible spans.
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/hir_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(clippy::impl_trait_in_params)]
use crate::consts::constant_simple;
use crate::macros::macro_backtrace;
use crate::source::snippet_opt;
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::similar_names, clippy::impl_trait_in_params)] // `expr` and `expn`
#![allow(clippy::similar_names)] // `expr` and `expn`

use crate::is_path_diagnostic_item;
use crate::source::snippet_opt;
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utils for extracting, inspecting or transforming source code

#![allow(clippy::module_name_repetitions, clippy::impl_trait_in_params)]
#![allow(clippy::module_name_repetitions)]

use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
Expand Down
6 changes: 1 addition & 5 deletions tests/ui/borrow_box.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#![deny(clippy::borrowed_box)]
#![allow(dead_code, unused_variables)]
#![allow(
clippy::uninlined_format_args,
clippy::disallowed_names,
clippy::impl_trait_in_params
)]
#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]

use std::fmt::Display;

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/borrow_box.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> $DIR/borrow_box.rs:24:14
--> $DIR/borrow_box.rs:20:14
|
LL | let foo: &Box<bool>;
| ^^^^^^^^^^ help: try: `&bool`
Expand All @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
| ^^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> $DIR/borrow_box.rs:109:25
--> $DIR/borrow_box.rs:105:25
|
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/eta.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
clippy::no_effect,
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::impl_trait_in_params
clippy::uninlined_format_args
)]

use std::path::{Path, PathBuf};
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/eta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
clippy::no_effect,
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::impl_trait_in_params
clippy::uninlined_format_args
)]

use std::path::{Path, PathBuf};
Expand Down
52 changes: 26 additions & 26 deletions tests/ui/eta.stderr
Original file line number Diff line number Diff line change
@@ -1,159 +1,159 @@
error: redundant closure
--> $DIR/eta.rs:29:27
--> $DIR/eta.rs:28:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
|
= note: `-D clippy::redundant-closure` implied by `-D warnings`

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: redundant closure
--> $DIR/eta.rs:340:17
--> $DIR/eta.rs:339:17
|
LL | dyn_opt.map(|d| d.method_on_dyn());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
Expand Down
Loading

0 comments on commit 452b474

Please sign in to comment.