Skip to content

Commit 4540c9f

Browse files
authored
Rollup merge of rust-lang#84427 - flip1995:clippyup, r=Manishearth
Update Clippy r? ``@Manishearth`` Biweekly Clippy update.
2 parents 14bfb6b + 9482caf commit 4540c9f

File tree

186 files changed

+4649
-1551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+4649
-1551
lines changed

src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Thank you for making Clippy better!
33
We're collecting our changelog from pull request descriptions.
44
If your PR only includes internal changes, you can just write
55
`changelog: none`. Otherwise, please write a short comment
6-
explaining your change.
6+
explaining your change. Also, it's helpful for us that
7+
the lint name is put into brackets `[]` and backticks `` ` ` ``,
8+
e.g. ``[`lint_name`]``.
79

810
If your PR fixes an issue, you can add "fixes #issue_number" into this
911
PR description. This way the issue will be automatically closed when
@@ -29,4 +31,5 @@ Delete this line and everything above before opening your PR.
2931
---
3032

3133
*Please write a short comment explaining your change (or "none" for internal only changes)*
34+
3235
changelog:

src/tools/clippy/.github/workflows/clippy_bors.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ jobs:
3434
run: |
3535
MESSAGE=$(git log --format=%B -n 1)
3636
PR=$(echo "$MESSAGE" | grep -o "#[0-9]*" | head -1 | sed -e 's/^#//')
37-
output=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \
38-
python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \
39-
grep "^changelog: " | \
40-
sed "s/changelog: //g")
41-
if [[ -z "$output" ]]; then
37+
body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \
38+
python -c "import sys, json; print(json.load(sys.stdin)['body'])")
39+
output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || {
4240
echo "ERROR: PR body must contain 'changelog: ...'"
4341
exit 1
44-
elif [[ "$output" = "none" ]]; then
42+
}
43+
if [[ "$output" = "none" ]]; then
4544
echo "WARNING: changelog is 'none'"
45+
else
46+
echo "changelog: $output"
4647
fi
4748
env:
4849
PYTHONIOENCODING: 'utf-8'

src/tools/clippy/CHANGELOG.md

+16-18
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Current stable, released 2021-03-25
179179

