Skip to content

Update Clippy #74792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f7acea2
Register redundant_field_names and non_expressive_names as early passes
flip1995 Apr 23, 2020
485229c
Fix fallout in redundant_field_names
flip1995 May 12, 2020
efd3dcf
Fix fallout in similar_names
flip1995 May 12, 2020
bb37a0f
Avoid triggering similar names on code from expansion
ebroto May 26, 2020
201999c
improve advice in iter_nth_zero
warner Jul 13, 2020
d067d03
Add test for `needless_range_loop` issue
Jul 14, 2020
6f25adb
Merge commit '2ca58e7dda4a9eb142599638c59dc04d15961175' into clippyup
flip1995 Jul 14, 2020
1267909
new lint: Returning unit from closures expecting Ord
matthiaskrgr Mar 30, 2020
e83b3eb
formatting nits
warner Jul 14, 2020
97d7a8b
Auto merge of #5737 - Uriopass:unit-for-ord, r=flip1995
bors Jul 14, 2020
128c5de
Auto merge of #5793 - warner:5783-nth-zero-next, r=flip1995
bors Jul 14, 2020
84cdce0
Auto merge of #5798 - mikerite:fix-2277-2, r=yaahc
bors Jul 14, 2020
f2f99be
Remove lots of `Symbol::as_str()` calls.
nnethercote Jul 8, 2020
29de25b
const_eval_resolve
lcnr Jul 2, 2020
c5b9463
improve naming
lcnr Jul 15, 2020
bf3104e
WithOptConstParam::dummy -> WithOptConstParam::unknown
lcnr Jul 15, 2020
a064045
Removing snippet from SHADOW_UNRELATED message.
Leulz Jul 13, 2020
d9bf74e
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 15, 2020
b3614b4
Auto merge of #5802 - flip1995:rustup, r=flip1995
bors Jul 15, 2020
9349441
Auto merge of #5788 - Leulz:shadow-unrelated-fix-rhs, r=flip1995
bors Jul 15, 2020
9aa3435
Merge remote-tracking branch 'upstream/rust-1.44.1' into backport_rem…
flip1995 Jul 16, 2020
bb67423
Auto merge of #5804 - flip1995:backport_remerge, r=flip1995
bors Jul 16, 2020
ef896fa
Fix deploy script for beta deployment
flip1995 Jul 16, 2020
c65eb4d
Track tag files, before checking for the diff
flip1995 Jul 16, 2020
cf383cf
Update changelog to beta-1.46
flip1995 Jul 16, 2020
aba0d24
Typo: Change Log -> Changelog
flip1995 Jul 16, 2020
d9bf9f0
Auto merge of #5806 - flip1995:deploy_beta_fix, r=phansch
bors Jul 16, 2020
c2cb565
Auto merge of #5807 - flip1995:changelog, r=yaahc
bors Jul 16, 2020
62db617
Avoid storing `SymbolStr` in a struct.
nnethercote Jul 13, 2020
70a41a9
Enable detecting multiple-argument panics
JarredAllen Jul 16, 2020
07867fd
Clean up dogfood fallout
JarredAllen Jul 16, 2020
3618b97
fix typos (found by codespell)
matthiaskrgr Jul 16, 2020
82c8f25
Auto merge of #5810 - matthiaskrgr:typos_2, r=Manishearth
bors Jul 17, 2020
57678c8
Auto merge of #5811 - JarredAllen:panic_multiple_args, r=phansch
bors Jul 17, 2020
5a20489
Rename TypeckTables to TypeckResults.
Lezzz Jul 17, 2020
e5105e8
Fix typo
giraffate Jul 17, 2020
1367f25
Auto merge of #5814 - giraffate:fix_typo, r=flip1995
bors Jul 17, 2020
7c5d4a4
Add test for correct behavior
JarredAllen Jul 17, 2020
e85b590
Fix bug in lint
JarredAllen Jul 17, 2020
3d3a13d
Fix sync fallout (fmt)
flip1995 Jul 17, 2020
9a945c7
Auto merge of #5817 - flip1995:rustup, r=flip1995
bors Jul 17, 2020
0f501ac
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 18, 2020
799eef6
Auto merge of #5818 - flip1995:rustup, r=flip1995
bors Jul 18, 2020
8cf4219
Auto merge of #5815 - JarredAllen:redundant_pattern_bugfix, r=flip1995
bors Jul 18, 2020
c720d82
redundant_closure_call - don't lint when used more than once
tnielens Jul 14, 2020
0fecaf1
redundant_closure_call - extract lint from misc_early.rs, adapt to La…
tnielens Jul 18, 2020
9603d96
redundant_closure_call - add support for shadowed closures
tnielens Jul 19, 2020
1ac8b85
redundant_closure_call - pr review
tnielens Jul 19, 2020
942e0e6
Auto merge of #5800 - montrivo:bugfix/redundant_closure, r=matthiaskrgr
bors Jul 19, 2020
a5cdd4a
Ignore not really redundant clones of ManuallyDrop
tmiasko Jul 20, 2020
61e3d8a
Auto merge of #5824 - tmiasko:manually-drop-clone, r=Manishearth
bors Jul 20, 2020
b7c8b96
trait_sel: only test predicates w/ no substs
davidtwco Jun 22, 2020
142a273
Use `(std::)f64::EPSILON` in the examples as suggested in the lints
JohnTitor Jul 21, 2020
8c83d5f
Auto merge of #5830 - flip1995:rustup, r=flip1995
bors Jul 21, 2020
bdc01c8
Update Usage section of README.md
flip1995 Jul 22, 2020
b4e4fa5
Auto merge of #5832 - rust-lang:update_usage_instr, r=Manishearth
bors Jul 23, 2020
79f948e
Auto merge of #5829 - JohnTitor:epsilon, r=flip1995
bors Jul 23, 2020
c81bbd0
Fix FP `useless_conversion`
giraffate Jul 25, 2020
da5a6fb
Auto merge of #5845 - giraffate:fix_fp_useless_conversion, r=yaahc
bors Jul 26, 2020
e4e1b8c
Merge commit 'da5a6fb1b65ec6581a67e942a3850f6bc15a552c' into clippyup
flip1995 Jul 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/tools/clippy/.github/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi

