Skip to content

Commit

Permalink
Auto merge of #7671 - dtolnay-contrib:singlecharnames, r=xFrednet
Browse files Browse the repository at this point in the history
Downgrade many_single_char_names to pedantic

As suggested by `@flip1995` in #7666 (comment), by today's standards this lint would be considered `pedantic`.

This is one of the most widely suppressed Clippy lints on crates.io according to https://github.com/dtolnay/noisy-clippy.

In my opinion this lint is just too domain specific for Clippy to have reliable visibility into. Sure there are some cases where the author is just being lazy and could use a kick in the butt, but we're still left with an enormous number of suppressions where single chars are the most appropriate name. For example in the context of colors, a function using `h`, `s`, `l`, `r`, `g`, `b` is 100% sensible and spelling all those out is silly, but it's past the default lint threshold.

---

changelog: Moved [`many_single_char_names`] to `pedantic`
  • Loading branch information
bors committed Sep 14, 2021
2 parents 746a005 + c2783c1 commit 2316f4d
Show file tree
Hide file tree
Showing 40 changed files with 124 additions and 139 deletions.
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(needless_continue::NEEDLESS_CONTINUE),
LintId::of(needless_for_each::NEEDLESS_FOR_EACH),
LintId::of(needless_pass_by_value::NEEDLESS_PASS_BY_VALUE),
LintId::of(non_expressive_names::MANY_SINGLE_CHAR_NAMES),
LintId::of(non_expressive_names::SIMILAR_NAMES),
LintId::of(pass_by_ref_or_value::LARGE_TYPES_PASSED_BY_VALUE),
LintId::of(pass_by_ref_or_value::TRIVIALLY_COPY_PASS_BY_REF),
Expand Down Expand Up @@ -1393,7 +1394,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
LintId::of(non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
LintId::of(non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
LintId::of(non_expressive_names::MANY_SINGLE_CHAR_NAMES),
LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),
LintId::of(option_env_unwrap::OPTION_ENV_UNWRAP),
Expand Down Expand Up @@ -1567,7 +1567,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
LintId::of(non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
LintId::of(non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
LintId::of(non_expressive_names::MANY_SINGLE_CHAR_NAMES),
LintId::of(ptr::CMP_NULL),
LintId::of(ptr::PTR_ARG),
LintId::of(ptr_eq::PTR_EQ),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare_clippy_lint! {
/// let (a, b, c, d, e, f, g) = (...);
/// ```
pub MANY_SINGLE_CHAR_NAMES,
style,
pedantic,
"too many single character bindings"
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
std::mem::discriminant(&b.rules).hash(&mut self.s);
}

#[allow(clippy::many_single_char_names, clippy::too_many_lines)]
#[allow(clippy::too_many_lines)]
pub fn hash_expr(&mut self, e: &Expr<'_>) {
let simple_const = self
.maybe_typeck_results
Expand Down
1 change: 0 additions & 1 deletion tests/ui-toml/toml_trivially_copy/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"

#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(clippy::many_single_char_names)]

#[derive(Copy, Clone)]
struct Foo(u8);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-toml/toml_trivially_copy/test.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:15:11
--> $DIR/test.rs:14:11
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16`
Expand All @@ -11,7 +11,7 @@ LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:15:20
--> $DIR/test.rs:14:20
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `Foo`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/deref_addrof.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn get_reference(n: &usize) -> &usize {
n
}

#[allow(clippy::many_single_char_names, clippy::double_parens)]
#[allow(clippy::double_parens)]
#[allow(unused_variables, unused_parens)]
fn main() {
let a = 10;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/deref_addrof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn get_reference(n: &usize) -> &usize {
n
}

#[allow(clippy::many_single_char_names, clippy::double_parens)]
#[allow(clippy::double_parens)]
#[allow(unused_variables, unused_parens)]
fn main() {
let a = 10;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[rustfmt::skip]
#[warn(clippy::eq_op)]
#[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)]
#[allow(clippy::identity_op, clippy::double_parens)]
#[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
#[allow(clippy::nonminimal_bool)]
#[allow(unused)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/eta.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
unused,
clippy::no_effect,
clippy::redundant_closure_call,
clippy::many_single_char_names,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn
)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/eta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
unused,
clippy::no_effect,
clippy::redundant_closure_call,
clippy::many_single_char_names,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn
)]
Expand Down
42 changes: 21 additions & 21 deletions tests/ui/eta.stderr
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
error: redundant closure
--> $DIR/eta.rs:32:27
--> $DIR/eta.rs:31: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:36:40
--> $DIR/eta.rs:35: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:37:35
--> $DIR/eta.rs:36: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: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
--> $DIR/eta.rs:38:21
--> $DIR/eta.rs:37:21
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^ help: change this to: `&2`
|
= note: `-D clippy::needless-borrow` implied by `-D warnings`

error: redundant closure
--> $DIR/eta.rs:38:26
--> $DIR/eta.rs:37: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:44:27
--> $DIR/eta.rs:43:27
|
LL | let e = Some(1u8).map(|a| divergent(a));
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `divergent`

error: redundant closure
--> $DIR/eta.rs:45:27
--> $DIR/eta.rs:44: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:91:51
--> $DIR/eta.rs:90: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:92:51
--> $DIR/eta.rs:91: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:94:42
--> $DIR/eta.rs:93: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:98:29
--> $DIR/eta.rs:97: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:99:27
--> $DIR/eta.rs:98: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:101:65
--> $DIR/eta.rs:100: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:164:22
--> $DIR/eta.rs:163:22
|
LL | requires_fn_once(|| x());
| ^^^^^^ help: replace the closure with the function itself: `x`

error: redundant closure
--> $DIR/eta.rs:171:27
--> $DIR/eta.rs:170: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:176:27
--> $DIR/eta.rs:175: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:208:28
--> $DIR/eta.rs:207: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:209:28
--> $DIR/eta.rs:208: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:210:28
--> $DIR/eta.rs:209: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:217:21
--> $DIR/eta.rs:216:21
|
LL | Some(1).map(|n| closure(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`

error: redundant closure
--> $DIR/eta.rs:236:21
--> $DIR/eta.rs:235:21
|
LL | map_str_to_path(|s| s.as_ref());
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::convert::AsRef::as_ref`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/eval_order_dependence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#[allow(
unused_assignments,
unused_variables,
clippy::many_single_char_names,
clippy::no_effect,
dead_code,
clippy::blacklisted_name
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/eval_order_dependence.stderr
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:17:9
--> $DIR/eval_order_dependence.rs:16:9
|
LL | } + x;
| ^
|
= note: `-D clippy::eval-order-dependence` implied by `-D warnings`
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:15:9
--> $DIR/eval_order_dependence.rs:14:9
|
LL | x = 1;
| ^^^^^

error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:20:5
--> $DIR/eval_order_dependence.rs:19:5
|
LL | x += {
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:21:9
--> $DIR/eval_order_dependence.rs:20:9
|
LL | x = 20;
| ^^^^^^

error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:33:12
--> $DIR/eval_order_dependence.rs:32:12
|
LL | a: x,
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:35:13
--> $DIR/eval_order_dependence.rs:34:13
|
LL | x = 6;
| ^^^^^

error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:42:9
--> $DIR/eval_order_dependence.rs:41:9
|
LL | x += {
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:43:13
--> $DIR/eval_order_dependence.rs:42:13
|
LL | x = 20;
| ^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/explicit_deref_methods.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-rustfix

#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)]
#![allow(unused_variables, clippy::clone_double_ref)]
#![warn(clippy::explicit_deref_methods)]

use std::ops::{Deref, DerefMut};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/explicit_deref_methods.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-rustfix

#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)]
#![allow(unused_variables, clippy::clone_double_ref)]
#![warn(clippy::explicit_deref_methods)]

use std::ops::{Deref, DerefMut};
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/float_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
clippy::no_effect,
clippy::op_ref,
clippy::unnecessary_operation,
clippy::cast_lossless,
clippy::many_single_char_names
clippy::cast_lossless
)]

use std::ops::Add;
Expand Down

0 comments on commit 2316f4d

Please sign in to comment.