180180
* Replace [`find_map`] with [`manual_find_map`]
181181
[#6591](https://github.com/rust-lang/rust-clippy/pull/6591)
182-
* [`unknown_clippy_lints`] Now integrated in the `unknown_lints` rustc lint
182+
* `unknown_clippy_lints` Now integrated in the `unknown_lints` rustc lint
183183
[#6653](https://github.com/rust-lang/rust-clippy/pull/6653)
184184

185185
### Enhancements
@@ -280,7 +280,7 @@ Released 2021-02-11
280280

281281
* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated
282282
as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333)
283-
* Deprecate [`panic_params`] lint. This is now available in rustc as `panic_fmt`
283+
* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panic`
284284
[#6351](https://github.com/rust-lang/rust-clippy/pull/6351)
285285
* Move [`map_err_ignore`] to `restriction`
286286
[#6416](https://github.com/rust-lang/rust-clippy/pull/6416)
@@ -419,7 +419,7 @@ Released 2020-12-31
419419
[#6037](https://github.com/rust-lang/rust-clippy/pull/6037)
420420
* Rename `zero_width_space` to [`invisible_characters`]
421421
[#6105](https://github.com/rust-lang/rust-clippy/pull/6105)
422-
* Deprecate [`drop_bounds`] (uplifted)
422+
* Deprecate `drop_bounds` (uplifted)
423423
[#6111](https://github.com/rust-lang/rust-clippy/pull/6111)
424424
* Move [`string_lit_as_bytes`] to `nursery`
425425
[#6117](https://github.com/rust-lang/rust-clippy/pull/6117)
@@ -1018,7 +1018,7 @@ Released 2020-03-12
10181018
[#5015](https://github.com/rust-lang/rust-clippy/pull/5015)
10191019
* Move [`range_plus_one`] to pedantic group [#5057](https://github.com/rust-lang/rust-clippy/pull/5057)
10201020
* Move [`debug_assert_with_mut_call`] to nursery group [#5106](https://github.com/rust-lang/rust-clippy/pull/5106)
1021-
* Deprecate [`unused_label`] [#4930](https://github.com/rust-lang/rust-clippy/pull/4930)
1021+
* Deprecate `unused_label` [#4930](https://github.com/rust-lang/rust-clippy/pull/4930)
10221022

10231023
### Enhancements
10241024

@@ -1046,7 +1046,7 @@ Released 2020-03-12
10461046
* [`wildcard_enum_match_arm`] [#4934](https://github.com/rust-lang/rust-clippy/pull/4934)
10471047
* [`cognitive_complexity`] [#4935](https://github.com/rust-lang/rust-clippy/pull/4935)
10481048
* [`decimal_literal_representation`] [#4956](https://github.com/rust-lang/rust-clippy/pull/4956)
1049-
* [`unknown_clippy_lints`] [#4963](https://github.com/rust-lang/rust-clippy/pull/4963)
1049+
* `unknown_clippy_lints` [#4963](https://github.com/rust-lang/rust-clippy/pull/4963)
10501050
* [`explicit_into_iter_loop`] [#4978](https://github.com/rust-lang/rust-clippy/pull/4978)
10511051
* [`useless_attribute`] [#5022](https://github.com/rust-lang/rust-clippy/pull/5022)
10521052
* [`if_let_some_result`] [#5032](https://github.com/rust-lang/rust-clippy/pull/5032)
@@ -1080,7 +1080,7 @@ Released 2020-01-30
10801080
[Inside Rust Blog](https://blog.rust-lang.org/inside-rust/2019/11/04/Clippy-removes-plugin-interface.html) for
10811081
details [#4714](https://github.com/rust-lang/rust-clippy/pull/4714)
10821082
* Move [`use_self`] to nursery group [#4863](https://github.com/rust-lang/rust-clippy/pull/4863)
1083-
* Deprecate [`into_iter_on_array`] [#4788](https://github.com/rust-lang/rust-clippy/pull/4788)
1083+
* Deprecate `into_iter_on_array` [#4788](https://github.com/rust-lang/rust-clippy/pull/4788)
10841084
* Expand [`string_lit_as_bytes`] to also trigger when literal has escapes
10851085
[#4808](https://github.com/rust-lang/rust-clippy/pull/4808)
10861086
* Fix false positive in `comparison_chain` [#4842](https://github.com/rust-lang/rust-clippy/pull/4842)
@@ -1282,7 +1282,7 @@ Released 2019-05-20
12821282

12831283
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)
12841284

1285-
* New lint: [`drop_bounds`] to detect `T: Drop` bounds
1285+
* New lint: `drop_bounds` to detect `T: Drop` bounds
12861286
* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101)
12871287
* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code
12881288
* Move [`get_unwrap`] to the restriction category
@@ -1375,7 +1375,7 @@ Released 2019-01-17
13751375

13761376
* New lints: [`slow_vector_initialization`], [`mem_discriminant_non_enum`],
13771377
[`redundant_clone`], [`wildcard_dependencies`],
1378-
[`into_iter_on_ref`], [`into_iter_on_array`], [`deprecated_cfg_attr`],
1378+
[`into_iter_on_ref`], `into_iter_on_array`, [`deprecated_cfg_attr`],
13791379
[`mem_discriminant_non_enum`], [`cargo_common_metadata`]
13801380
* Add support for `u128` and `i128` to integer related lints
13811381
* Add float support to `mistyped_literal_suffixes`
@@ -1649,7 +1649,7 @@ Released 2018-09-13
16491649

16501650
## 0.0.166
16511651
* Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)*
1652-
* New lints: [`explicit_write`], `identity_conversion`, [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`],
1652+
* New lints: [`explicit_write`], `identity_conversion`, [`implicit_hasher`], `invalid_ref`, [`option_map_or_none`],
16531653
[`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`],
16541654
[`transmute_int_to_float`]
16551655

@@ -2037,7 +2037,7 @@ Released 2018-09-13
20372037