if [[ $BETA = "true" ]]; then
echo "Update documentation for the beta release"
cp -r out/master out/beta
cp -r out/master/* out/beta
fi

# Generate version index that is shown as root index page
Expand All @@ -33,12 +33,13 @@ cd out
git config user.name "GHA CI"
git config user.email "[email protected]"

if git diff --exit-code --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi

if [[ -n $TAG_NAME ]]; then
# track files, so that the following check works
git add --intent-to-add "$TAG_NAME"
if git diff --exit-code --quiet -- $TAG_NAME/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
# Add the new dir
git add "$TAG_NAME"
# Update the symlink
Expand All @@ -47,9 +48,17 @@ if [[ -n $TAG_NAME ]]; then
git add versions.json
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
elif [[ $BETA = "true" ]]; then
if git diff --exit-code --quiet -- beta/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add beta
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
else
if git diff --exit-code --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add .
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
fi
Expand Down
71 changes: 67 additions & 4 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,78 @@
# Change Log
# Changelog

All notable changes to this project will be documented in this file.
See [Changelog Update](doc/changelog_update.md) if you want to update this
document.

## Unreleased / In Rust Nightly

[7ea7cd1...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
[c2c07fa...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)

## Rust 1.46

Current beta, release 2020-08-27

[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)

### New lints

* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378)
* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597)
* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623)
* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637)

### Moves and Deprecations

* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667)

### Enhancements

* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695)

### False Positive Fixes

* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled
[#5656](https://github.com/rust-lang/rust-clippy/pull/5656)
* [`let_and_return`]: Don't lint if a temporary borrow is involved
[#5680](https://github.com/rust-lang/rust-clippy/pull/5680)
* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
* [`if_same_then_else`]: Don't assume multiplication is always commutative
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
* [`blacklisted_name`]: Remove `bar` from the default configuration
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)

### Suggestion Fixes/Improvements

* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code
[#4455](https://github.com/rust-lang/rust-clippy/pull/4455)
* Add auto applicable suggestion to [`macro_use_imports`]
[#5279](https://github.com/rust-lang/rust-clippy/pull/5279)

### ICE Fixes

* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709)

### Documentation Improvements

* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664)

### Others

* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver`
into `rustc` and passes all the given arguments to `rustc`. This is especially
useful for tools that need the `rustc` version Clippy was compiled with,
instead of the Clippy version. E.g. `clippy-driver --rustc --version` will
print the output of `rustc --version`.
[#5178](https://github.com/rust-lang/rust-clippy/pull/5178)
* New issue templates now make it easier to complain if Clippy is too annoying
or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735)

## Rust 1.45

Current beta, release 2020-07-16
Current stable, released 2020-07-16

[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)

Expand Down Expand Up @@ -87,7 +149,7 @@ and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/565

## Rust 1.44

Current stable, released 2020-06-04
Released 2020-06-04

[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)

Expand Down Expand Up @@ -1679,6 +1741,7 @@ Released 2018-09-13
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
Expand Down
6 changes: 2 additions & 4 deletions src/tools/clippy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ Table of contents:

## Usage

Since this is a tool for helping the developer of a library or application
write better code, it is recommended not to include Clippy as a hard dependency.
Options include using it as an optional dependency, as a cargo subcommand, or
as an included feature during build. These options are detailed below.
Below are instructions on how to use Clippy as a subcommand, compiled from source
or in Travis CI.

### As a cargo subcommand (`cargo clippy`)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ declare_deprecated_lint! {
///
/// **Deprecation reason:** Associated-constants are now preferred.
pub REPLACE_CONSTS,
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants"
}

declare_deprecated_lint! {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls.
///
/// **Why is this bad?** Derefencing by `&*x` or `&mut *x` is clearer and more concise,
/// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise,
/// when not part of a method chain.
///
/// **Example:**
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
..
} = item.kind
{
// Remember for each inherent implementation encoutered its span and generics
// Remember for each inherent implementation encountered its span and generics
// but filter out implementations that have generic params (type or lifetime)
// or are derived from a macro
if !in_macro(item.span) && generics.params.is_empty() {
Expand Down
16 changes: 12 additions & 4 deletions src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ mod ptr_offset_with_cast;
mod question_mark;
mod ranges;
mod redundant_clone;
mod redundant_closure_call;
mod redundant_field_names;
mod redundant_pub_crate;
mod redundant_static_lifetimes;
Expand All @@ -300,6 +301,7 @@ mod trivially_copy_pass_by_ref;
mod try_err;
mod types;
mod unicode;
mod unit_return_expecting_ord;
mod unnamed_address;
mod unnecessary_sort_by;
mod unnested_or_patterns;
Expand Down Expand Up @@ -462,7 +464,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
);
store.register_removed(
"clippy::replace_consts",
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants",
);
store.register_removed(
"clippy::regex_macro",
Expand Down Expand Up @@ -701,7 +703,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&misc_early::DOUBLE_NEG,
&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
&misc_early::MIXED_CASE_HEX_LITERALS,
&misc_early::REDUNDANT_CLOSURE_CALL,
&misc_early::REDUNDANT_PATTERN,
&misc_early::UNNEEDED_FIELD_PATTERN,
&misc_early::UNNEEDED_WILDCARD_PATTERN,
Expand Down Expand Up @@ -758,6 +759,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&ranges::RANGE_ZIP_WITH_LEN,
&ranges::REVERSED_EMPTY_RANGES,
&redundant_clone::REDUNDANT_CLONE,
&redundant_closure_call::REDUNDANT_CLOSURE_CALL,
&redundant_field_names::REDUNDANT_FIELD_NAMES,
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
Expand Down Expand Up @@ -826,6 +828,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&unicode::NON_ASCII_LITERAL,
&unicode::UNICODE_NOT_NFC,
&unicode::ZERO_WIDTH_SPACE,
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
&unnamed_address::FN_ADDRESS_COMPARISONS,
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
Expand Down Expand Up @@ -891,6 +894,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box attrs::Attributes);
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
store.register_late_pass(|| box unicode::Unicode);
store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd);
store.register_late_pass(|| box strings::StringAdd);
store.register_late_pass(|| box implicit_return::ImplicitReturn);
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
Expand Down Expand Up @@ -1015,6 +1019,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_early_pass(|| box int_plus_one::IntPlusOne);
store.register_early_pass(|| box formatting::Formatting);
store.register_early_pass(|| box misc_early::MiscEarlyLints);
store.register_early_pass(|| box redundant_closure_call::RedundantClosureCall);
store.register_late_pass(|| box redundant_closure_call::RedundantClosureCall);
store.register_early_pass(|| box returns::Return);
store.register_late_pass(|| box let_and_return::LetReturn);
store.register_early_pass(|| box collapsible_if::CollapsibleIf);
Expand Down Expand Up @@ -1356,7 +1362,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&misc_early::DOUBLE_NEG),
LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT),
LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS),
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
LintId::of(&misc_early::REDUNDANT_PATTERN),
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
Expand Down Expand Up @@ -1390,6 +1395,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
LintId::of(&redundant_clone::REDUNDANT_CLONE),
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
LintId::of(&reference::DEREF_ADDROF),
Expand Down Expand Up @@ -1436,6 +1442,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::UNNECESSARY_CAST),
LintId::of(&types::VEC_BOX),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
Expand Down Expand Up @@ -1589,7 +1596,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::UNNECESSARY_FILTER_MAP),
LintId::of(&methods::USELESS_ASREF),
LintId::of(&misc::SHORT_CIRCUIT_STATEMENT),
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
LintId::of(&needless_bool::BOOL_COMPARISON),
Expand All @@ -1604,6 +1610,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&precedence::PRECEDENCE),
LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST),
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
LintId::of(&reference::DEREF_ADDROF),
LintId::of(&reference::REF_IN_DEREF),
LintId::of(&repeat_once::REPEAT_ONCE),
Expand Down Expand Up @@ -1692,6 +1699,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::CAST_REF_TO_MUT),
LintId::of(&types::UNIT_CMP),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
Expand Down
14 changes: 11 additions & 3 deletions src/tools/clippy/clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
}
}

let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then(
cx,
REDUNDANT_PATTERN_MATCHING,
Expand All @@ -1524,7 +1528,7 @@ mod redundant_pattern_match {

// while let ... = ... { ... }
// ^^^
let op_span = op.span.source_callsite();
let op_span = result_expr.span.source_callsite();

// while let ... = ... { ... }
// ^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
};

if let Some(good_method) = found_good_method {
let span = expr.span.to(op.span);
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then(
cx,
REDUNDANT_PATTERN_MATCHING,
expr.span,
&format!("redundant pattern matching, consider using `{}`", good_method),
|diag| {
let span = expr.span.to(op.span);
diag.span_suggestion(
span,
"try this",
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
Applicability::MaybeIncorrect, // snippet
);
},
Expand Down
11 changes: 8 additions & 3 deletions src/tools/clippy/clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,8 +2354,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
cx,
ITER_NTH_ZERO,
expr.span,
"called `.nth(0)` on a `std::iter::Iterator`",
"try calling",
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
"try calling `.next()` instead of `.nth(0)`",
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
applicability,
);
Expand Down Expand Up @@ -3290,7 +3290,12 @@ fn lint_option_as_ref_deref<'tcx>(
if let hir::ExprKind::Path(qpath) = &args[0].kind;
if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
if closure_body.params[0].pat.hir_id == local_id;
let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
let adj = cx
.typeck_results()
.expr_adjustments(&args[0])
.iter()
.map(|x| &x.kind)
.collect::<Box<[_]>>();
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
Expand Down
10 changes: 7 additions & 3 deletions src/tools/clippy/clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ declare_clippy_lint! {
/// if y != x {} // where both are floats
///
/// // Good
/// let error = 0.01f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (y - 1.23f64).abs() < error { }
/// if (y - x).abs() > error { }
/// ```
Expand Down Expand Up @@ -237,10 +239,12 @@ declare_clippy_lint! {
/// const ONE: f64 = 1.00;
///
/// // Bad
/// if x == ONE { } // where both are floats
/// if x == ONE { } // where both are floats
///
/// // Good
/// let error = 0.1f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (x - ONE).abs() < error { }
/// ```
pub FLOAT_CMP_CONST,
Expand Down
Loading