20382038
## 0.0.64 — 2016-04-26
20392039
* Rustup to *rustc 1.10.0-nightly (645dd013a 2016-04-24)*
2040-
* New lints: [`temporary_cstring_as_ptr`], [`unsafe_removed_from_name`], and [`mem_forget`]
2040+
* New lints: `temporary_cstring_as_ptr`, [`unsafe_removed_from_name`], and [`mem_forget`]
20412041

20422042
## 0.0.63 — 2016-04-08
20432043
* Rustup to *rustc 1.9.0-nightly (7979dd608 2016-04-07)*
@@ -2091,7 +2091,7 @@ Released 2018-09-13
20912091

20922092
## 0.0.49 — 2016-03-09
20932093
* Update to *rustc 1.9.0-nightly (eabfc160f 2016-03-08)*
2094-
* New lints: [`overflow_check_conditional`], [`unused_label`], [`new_without_default`]
2094+
* New lints: [`overflow_check_conditional`], `unused_label`, [`new_without_default`]
20952095

20962096
## 0.0.48 — 2016-03-07
20972097
* Fixed: ICE in [`needless_range_loop`] with globals
@@ -2124,6 +2124,7 @@ Released 2018-09-13
21242124
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
21252125
[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints
21262126
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
2127+
[`bool_assert_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
21272128
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
21282129
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
21292130
[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
@@ -2148,6 +2149,7 @@ Released 2018-09-13
21482149
[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
21492150
[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
21502151
[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
2152+
[`cloned_instead_of_copied`]: https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied
21512153
[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan
21522154
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
21532155
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
@@ -2178,7 +2180,6 @@ Released 2018-09-13
21782180
[`double_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use
21792181
[`double_neg`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_neg
21802182
[`double_parens`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
2181-
[`drop_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_bounds
21822183
[`drop_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy
21832184
[`drop_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref
21842185
[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument
@@ -2216,6 +2217,7 @@ Released 2018-09-13
22162217
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
22172218
[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map
22182219
[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity
2220+
[`flat_map_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_option
22192221
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
22202222
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
22212223
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const
@@ -2264,10 +2266,9 @@ Released 2018-09-13
22642266
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
22652267
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
22662268
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
2267-
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
22682269
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
22692270
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
2270-
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
2271+
[`invalid_null_ptr_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_null_ptr_usage
22712272
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
22722273
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
22732274
[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters
@@ -2402,7 +2403,6 @@ Released 2018-09-13
24022403
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
24032404
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
24042405
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
2405-
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
24062406
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
24072407
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
24082408
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
@@ -2488,7 +2488,6 @@ Released 2018-09-13
24882488
[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting
24892489
[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
24902490
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
2491-
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
24922491
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
24932492
[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display
24942493
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
@@ -2517,13 +2516,13 @@ Released 2018-09-13
25172516
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
25182517
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
25192518
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
2520-
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
25212519
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
25222520
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
25232521
[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold
25242522
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
25252523
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
25262524
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
2525+
[`unnecessary_self_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports
25272526
[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
25282527
[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
25292528
[`unnecessary_wraps`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
@@ -2541,7 +2540,6 @@ Released 2018-09-13
25412540
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
25422541
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
25432542
[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
2544-
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
25452543
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
25462544
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
25472545
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings

src/tools/clippy/CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ All contributors are expected to follow the [Rust Code of Conduct].
2121
- [IntelliJ Rust](#intellij-rust)
2222
- [Rust Analyzer](#rust-analyzer)
2323
- [How Clippy works](#how-clippy-works)
24-
- [Syncing changes between Clippy and [`rust-lang/rust`]](#syncing-changes-between-clippy-and-rust-langrust)
24+
- [Syncing changes between Clippy and `rust-lang/rust`](#syncing-changes-between-clippy-and-rust-langrust)
2525
- [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos)
26-
- [Performing the sync from [`rust-lang/rust`] to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
27-
- [Performing the sync from Clippy to [`rust-lang/rust`]](#performing-the-sync-from-clippy-to-rust-langrust)
26+
- [Performing the sync from `rust-lang/rust` to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
27+
- [Performing the sync from Clippy to `rust-lang/rust`](#performing-the-sync-from-clippy-to-rust-langrust)
2828
- [Defining remotes](#defining-remotes)
2929
- [Issue and PR triage](#issue-and-pr-triage)
3030
- [Bors and Homu](#bors-and-homu)

src/tools/clippy/clippy_lints/src/assertions_on_constants.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
127127
_ => &block.expr,
128128
};
129129
// function call
130-
if let Some(args) = match_panic_call(cx, begin_panic_call);
131-
if args.len() == 1;
130+
if let Some(arg) = match_panic_call(cx, begin_panic_call);
132131
// bind the second argument of the `assert!` macro if it exists
133-
if let panic_message = snippet_opt(cx, args[0].span);
132+
if let panic_message = snippet_opt(cx, arg.span);
134133
// second argument of begin_panic is irrelevant
135134
// as is the second match arm
136135
then {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::{ast_utils, is_direct_expn_of};
3+
use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind};
4+
use rustc_errors::Applicability;
5+
use rustc_lint::{EarlyContext, EarlyLintPass};
6+
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
8+
declare_clippy_lint! {
9+
/// **What it does:** This lint warns about boolean comparisons in assert-like macros.
10+
///
11+
/// **Why is this bad?** It is shorter to use the equivalent.
12+
///
13+
/// **Known problems:** None.
14+
///
15+
/// **Example:**
16+
///
17+
/// ```rust
18+
/// // Bad
19+
/// assert_eq!("a".is_empty(), false);
20+
/// assert_ne!("a".is_empty(), true);
21+
///
22+
/// // Good
23+
/// assert!(!"a".is_empty());
24+
/// ```
25+
pub BOOL_ASSERT_COMPARISON,
26+
style,
27+
"Using a boolean as comparison value in an assert_* macro when there is no need"
28+
}
29+
30+
declare_lint_pass!(BoolAssertComparison => [BOOL_ASSERT_COMPARISON]);
31+
32+
fn is_bool_lit(e: &Expr) -> bool {
33+
matches!(
34+
e.kind,
35+
ExprKind::Lit(Lit {
36+
kind: LitKind::Bool(_),
37+
..
38+
})
39+
) && !e.span.from_expansion()
40+
}
41+
42+
impl EarlyLintPass for BoolAssertComparison {
43+
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
44+
let macros = ["assert_eq", "debug_assert_eq"];
45+
let inverted_macros = ["assert_ne", "debug_assert_ne"];
46+
47+
for mac in macros.iter().chain(inverted_macros.iter()) {
48+
if let Some(span) = is_direct_expn_of(e.span, mac) {
49+
if let Some([a, b]) = ast_utils::extract_assert_macro_args(e) {
50+
let nb_bool_args = is_bool_lit(a) as usize + is_bool_lit(b) as usize;
51+
52+
if nb_bool_args != 1 {
53+
// If there are two boolean arguments, we definitely don't understand
54+
// what's going on, so better leave things as is...
55+
//
56+
// Or there is simply no boolean and then we can leave things as is!
57+
return;
58+
}
59+
60+
let non_eq_mac = &mac[..mac.len() - 3];
61+
span_lint_and_sugg(
62+
cx,
63+
BOOL_ASSERT_COMPARISON,
64+
span,
65+
&format!("used `{}!` with a literal bool", mac),
66+
"replace it with",
67+
format!("{}!(..)", non_eq_mac),
68+
Applicability::MaybeIncorrect,
69+
);
70+
return;
71+
}
72+
}
73+
}
74+
}
75+
}

src/tools/clippy/clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
261261
}
262262
METHODS_WITH_NEGATION
263263
.iter()
264-
.cloned()
264+
.copied()
265265
.flat_map(|(a, b)| vec![(a, b), (b, a)])
266266
.find(|&(a, _)| {
267267
let path: &str = &path.ident.name.as_str();

0 commit comments

Comments
 (0)