Auto merge of #74792 - flip1995:clippyup, r=Manishearth
Update Clippy Biweekly Clippy Sync r? @Manishearth
This commit is contained in:
commit
6c8927b0cf
54 changed files with 849 additions and 268 deletions
21
src/tools/clippy/.github/deploy.sh
vendored
21
src/tools/clippy/.github/deploy.sh
vendored
|
@ -19,7 +19,7 @@ fi
|
||||||
|
|
||||||
if [[ $BETA = "true" ]]; then
|
if [[ $BETA = "true" ]]; then
|
||||||
echo "Update documentation for the beta release"
|
echo "Update documentation for the beta release"
|
||||||
cp -r out/master out/beta
|
cp -r out/master/* out/beta
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate version index that is shown as root index page
|
# Generate version index that is shown as root index page
|
||||||
|
@ -33,12 +33,13 @@ cd out
|
||||||
git config user.name "GHA CI"
|
git config user.name "GHA CI"
|
||||||
git config user.email "gha@ci.invalid"
|
git config user.email "gha@ci.invalid"
|
||||||
|
|
||||||
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
|
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
|
# Add the new dir
|
||||||
git add "$TAG_NAME"
|
git add "$TAG_NAME"
|
||||||
# Update the symlink
|
# Update the symlink
|
||||||
|
@ -47,9 +48,17 @@ if [[ -n $TAG_NAME ]]; then
|
||||||
git add versions.json
|
git add versions.json
|
||||||
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
|
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
|
||||||
elif [[ $BETA = "true" ]]; then
|
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 add beta
|
||||||
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
|
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
|
||||||
else
|
else
|
||||||
|
if git diff --exit-code --quiet; then
|
||||||
|
echo "No changes to the output on this push; exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
|
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Change Log
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
See [Changelog Update](doc/changelog_update.md) if you want to update this
|
||||||
|
@ -6,11 +6,73 @@ document.
|
||||||
|
|
||||||
## Unreleased / In Rust Nightly
|
## 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
|
## 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)
|
[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)
|
||||||
|
|
||||||
|
@ -87,7 +149,7 @@ and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/565
|
||||||
|
|
||||||
## Rust 1.44
|
## 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)
|
[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)
|
||||||
|
|
||||||
|
@ -1679,6 +1741,7 @@ Released 2018-09-13
|
||||||
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
|
[`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_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_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
|
[`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_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
|
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
|
||||||
|
|
|
@ -42,10 +42,8 @@ Table of contents:
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Since this is a tool for helping the developer of a library or application
|
Below are instructions on how to use Clippy as a subcommand, compiled from source
|
||||||
write better code, it is recommended not to include Clippy as a hard dependency.
|
or in Travis CI.
|
||||||
Options include using it as an optional dependency, as a cargo subcommand, or
|
|
||||||
as an included feature during build. These options are detailed below.
|
|
||||||
|
|
||||||
### As a cargo subcommand (`cargo clippy`)
|
### As a cargo subcommand (`cargo clippy`)
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ declare_deprecated_lint! {
|
||||||
///
|
///
|
||||||
/// **Deprecation reason:** Associated-constants are now preferred.
|
/// **Deprecation reason:** Associated-constants are now preferred.
|
||||||
pub REPLACE_CONSTS,
|
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! {
|
declare_deprecated_lint! {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls.
|
/// **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.
|
/// when not part of a method chain.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
||||||
..
|
..
|
||||||
} = item.kind
|
} = 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)
|
// but filter out implementations that have generic params (type or lifetime)
|
||||||
// or are derived from a macro
|
// or are derived from a macro
|
||||||
if !in_macro(item.span) && generics.params.is_empty() {
|
if !in_macro(item.span) && generics.params.is_empty() {
|
||||||
|
|
|
@ -276,6 +276,7 @@ mod ptr_offset_with_cast;
|
||||||
mod question_mark;
|
mod question_mark;
|
||||||
mod ranges;
|
mod ranges;
|
||||||
mod redundant_clone;
|
mod redundant_clone;
|
||||||
|
mod redundant_closure_call;
|
||||||
mod redundant_field_names;
|
mod redundant_field_names;
|
||||||
mod redundant_pub_crate;
|
mod redundant_pub_crate;
|
||||||
mod redundant_static_lifetimes;
|
mod redundant_static_lifetimes;
|
||||||
|
@ -300,6 +301,7 @@ mod trivially_copy_pass_by_ref;
|
||||||
mod try_err;
|
mod try_err;
|
||||||
mod types;
|
mod types;
|
||||||
mod unicode;
|
mod unicode;
|
||||||
|
mod unit_return_expecting_ord;
|
||||||
mod unnamed_address;
|
mod unnamed_address;
|
||||||
mod unnecessary_sort_by;
|
mod unnecessary_sort_by;
|
||||||
mod unnested_or_patterns;
|
mod unnested_or_patterns;
|
||||||
|
@ -462,7 +464,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
);
|
);
|
||||||
store.register_removed(
|
store.register_removed(
|
||||||
"clippy::replace_consts",
|
"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(
|
store.register_removed(
|
||||||
"clippy::regex_macro",
|
"clippy::regex_macro",
|
||||||
|
@ -701,7 +703,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
&misc_early::DOUBLE_NEG,
|
&misc_early::DOUBLE_NEG,
|
||||||
&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
|
&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
|
||||||
&misc_early::MIXED_CASE_HEX_LITERALS,
|
&misc_early::MIXED_CASE_HEX_LITERALS,
|
||||||
&misc_early::REDUNDANT_CLOSURE_CALL,
|
|
||||||
&misc_early::REDUNDANT_PATTERN,
|
&misc_early::REDUNDANT_PATTERN,
|
||||||
&misc_early::UNNEEDED_FIELD_PATTERN,
|
&misc_early::UNNEEDED_FIELD_PATTERN,
|
||||||
&misc_early::UNNEEDED_WILDCARD_PATTERN,
|
&misc_early::UNNEEDED_WILDCARD_PATTERN,
|
||||||
|
@ -758,6 +759,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
&ranges::RANGE_ZIP_WITH_LEN,
|
&ranges::RANGE_ZIP_WITH_LEN,
|
||||||
&ranges::REVERSED_EMPTY_RANGES,
|
&ranges::REVERSED_EMPTY_RANGES,
|
||||||
&redundant_clone::REDUNDANT_CLONE,
|
&redundant_clone::REDUNDANT_CLONE,
|
||||||
|
&redundant_closure_call::REDUNDANT_CLOSURE_CALL,
|
||||||
&redundant_field_names::REDUNDANT_FIELD_NAMES,
|
&redundant_field_names::REDUNDANT_FIELD_NAMES,
|
||||||
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
|
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
|
||||||
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
|
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
|
||||||
|
@ -826,6 +828,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
&unicode::NON_ASCII_LITERAL,
|
&unicode::NON_ASCII_LITERAL,
|
||||||
&unicode::UNICODE_NOT_NFC,
|
&unicode::UNICODE_NOT_NFC,
|
||||||
&unicode::ZERO_WIDTH_SPACE,
|
&unicode::ZERO_WIDTH_SPACE,
|
||||||
|
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
|
||||||
&unnamed_address::FN_ADDRESS_COMPARISONS,
|
&unnamed_address::FN_ADDRESS_COMPARISONS,
|
||||||
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
|
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
|
||||||
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
|
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
|
||||||
|
@ -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 attrs::Attributes);
|
||||||
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
|
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
|
||||||
store.register_late_pass(|| box unicode::Unicode);
|
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 strings::StringAdd);
|
||||||
store.register_late_pass(|| box implicit_return::ImplicitReturn);
|
store.register_late_pass(|| box implicit_return::ImplicitReturn);
|
||||||
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
|
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
|
||||||
|
@ -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 int_plus_one::IntPlusOne);
|
||||||
store.register_early_pass(|| box formatting::Formatting);
|
store.register_early_pass(|| box formatting::Formatting);
|
||||||
store.register_early_pass(|| box misc_early::MiscEarlyLints);
|
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_early_pass(|| box returns::Return);
|
||||||
store.register_late_pass(|| box let_and_return::LetReturn);
|
store.register_late_pass(|| box let_and_return::LetReturn);
|
||||||
store.register_early_pass(|| box collapsible_if::CollapsibleIf);
|
store.register_early_pass(|| box collapsible_if::CollapsibleIf);
|
||||||
|
@ -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::DOUBLE_NEG),
|
||||||
LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT),
|
LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT),
|
||||||
LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS),
|
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::REDUNDANT_PATTERN),
|
||||||
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
|
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
|
||||||
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
|
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
|
||||||
|
@ -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::RANGE_ZIP_WITH_LEN),
|
||||||
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
|
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
|
||||||
LintId::of(&redundant_clone::REDUNDANT_CLONE),
|
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_field_names::REDUNDANT_FIELD_NAMES),
|
||||||
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
|
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
|
||||||
LintId::of(&reference::DEREF_ADDROF),
|
LintId::of(&reference::DEREF_ADDROF),
|
||||||
|
@ -1436,6 +1442,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
LintId::of(&types::UNNECESSARY_CAST),
|
LintId::of(&types::UNNECESSARY_CAST),
|
||||||
LintId::of(&types::VEC_BOX),
|
LintId::of(&types::VEC_BOX),
|
||||||
LintId::of(&unicode::ZERO_WIDTH_SPACE),
|
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::FN_ADDRESS_COMPARISONS),
|
||||||
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
|
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
|
||||||
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
|
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
|
||||||
|
@ -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::UNNECESSARY_FILTER_MAP),
|
||||||
LintId::of(&methods::USELESS_ASREF),
|
LintId::of(&methods::USELESS_ASREF),
|
||||||
LintId::of(&misc::SHORT_CIRCUIT_STATEMENT),
|
LintId::of(&misc::SHORT_CIRCUIT_STATEMENT),
|
||||||
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
|
|
||||||
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
|
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
|
||||||
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
|
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
|
||||||
LintId::of(&needless_bool::BOOL_COMPARISON),
|
LintId::of(&needless_bool::BOOL_COMPARISON),
|
||||||
|
@ -1604,6 +1610,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||||
LintId::of(&precedence::PRECEDENCE),
|
LintId::of(&precedence::PRECEDENCE),
|
||||||
LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST),
|
LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST),
|
||||||
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
|
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
|
||||||
|
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
|
||||||
LintId::of(&reference::DEREF_ADDROF),
|
LintId::of(&reference::DEREF_ADDROF),
|
||||||
LintId::of(&reference::REF_IN_DEREF),
|
LintId::of(&reference::REF_IN_DEREF),
|
||||||
LintId::of(&repeat_once::REPEAT_ONCE),
|
LintId::of(&repeat_once::REPEAT_ONCE),
|
||||||
|
@ -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::CAST_REF_TO_MUT),
|
||||||
LintId::of(&types::UNIT_CMP),
|
LintId::of(&types::UNIT_CMP),
|
||||||
LintId::of(&unicode::ZERO_WIDTH_SPACE),
|
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::FN_ADDRESS_COMPARISONS),
|
||||||
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
|
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
|
||||||
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
|
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
|
||||||
|
|
|
@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let result_expr = match &op.kind {
|
||||||
|
ExprKind::AddrOf(_, _, borrowed) => borrowed,
|
||||||
|
_ => op,
|
||||||
|
};
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_PATTERN_MATCHING,
|
REDUNDANT_PATTERN_MATCHING,
|
||||||
|
@ -1524,7 +1528,7 @@ mod redundant_pattern_match {
|
||||||
|
|
||||||
// while let ... = ... { ... }
|
// while let ... = ... { ... }
|
||||||
// ^^^
|
// ^^^
|
||||||
let op_span = op.span.source_callsite();
|
let op_span = result_expr.span.source_callsite();
|
||||||
|
|
||||||
// while let ... = ... { ... }
|
// while let ... = ... { ... }
|
||||||
// ^^^^^^^^^^^^^^^^^^^
|
// ^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(good_method) = found_good_method {
|
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(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_PATTERN_MATCHING,
|
REDUNDANT_PATTERN_MATCHING,
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("redundant pattern matching, consider using `{}`", good_method),
|
&format!("redundant pattern matching, consider using `{}`", good_method),
|
||||||
|diag| {
|
|diag| {
|
||||||
let span = expr.span.to(op.span);
|
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
|
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
|
||||||
Applicability::MaybeIncorrect, // snippet
|
Applicability::MaybeIncorrect, // snippet
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -2354,8 +2354,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
|
||||||
cx,
|
cx,
|
||||||
ITER_NTH_ZERO,
|
ITER_NTH_ZERO,
|
||||||
expr.span,
|
expr.span,
|
||||||
"called `.nth(0)` on a `std::iter::Iterator`",
|
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
|
||||||
"try calling",
|
"try calling `.next()` instead of `.nth(0)`",
|
||||||
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
|
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
|
||||||
applicability,
|
applicability,
|
||||||
);
|
);
|
||||||
|
@ -3290,7 +3290,12 @@ fn lint_option_as_ref_deref<'tcx>(
|
||||||
if let hir::ExprKind::Path(qpath) = &args[0].kind;
|
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 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;
|
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;
|
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
|
||||||
then {
|
then {
|
||||||
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
|
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
|
||||||
|
|
|
@ -99,7 +99,9 @@ declare_clippy_lint! {
|
||||||
/// if y != x {} // where both are floats
|
/// if y != x {} // where both are floats
|
||||||
///
|
///
|
||||||
/// // Good
|
/// // 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 - 1.23f64).abs() < error { }
|
||||||
/// if (y - x).abs() > error { }
|
/// if (y - x).abs() > error { }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -237,10 +239,12 @@ declare_clippy_lint! {
|
||||||
/// const ONE: f64 = 1.00;
|
/// const ONE: f64 = 1.00;
|
||||||
///
|
///
|
||||||
/// // Bad
|
/// // Bad
|
||||||
/// if x == ONE { } // where both are floats
|
/// if x == ONE { } // where both are floats
|
||||||
///
|
///
|
||||||
/// // Good
|
/// // 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 { }
|
/// if (x - ONE).abs() < error { }
|
||||||
/// ```
|
/// ```
|
||||||
pub FLOAT_CMP_CONST,
|
pub FLOAT_CMP_CONST,
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
use crate::utils::{
|
use crate::utils::{constants, snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
|
||||||
constants, snippet_opt, snippet_with_applicability, span_lint, span_lint_and_help, span_lint_and_sugg,
|
|
||||||
span_lint_and_then,
|
|
||||||
};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use rustc_ast::ast::{
|
use rustc_ast::ast::{
|
||||||
BindingMode, Block, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
|
BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
|
||||||
NodeId, Pat, PatKind, StmtKind, UnOp,
|
NodeId, Pat, PatKind, UnOp,
|
||||||
};
|
};
|
||||||
use rustc_ast::visit::{walk_expr, FnKind, Visitor};
|
use rustc_ast::visit::FnKind;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||||
|
@ -70,28 +66,6 @@ declare_clippy_lint! {
|
||||||
"function arguments having names which only differ by an underscore"
|
"function arguments having names which only differ by an underscore"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_clippy_lint! {
|
|
||||||
/// **What it does:** Detects closures called in the same expression where they
|
|
||||||
/// are defined.
|
|
||||||
///
|
|
||||||
/// **Why is this bad?** It is unnecessarily adding to the expression's
|
|
||||||
/// complexity.
|
|
||||||
///
|
|
||||||
/// **Known problems:** None.
|
|
||||||
///
|
|
||||||
/// **Example:**
|
|
||||||
/// ```rust,ignore
|
|
||||||
/// // Bad
|
|
||||||
/// let a = (|| 42)()
|
|
||||||
///
|
|
||||||
/// // Good
|
|
||||||
/// let a = 42
|
|
||||||
/// ```
|
|
||||||
pub REDUNDANT_CLOSURE_CALL,
|
|
||||||
complexity,
|
|
||||||
"throwaway closures called in the expression they are defined"
|
|
||||||
}
|
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Detects expressions of the form `--x`.
|
/// **What it does:** Detects expressions of the form `--x`.
|
||||||
///
|
///
|
||||||
|
@ -278,7 +252,6 @@ declare_clippy_lint! {
|
||||||
declare_lint_pass!(MiscEarlyLints => [
|
declare_lint_pass!(MiscEarlyLints => [
|
||||||
UNNEEDED_FIELD_PATTERN,
|
UNNEEDED_FIELD_PATTERN,
|
||||||
DUPLICATE_UNDERSCORE_ARGUMENT,
|
DUPLICATE_UNDERSCORE_ARGUMENT,
|
||||||
REDUNDANT_CLOSURE_CALL,
|
|
||||||
DOUBLE_NEG,
|
DOUBLE_NEG,
|
||||||
MIXED_CASE_HEX_LITERALS,
|
MIXED_CASE_HEX_LITERALS,
|
||||||
UNSEPARATED_LITERAL_SUFFIX,
|
UNSEPARATED_LITERAL_SUFFIX,
|
||||||
|
@ -288,30 +261,6 @@ declare_lint_pass!(MiscEarlyLints => [
|
||||||
UNNEEDED_WILDCARD_PATTERN,
|
UNNEEDED_WILDCARD_PATTERN,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Used to find `return` statements or equivalents e.g., `?`
|
|
||||||
struct ReturnVisitor {
|
|
||||||
found_return: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ReturnVisitor {
|
|
||||||
#[must_use]
|
|
||||||
fn new() -> Self {
|
|
||||||
Self { found_return: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ast> Visitor<'ast> for ReturnVisitor {
|
|
||||||
fn visit_expr(&mut self, ex: &'ast Expr) {
|
|
||||||
if let ExprKind::Ret(_) = ex.kind {
|
|
||||||
self.found_return = true;
|
|
||||||
} else if let ExprKind::Try(_) = ex.kind {
|
|
||||||
self.found_return = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
walk_expr(self, ex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EarlyLintPass for MiscEarlyLints {
|
impl EarlyLintPass for MiscEarlyLints {
|
||||||
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
|
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
|
||||||
for param in &gen.params {
|
for param in &gen.params {
|
||||||
|
@ -453,30 +402,6 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Call(ref paren, _) => {
|
|
||||||
if let ExprKind::Paren(ref closure) = paren.kind {
|
|
||||||
if let ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.kind {
|
|
||||||
let mut visitor = ReturnVisitor::new();
|
|
||||||
visitor.visit_expr(block);
|
|
||||||
if !visitor.found_return {
|
|
||||||
span_lint_and_then(
|
|
||||||
cx,
|
|
||||||
REDUNDANT_CLOSURE_CALL,
|
|
||||||
expr.span,
|
|
||||||
"Try not to call a closure in the expression where it is declared.",
|
|
||||||
|diag| {
|
|
||||||
if decl.inputs.is_empty() {
|
|
||||||
let mut app = Applicability::MachineApplicable;
|
|
||||||
let hint =
|
|
||||||
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
|
|
||||||
diag.span_suggestion(expr.span, "Try doing something like: ", hint, app);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ExprKind::Unary(UnOp::Neg, ref inner) => {
|
ExprKind::Unary(UnOp::Neg, ref inner) => {
|
||||||
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
|
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
|
||||||
span_lint(
|
span_lint(
|
||||||
|
@ -491,31 +416,6 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
|
|
||||||
for w in block.stmts.windows(2) {
|
|
||||||
if_chain! {
|
|
||||||
if let StmtKind::Local(ref local) = w[0].kind;
|
|
||||||
if let Option::Some(ref t) = local.init;
|
|
||||||
if let ExprKind::Closure(..) = t.kind;
|
|
||||||
if let PatKind::Ident(_, ident, _) = local.pat.kind;
|
|
||||||
if let StmtKind::Semi(ref second) = w[1].kind;
|
|
||||||
if let ExprKind::Assign(_, ref call, _) = second.kind;
|
|
||||||
if let ExprKind::Call(ref closure, _) = call.kind;
|
|
||||||
if let ExprKind::Path(_, ref path) = closure.kind;
|
|
||||||
then {
|
|
||||||
if ident == path.segments[0].ident {
|
|
||||||
span_lint(
|
|
||||||
cx,
|
|
||||||
REDUNDANT_CLOSURE_CALL,
|
|
||||||
second.span,
|
|
||||||
"Closure called just once immediately after it was declared",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MiscEarlyLints {
|
impl MiscEarlyLints {
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
||||||
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
|
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
|
||||||
/// can't be made const then, because `drop` can't be const-evaluated.
|
/// can't be made const then, because `drop` can't be const-evaluated.
|
||||||
fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool {
|
fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool {
|
||||||
// If any of the params are dropable, return true
|
// If any of the params are droppable, return true
|
||||||
param_tys.iter().any(|hir_ty| {
|
param_tys.iter().any(|hir_ty| {
|
||||||
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||||
has_drop(cx, ty_ty)
|
has_drop(cx, ty_ty)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for modulo arithemtic.
|
/// **What it does:** Checks for modulo arithmetic.
|
||||||
///
|
///
|
||||||
/// **Why is this bad?** The results of modulo (%) operation might differ
|
/// **Why is this bad?** The results of modulo (%) operation might differ
|
||||||
/// depending on the language, when negative numbers are involved.
|
/// depending on the language, when negative numbers are involved.
|
||||||
|
|
|
@ -218,12 +218,16 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
||||||
let mut split_at = None;
|
let mut split_at = None;
|
||||||
match existing_name.len.cmp(&count) {
|
match existing_name.len.cmp(&count) {
|
||||||
Ordering::Greater => {
|
Ordering::Greater => {
|
||||||
if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) {
|
if existing_name.len - count != 1
|
||||||
|
|| levenstein_not_1(&interned_name, &existing_name.interned.as_str())
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ordering::Less => {
|
Ordering::Less => {
|
||||||
if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) {
|
if count - existing_name.len != 1
|
||||||
|
|| levenstein_not_1(&existing_name.interned.as_str(), &interned_name)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -79,7 +79,7 @@ fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A struct containing information about occurences of the
|
/// A struct containing information about occurrences of the
|
||||||
/// `if let Some(..) = .. else` construct that this lint detects.
|
/// `if let Some(..) = .. else` construct that this lint detects.
|
||||||
struct OptionIfLetElseOccurence {
|
struct OptionIfLetElseOccurence {
|
||||||
option: String,
|
option: String,
|
||||||
|
|
|
@ -96,23 +96,20 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Block(ref block, _) = expr.kind;
|
if let ExprKind::Block(ref block, _) = expr.kind;
|
||||||
if let Some(ref ex) = block.expr;
|
if let Some(ref ex) = block.expr;
|
||||||
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC);
|
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC)
|
||||||
if params.len() == 1;
|
.or_else(|| match_function_call(cx, ex, &paths::BEGIN_PANIC_FMT));
|
||||||
then {
|
then {
|
||||||
|
let span = get_outer_span(expr);
|
||||||
if is_expn_of(expr.span, "unimplemented").is_some() {
|
if is_expn_of(expr.span, "unimplemented").is_some() {
|
||||||
let span = get_outer_span(expr);
|
|
||||||
span_lint(cx, UNIMPLEMENTED, span,
|
span_lint(cx, UNIMPLEMENTED, span,
|
||||||
"`unimplemented` should not be present in production code");
|
"`unimplemented` should not be present in production code");
|
||||||
} else if is_expn_of(expr.span, "todo").is_some() {
|
} else if is_expn_of(expr.span, "todo").is_some() {
|
||||||
let span = get_outer_span(expr);
|
|
||||||
span_lint(cx, TODO, span,
|
span_lint(cx, TODO, span,
|
||||||
"`todo` should not be present in production code");
|
"`todo` should not be present in production code");
|
||||||
} else if is_expn_of(expr.span, "unreachable").is_some() {
|
} else if is_expn_of(expr.span, "unreachable").is_some() {
|
||||||
let span = get_outer_span(expr);
|
|
||||||
span_lint(cx, UNREACHABLE, span,
|
span_lint(cx, UNREACHABLE, span,
|
||||||
"`unreachable` should not be present in production code");
|
"`unreachable` should not be present in production code");
|
||||||
} else if is_expn_of(expr.span, "panic").is_some() {
|
} else if is_expn_of(expr.span, "panic").is_some() {
|
||||||
let span = get_outer_span(expr);
|
|
||||||
span_lint(cx, PANIC, span,
|
span_lint(cx, PANIC, span,
|
||||||
"`panic` should not be present in production code");
|
"`panic` should not be present in production code");
|
||||||
match_panic(params, expr, cx);
|
match_panic(params, expr, cx);
|
||||||
|
|
|
@ -124,6 +124,12 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let ty::Adt(ref def, _) = arg_ty.kind {
|
||||||
|
if match_def_path(cx, def.did, &paths::MEM_MANUALLY_DROP) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// `{ cloned = &arg; clone(move cloned); }` or `{ cloned = &arg; to_path_buf(cloned); }`
|
// `{ cloned = &arg; clone(move cloned); }` or `{ cloned = &arg; to_path_buf(cloned); }`
|
||||||
let (cloned, cannot_move_out) = unwrap_or_continue!(find_stmt_assigns_to(cx, mir, arg, from_borrow, bb));
|
let (cloned, cannot_move_out) = unwrap_or_continue!(find_stmt_assigns_to(cx, mir, arg, from_borrow, bb));
|
||||||
|
|
||||||
|
|
151
src/tools/clippy/clippy_lints/src/redundant_closure_call.rs
Normal file
151
src/tools/clippy/clippy_lints/src/redundant_closure_call.rs
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_then};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
use rustc_ast::ast;
|
||||||
|
use rustc_ast::visit as ast_visit;
|
||||||
|
use rustc_ast::visit::Visitor as AstVisitor;
|
||||||
|
use rustc_errors::Applicability;
|
||||||
|
use rustc_hir as hir;
|
||||||
|
use rustc_hir::intravisit as hir_visit;
|
||||||
|
use rustc_hir::intravisit::Visitor as HirVisitor;
|
||||||
|
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
|
||||||
|
use rustc_middle::hir::map::Map;
|
||||||
|
use rustc_middle::lint::in_external_macro;
|
||||||
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
|
declare_clippy_lint! {
|
||||||
|
/// **What it does:** Detects closures called in the same expression where they
|
||||||
|
/// are defined.
|
||||||
|
///
|
||||||
|
/// **Why is this bad?** It is unnecessarily adding to the expression's
|
||||||
|
/// complexity.
|
||||||
|
///
|
||||||
|
/// **Known problems:** None.
|
||||||
|
///
|
||||||
|
/// **Example:**
|
||||||
|
/// ```rust,ignore
|
||||||
|
/// // Bad
|
||||||
|
/// let a = (|| 42)()
|
||||||
|
///
|
||||||
|
/// // Good
|
||||||
|
/// let a = 42
|
||||||
|
/// ```
|
||||||
|
pub REDUNDANT_CLOSURE_CALL,
|
||||||
|
complexity,
|
||||||
|
"throwaway closures called in the expression they are defined"
|
||||||
|
}
|
||||||
|
|
||||||
|
declare_lint_pass!(RedundantClosureCall => [REDUNDANT_CLOSURE_CALL]);
|
||||||
|
|
||||||
|
// Used to find `return` statements or equivalents e.g., `?`
|
||||||
|
struct ReturnVisitor {
|
||||||
|
found_return: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReturnVisitor {
|
||||||
|
#[must_use]
|
||||||
|
fn new() -> Self {
|
||||||
|
Self { found_return: false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ast> ast_visit::Visitor<'ast> for ReturnVisitor {
|
||||||
|
fn visit_expr(&mut self, ex: &'ast ast::Expr) {
|
||||||
|
if let ast::ExprKind::Ret(_) = ex.kind {
|
||||||
|
self.found_return = true;
|
||||||
|
} else if let ast::ExprKind::Try(_) = ex.kind {
|
||||||
|
self.found_return = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_visit::walk_expr(self, ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EarlyLintPass for RedundantClosureCall {
|
||||||
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||||
|
if in_external_macro(cx.sess(), expr.span) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if_chain! {
|
||||||
|
if let ast::ExprKind::Call(ref paren, _) = expr.kind;
|
||||||
|
if let ast::ExprKind::Paren(ref closure) = paren.kind;
|
||||||
|
if let ast::ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.kind;
|
||||||
|
then {
|
||||||
|
let mut visitor = ReturnVisitor::new();
|
||||||
|
visitor.visit_expr(block);
|
||||||
|
if !visitor.found_return {
|
||||||
|
span_lint_and_then(
|
||||||
|
cx,
|
||||||
|
REDUNDANT_CLOSURE_CALL,
|
||||||
|
expr.span,
|
||||||
|
"try not to call a closure in the expression where it is declared.",
|
||||||
|
|diag| {
|
||||||
|
if decl.inputs.is_empty() {
|
||||||
|
let mut app = Applicability::MachineApplicable;
|
||||||
|
let hint =
|
||||||
|
snippet_with_applicability(cx, block.span, "..", &mut app).into_owned();
|
||||||
|
diag.span_suggestion(expr.span, "try doing something like", hint, app);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
|
||||||
|
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
|
||||||
|
fn count_closure_usage<'tcx>(block: &'tcx hir::Block<'_>, path: &'tcx hir::Path<'tcx>) -> usize {
|
||||||
|
struct ClosureUsageCount<'tcx> {
|
||||||
|
path: &'tcx hir::Path<'tcx>,
|
||||||
|
count: usize,
|
||||||
|
};
|
||||||
|
impl<'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'tcx> {
|
||||||
|
type Map = Map<'tcx>;
|
||||||
|
|
||||||
|
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||||
|
if_chain! {
|
||||||
|
if let hir::ExprKind::Call(ref closure, _) = expr.kind;
|
||||||
|
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = closure.kind;
|
||||||
|
if self.path.segments[0].ident == path.segments[0].ident
|
||||||
|
&& self.path.res == path.res;
|
||||||
|
then {
|
||||||
|
self.count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hir_visit::walk_expr(self, expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap<Self::Map> {
|
||||||
|
hir_visit::NestedVisitorMap::None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut closure_usage_count = ClosureUsageCount { path, count: 0 };
|
||||||
|
closure_usage_count.visit_block(block);
|
||||||
|
closure_usage_count.count
|
||||||
|
}
|
||||||
|
|
||||||
|
for w in block.stmts.windows(2) {
|
||||||
|
if_chain! {
|
||||||
|
if let hir::StmtKind::Local(ref local) = w[0].kind;
|
||||||
|
if let Option::Some(ref t) = local.init;
|
||||||
|
if let hir::ExprKind::Closure(..) = t.kind;
|
||||||
|
if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind;
|
||||||
|
if let hir::StmtKind::Semi(ref second) = w[1].kind;
|
||||||
|
if let hir::ExprKind::Assign(_, ref call, _) = second.kind;
|
||||||
|
if let hir::ExprKind::Call(ref closure, _) = call.kind;
|
||||||
|
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = closure.kind;
|
||||||
|
if ident == path.segments[0].ident;
|
||||||
|
if count_closure_usage(block, path) == 1;
|
||||||
|
then {
|
||||||
|
span_lint(
|
||||||
|
cx,
|
||||||
|
REDUNDANT_CLOSURE_CALL,
|
||||||
|
second.span,
|
||||||
|
"closure called just once immediately after it was declared",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -295,11 +295,7 @@ fn lint_shadow<'tcx>(
|
||||||
cx,
|
cx,
|
||||||
SHADOW_UNRELATED,
|
SHADOW_UNRELATED,
|
||||||
pattern_span,
|
pattern_span,
|
||||||
&format!(
|
&format!("`{}` is being shadowed", snippet(cx, pattern_span, "_")),
|
||||||
"`{}` is shadowed by `{}`",
|
|
||||||
snippet(cx, pattern_span, "_"),
|
|
||||||
snippet(cx, expr.span, "..")
|
|
||||||
),
|
|
||||||
|diag| {
|
|diag| {
|
||||||
diag.span_note(expr.span, "initialization happens here");
|
diag.span_note(expr.span, "initialization happens here");
|
||||||
diag.span_note(prev_span, "previous binding is here");
|
diag.span_note(prev_span, "previous binding is here");
|
||||||
|
|
177
src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs
Normal file
177
src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
use crate::utils::{get_trait_def_id, paths, span_lint, span_lint_and_help};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
use rustc_hir::def_id::DefId;
|
||||||
|
use rustc_hir::{Expr, ExprKind, StmtKind};
|
||||||
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
use rustc_middle::ty;
|
||||||
|
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
|
||||||
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
use rustc_span::{BytePos, Span};
|
||||||
|
|
||||||
|
declare_clippy_lint! {
|
||||||
|
/// **What it does:** Checks for functions that expect closures of type
|
||||||
|
/// Fn(...) -> Ord where the implemented closure returns the unit type.
|
||||||
|
/// The lint also suggests to remove the semi-colon at the end of the statement if present.
|
||||||
|
///
|
||||||
|
/// **Why is this bad?** Likely, returning the unit type is unintentional, and
|
||||||
|
/// could simply be caused by an extra semi-colon. Since () implements Ord
|
||||||
|
/// it doesn't cause a compilation error.
|
||||||
|
/// This is the same reasoning behind the unit_cmp lint.
|
||||||
|
///
|
||||||
|
/// **Known problems:** If returning unit is intentional, then there is no
|
||||||
|
/// way of specifying this without triggering needless_return lint
|
||||||
|
///
|
||||||
|
/// **Example:**
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// let mut twins = vec!((1,1), (2,2));
|
||||||
|
/// twins.sort_by_key(|x| { x.1; });
|
||||||
|
/// ```
|
||||||
|
pub UNIT_RETURN_EXPECTING_ORD,
|
||||||
|
correctness,
|
||||||
|
"fn arguments of type Fn(...) -> Ord returning the unit type ()."
|
||||||
|
}
|
||||||
|
|
||||||
|
declare_lint_pass!(UnitReturnExpectingOrd => [UNIT_RETURN_EXPECTING_ORD]);
|
||||||
|
|
||||||
|
fn get_trait_predicates_for_trait_id<'tcx>(
|
||||||
|
cx: &LateContext<'tcx>,
|
||||||
|
generics: GenericPredicates<'tcx>,
|
||||||
|
trait_id: Option<DefId>,
|
||||||
|
) -> Vec<TraitPredicate<'tcx>> {
|
||||||
|
let mut preds = Vec::new();
|
||||||
|
for (pred, _) in generics.predicates {
|
||||||
|
if_chain! {
|
||||||
|
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind();
|
||||||
|
let trait_pred = cx.tcx.erase_late_bound_regions(&poly_trait_pred);
|
||||||
|
if let Some(trait_def_id) = trait_id;
|
||||||
|
if trait_def_id == trait_pred.trait_ref.def_id;
|
||||||
|
then {
|
||||||
|
preds.push(trait_pred);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
preds
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_projection_pred<'tcx>(
|
||||||
|
cx: &LateContext<'tcx>,
|
||||||
|
generics: GenericPredicates<'tcx>,
|
||||||
|
pred: TraitPredicate<'tcx>,
|
||||||
|
) -> Option<ProjectionPredicate<'tcx>> {
|
||||||
|
generics.predicates.iter().find_map(|(proj_pred, _)| {
|
||||||
|
if let PredicateKind::Projection(proj_pred) = proj_pred.kind() {
|
||||||
|
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred);
|
||||||
|
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
|
||||||
|
return Some(projection_pred);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> {
|
||||||
|
let mut args_to_check = Vec::new();
|
||||||
|
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
|
||||||
|
let fn_sig = cx.tcx.fn_sig(def_id);
|
||||||
|
let generics = cx.tcx.predicates_of(def_id);
|
||||||
|
let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait());
|
||||||
|
let ord_preds = get_trait_predicates_for_trait_id(cx, generics, get_trait_def_id(cx, &paths::ORD));
|
||||||
|
let partial_ord_preds =
|
||||||
|
get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait());
|
||||||
|
// Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error
|
||||||
|
// The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]`
|
||||||
|
let inputs_output = cx.tcx.erase_late_bound_regions(&fn_sig.inputs_and_output());
|
||||||
|
inputs_output
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.skip(1)
|
||||||
|
.rev()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, inp)| {
|
||||||
|
for trait_pred in &fn_mut_preds {
|
||||||
|
if_chain! {
|
||||||
|
if trait_pred.self_ty() == inp;
|
||||||
|
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
|
||||||
|
then {
|
||||||
|
if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.ty) {
|
||||||
|
args_to_check.push((i, "Ord".to_string()));
|
||||||
|
} else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.ty) {
|
||||||
|
args_to_check.push((i, "PartialOrd".to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
args_to_check
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option<Span>)> {
|
||||||
|
if_chain! {
|
||||||
|
if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind;
|
||||||
|
if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind;
|
||||||
|
let ret_ty = substs.as_closure().sig().output();
|
||||||
|
let ty = cx.tcx.erase_late_bound_regions(&ret_ty);
|
||||||
|
if ty.is_unit();
|
||||||
|
then {
|
||||||
|
if_chain! {
|
||||||
|
let body = cx.tcx.hir().body(body_id);
|
||||||
|
if let ExprKind::Block(block, _) = body.value.kind;
|
||||||
|
if block.expr.is_none();
|
||||||
|
if let Some(stmt) = block.stmts.last();
|
||||||
|
if let StmtKind::Semi(_) = stmt.kind;
|
||||||
|
then {
|
||||||
|
let data = stmt.span.data();
|
||||||
|
// Make a span out of the semicolon for the help message
|
||||||
|
Some((span, Some(Span::new(data.hi-BytePos(1), data.hi, data.ctxt))))
|
||||||
|
} else {
|
||||||
|
Some((span, None))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd {
|
||||||
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
|
if let ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
|
||||||
|
let arg_indices = get_args_to_check(cx, expr);
|
||||||
|
for (i, trait_name) in arg_indices {
|
||||||
|
if i < args.len() {
|
||||||
|
match check_arg(cx, &args[i]) {
|
||||||
|
Some((span, None)) => {
|
||||||
|
span_lint(
|
||||||
|
cx,
|
||||||
|
UNIT_RETURN_EXPECTING_ORD,
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"this closure returns \
|
||||||
|
the unit type which also implements {}",
|
||||||
|
trait_name
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Some((span, Some(last_semi))) => {
|
||||||
|
span_lint_and_help(
|
||||||
|
cx,
|
||||||
|
UNIT_RETURN_EXPECTING_ORD,
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"this closure returns \
|
||||||
|
the unit type which also implements {}",
|
||||||
|
trait_name
|
||||||
|
),
|
||||||
|
Some(last_semi),
|
||||||
|
&"probably caused by this trailing semicolon".to_string(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
is_type_diagnostic_item, match_def_path, match_trait_method, paths, snippet, snippet_with_macro_callsite,
|
get_parent_expr, is_type_diagnostic_item, match_def_path, match_trait_method, paths, snippet,
|
||||||
span_lint_and_help, span_lint_and_sugg,
|
snippet_with_macro_callsite, span_lint_and_help, span_lint_and_sugg,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
@ -79,6 +79,13 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" {
|
if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" {
|
||||||
|
if let Some(parent_expr) = get_parent_expr(cx, e) {
|
||||||
|
if let ExprKind::MethodCall(ref parent_name, ..) = parent_expr.kind {
|
||||||
|
if &*parent_name.ident.as_str() != "into_iter" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let a = cx.typeck_results().expr_ty(e);
|
let a = cx.typeck_results().expr_ty(e);
|
||||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||||
if TyS::same_type(a, b) {
|
if TyS::same_type(a, b) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub struct NumericLiteral<'a> {
|
||||||
pub integer: &'a str,
|
pub integer: &'a str,
|
||||||
/// The fraction part of the number.
|
/// The fraction part of the number.
|
||||||
pub fraction: Option<&'a str>,
|
pub fraction: Option<&'a str>,
|
||||||
/// The character used as exponent seperator (b'e' or b'E') and the exponent part.
|
/// The character used as exponent separator (b'e' or b'E') and the exponent part.
|
||||||
pub exponent: Option<(char, &'a str)>,
|
pub exponent: Option<(char, &'a str)>,
|
||||||
|
|
||||||
/// The type suffix, including preceding underscore if present.
|
/// The type suffix, including preceding underscore if present.
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "Link
|
||||||
pub const LINT: [&str; 3] = ["rustc_session", "lint", "Lint"];
|
pub const LINT: [&str; 3] = ["rustc_session", "lint", "Lint"];
|
||||||
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
|
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
|
||||||
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
|
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
|
||||||
|
pub const MEM_MANUALLY_DROP: [&str; 4] = ["core", "mem", "manually_drop", "ManuallyDrop"];
|
||||||
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
|
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
|
||||||
pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"];
|
pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"];
|
||||||
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];
|
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];
|
||||||
|
|
|
@ -11,7 +11,7 @@ use rustc_ast::ast::LitKind;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Finds occurences of `Vec::resize(0, an_int)`
|
/// **What it does:** Finds occurrences of `Vec::resize(0, an_int)`
|
||||||
///
|
///
|
||||||
/// **Why is this bad?** This is probably an argument inversion mistake.
|
/// **Why is this bad?** This is probably an argument inversion mistake.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1835,7 +1835,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
|
||||||
group: "complexity",
|
group: "complexity",
|
||||||
desc: "throwaway closures called in the expression they are defined",
|
desc: "throwaway closures called in the expression they are defined",
|
||||||
deprecation: None,
|
deprecation: None,
|
||||||
module: "misc_early",
|
module: "redundant_closure_call",
|
||||||
},
|
},
|
||||||
Lint {
|
Lint {
|
||||||
name: "redundant_closure_for_method_calls",
|
name: "redundant_closure_for_method_calls",
|
||||||
|
@ -2292,6 +2292,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
|
||||||
deprecation: None,
|
deprecation: None,
|
||||||
module: "types",
|
module: "types",
|
||||||
},
|
},
|
||||||
|
Lint {
|
||||||
|
name: "unit_return_expecting_ord",
|
||||||
|
group: "correctness",
|
||||||
|
desc: "fn arguments of type Fn(...) -> Ord returning the unit type ().",
|
||||||
|
deprecation: None,
|
||||||
|
module: "unit_return_expecting_ord",
|
||||||
|
},
|
||||||
Lint {
|
Lint {
|
||||||
name: "unknown_clippy_lints",
|
name: "unknown_clippy_lints",
|
||||||
group: "style",
|
group: "style",
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||||
--> $DIR/iter_nth_zero.rs:20:14
|
--> $DIR/iter_nth_zero.rs:20:14
|
||||||
|
|
|
|
||||||
LL | let _x = s.iter().nth(0);
|
LL | let _x = s.iter().nth(0);
|
||||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.iter().next()`
|
| ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::iter-nth-zero` implied by `-D warnings`
|
= note: `-D clippy::iter-nth-zero` implied by `-D warnings`
|
||||||
|
|
||||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||||
--> $DIR/iter_nth_zero.rs:25:14
|
--> $DIR/iter_nth_zero.rs:25:14
|
||||||
|
|
|
|
||||||
LL | let _y = iter.nth(0);
|
LL | let _y = iter.nth(0);
|
||||||
| ^^^^^^^^^^^ help: try calling: `iter.next()`
|
| ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()`
|
||||||
|
|
||||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||||
--> $DIR/iter_nth_zero.rs:30:22
|
--> $DIR/iter_nth_zero.rs:30:22
|
||||||
|
|
|
|
||||||
LL | let _unwrapped = iter2.nth(0).unwrap();
|
LL | let _unwrapped = iter2.nth(0).unwrap();
|
||||||
| ^^^^^^^^^^^^ help: try calling: `iter2.next()`
|
| ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ async fn already_async() -> impl Future<Output = i32> {
|
||||||
struct S {}
|
struct S {}
|
||||||
impl S {
|
impl S {
|
||||||
async fn inh_fut() -> i32 {
|
async fn inh_fut() -> i32 {
|
||||||
// NOTE: this code is here just to check that the identation is correct in the suggested fix
|
// NOTE: this code is here just to check that the indentation is correct in the suggested fix
|
||||||
let a = 42;
|
let a = 42;
|
||||||
let b = 21;
|
let b = 21;
|
||||||
if a < b {
|
if a < b {
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct S {}
|
||||||
impl S {
|
impl S {
|
||||||
fn inh_fut() -> impl Future<Output = i32> {
|
fn inh_fut() -> impl Future<Output = i32> {
|
||||||
async {
|
async {
|
||||||
// NOTE: this code is here just to check that the identation is correct in the suggested fix
|
// NOTE: this code is here just to check that the indentation is correct in the suggested fix
|
||||||
let a = 42;
|
let a = 42;
|
||||||
let b = 21;
|
let b = 21;
|
||||||
if a < b {
|
if a < b {
|
||||||
|
|
|
@ -57,7 +57,7 @@ LL | async fn inh_fut() -> i32 {
|
||||||
help: move the body of the async block to the enclosing function
|
help: move the body of the async block to the enclosing function
|
||||||
|
|
|
|
||||||
LL | fn inh_fut() -> impl Future<Output = i32> {
|
LL | fn inh_fut() -> impl Future<Output = i32> {
|
||||||
LL | // NOTE: this code is here just to check that the identation is correct in the suggested fix
|
LL | // NOTE: this code is here just to check that the indentation is correct in the suggested fix
|
||||||
LL | let a = 42;
|
LL | let a = 42;
|
||||||
LL | let b = 21;
|
LL | let b = 21;
|
||||||
LL | if a < b {
|
LL | if a < b {
|
||||||
|
|
|
@ -83,3 +83,13 @@ fn main() {
|
||||||
println!("{}", arr[i]);
|
println!("{}", arr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue2277 {
|
||||||
|
pub fn example(list: &[[f64; 3]]) {
|
||||||
|
let mut x: [f64; 3] = [10.; 3];
|
||||||
|
|
||||||
|
for i in 0..3 {
|
||||||
|
x[i] = list.iter().map(|item| item[i]).sum::<f64>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub fn test14() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue #1991: the outter loop should not warn.
|
// Issue #1991: the outer loop should not warn.
|
||||||
pub fn test15() {
|
pub fn test15() {
|
||||||
'label: loop {
|
'label: loop {
|
||||||
while false {
|
while false {
|
||||||
|
|
|
@ -4,24 +4,32 @@
|
||||||
fn panic() {
|
fn panic() {
|
||||||
let a = 2;
|
let a = 2;
|
||||||
panic!();
|
panic!();
|
||||||
|
panic!("message");
|
||||||
|
panic!("{} {}", "panic with", "multiple arguments");
|
||||||
let b = a + 2;
|
let b = a + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn todo() {
|
fn todo() {
|
||||||
let a = 2;
|
let a = 2;
|
||||||
todo!();
|
todo!();
|
||||||
|
todo!("message");
|
||||||
|
todo!("{} {}", "panic with", "multiple arguments");
|
||||||
let b = a + 2;
|
let b = a + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unimplemented() {
|
fn unimplemented() {
|
||||||
let a = 2;
|
let a = 2;
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
|
unimplemented!("message");
|
||||||
|
unimplemented!("{} {}", "panic with", "multiple arguments");
|
||||||
let b = a + 2;
|
let b = a + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unreachable() {
|
fn unreachable() {
|
||||||
let a = 2;
|
let a = 2;
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
unreachable!("message");
|
||||||
|
unreachable!("{} {}", "panic with", "multiple arguments");
|
||||||
let b = a + 2;
|
let b = a + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,29 +6,83 @@ LL | panic!();
|
||||||
|
|
|
|
||||||
= note: `-D clippy::panic` implied by `-D warnings`
|
= note: `-D clippy::panic` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: `panic` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:7:5
|
||||||
|
|
|
||||||
|
LL | panic!("message");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: `panic` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:8:5
|
||||||
|
|
|
||||||
|
LL | panic!("{} {}", "panic with", "multiple arguments");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: `todo` should not be present in production code
|
error: `todo` should not be present in production code
|
||||||
--> $DIR/panicking_macros.rs:12:5
|
--> $DIR/panicking_macros.rs:14:5
|
||||||
|
|
|
|
||||||
LL | todo!();
|
LL | todo!();
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::todo` implied by `-D warnings`
|
= note: `-D clippy::todo` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: `todo` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:15:5
|
||||||
|
|
|
||||||
|
LL | todo!("message");
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: `todo` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:16:5
|
||||||
|
|
|
||||||
|
LL | todo!("{} {}", "panic with", "multiple arguments");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: `unimplemented` should not be present in production code
|
error: `unimplemented` should not be present in production code
|
||||||
--> $DIR/panicking_macros.rs:18:5
|
--> $DIR/panicking_macros.rs:22:5
|
||||||
|
|
|
|
||||||
LL | unimplemented!();
|
LL | unimplemented!();
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::unimplemented` implied by `-D warnings`
|
= note: `-D clippy::unimplemented` implied by `-D warnings`
|
||||||
|
|
||||||
error: `unreachable` should not be present in production code
|
error: `unimplemented` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:23:5
|
||||||
|
|
|
||||||
|
LL | unimplemented!("message");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: `unimplemented` should not be present in production code
|
||||||
--> $DIR/panicking_macros.rs:24:5
|
--> $DIR/panicking_macros.rs:24:5
|
||||||
|
|
|
|
||||||
|
LL | unimplemented!("{} {}", "panic with", "multiple arguments");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: `unreachable` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:30:5
|
||||||
|
|
|
||||||
LL | unreachable!();
|
LL | unreachable!();
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::unreachable` implied by `-D warnings`
|
= note: `-D clippy::unreachable` implied by `-D warnings`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: `unreachable` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:31:5
|
||||||
|
|
|
||||||
|
LL | unreachable!("message");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: `unreachable` should not be present in production code
|
||||||
|
--> $DIR/panicking_macros.rs:32:5
|
||||||
|
|
|
||||||
|
LL | unreachable!("{} {}", "panic with", "multiple arguments");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn main() {
|
||||||
let _ = -(1i32.abs());
|
let _ = -(1i32.abs());
|
||||||
let _ = -(1f32.abs());
|
let _ = -(1f32.abs());
|
||||||
|
|
||||||
// Odd functions shoud not trigger an error
|
// Odd functions should not trigger an error
|
||||||
let _ = -1f64.asin();
|
let _ = -1f64.asin();
|
||||||
let _ = -1f64.asinh();
|
let _ = -1f64.asinh();
|
||||||
let _ = -1f64.atan();
|
let _ = -1f64.atan();
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn main() {
|
||||||
let _ = -(1i32.abs());
|
let _ = -(1i32.abs());
|
||||||
let _ = -(1f32.abs());
|
let _ = -(1f32.abs());
|
||||||
|
|
||||||
// Odd functions shoud not trigger an error
|
// Odd functions should not trigger an error
|
||||||
let _ = -1f64.asin();
|
let _ = -1f64.asin();
|
||||||
let _ = -1f64.asinh();
|
let _ = -1f64.asinh();
|
||||||
let _ = -1f64.atan();
|
let _ = -1f64.atan();
|
||||||
|
|
|
@ -52,6 +52,7 @@ fn main() {
|
||||||
borrower_propagation();
|
borrower_propagation();
|
||||||
not_consumed();
|
not_consumed();
|
||||||
issue_5405();
|
issue_5405();
|
||||||
|
manually_drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -170,3 +171,17 @@ fn issue_5405() {
|
||||||
let c: [usize; 2] = [2, 3];
|
let c: [usize; 2] = [2, 3];
|
||||||
let _d: usize = c[1].clone();
|
let _d: usize = c[1].clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn manually_drop() {
|
||||||
|
use std::mem::ManuallyDrop;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
let a = ManuallyDrop::new(Arc::new("Hello!".to_owned()));
|
||||||
|
let _ = a.clone(); // OK
|
||||||
|
|
||||||
|
let p: *const String = Arc::into_raw(ManuallyDrop::into_inner(a));
|
||||||
|
unsafe {
|
||||||
|
Arc::from_raw(p);
|
||||||
|
Arc::from_raw(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ fn main() {
|
||||||
borrower_propagation();
|
borrower_propagation();
|
||||||
not_consumed();
|
not_consumed();
|
||||||
issue_5405();
|
issue_5405();
|
||||||
|
manually_drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -170,3 +171,17 @@ fn issue_5405() {
|
||||||
let c: [usize; 2] = [2, 3];
|
let c: [usize; 2] = [2, 3];
|
||||||
let _d: usize = c[1].clone();
|
let _d: usize = c[1].clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn manually_drop() {
|
||||||
|
use std::mem::ManuallyDrop;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
let a = ManuallyDrop::new(Arc::new("Hello!".to_owned()));
|
||||||
|
let _ = a.clone(); // OK
|
||||||
|
|
||||||
|
let p: *const String = Arc::into_raw(ManuallyDrop::into_inner(a));
|
||||||
|
unsafe {
|
||||||
|
Arc::from_raw(p);
|
||||||
|
Arc::from_raw(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -108,61 +108,61 @@ LL | let _t = tup.0.clone();
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: redundant clone
|
error: redundant clone
|
||||||
--> $DIR/redundant_clone.rs:61:22
|
--> $DIR/redundant_clone.rs:62:22
|
||||||
|
|
|
|
||||||
LL | (a.clone(), a.clone())
|
LL | (a.clone(), a.clone())
|
||||||
| ^^^^^^^^ help: remove this
|
| ^^^^^^^^ help: remove this
|
||||||
|
|
|
|
||||||
note: this value is dropped without further use
|
note: this value is dropped without further use
|
||||||
--> $DIR/redundant_clone.rs:61:21
|
--> $DIR/redundant_clone.rs:62:21
|
||||||
|
|
|
|
||||||
LL | (a.clone(), a.clone())
|
LL | (a.clone(), a.clone())
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: redundant clone
|
|
||||||
--> $DIR/redundant_clone.rs:121:15
|
|
||||||
|
|
|
||||||
LL | let _s = s.clone();
|
|
||||||
| ^^^^^^^^ help: remove this
|
|
||||||
|
|
|
||||||
note: this value is dropped without further use
|
|
||||||
--> $DIR/redundant_clone.rs:121:14
|
|
||||||
|
|
|
||||||
LL | let _s = s.clone();
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: redundant clone
|
error: redundant clone
|
||||||
--> $DIR/redundant_clone.rs:122:15
|
--> $DIR/redundant_clone.rs:122:15
|
||||||
|
|
|
|
||||||
LL | let _t = t.clone();
|
LL | let _s = s.clone();
|
||||||
| ^^^^^^^^ help: remove this
|
| ^^^^^^^^ help: remove this
|
||||||
|
|
|
|
||||||
note: this value is dropped without further use
|
note: this value is dropped without further use
|
||||||
--> $DIR/redundant_clone.rs:122:14
|
--> $DIR/redundant_clone.rs:122:14
|
||||||
|
|
|
|
||||||
|
LL | let _s = s.clone();
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: redundant clone
|
||||||
|
--> $DIR/redundant_clone.rs:123:15
|
||||||
|
|
|
||||||
|
LL | let _t = t.clone();
|
||||||
|
| ^^^^^^^^ help: remove this
|
||||||
|
|
|
||||||
|
note: this value is dropped without further use
|
||||||
|
--> $DIR/redundant_clone.rs:123:14
|
||||||
|
|
|
||||||
LL | let _t = t.clone();
|
LL | let _t = t.clone();
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: redundant clone
|
error: redundant clone
|
||||||
--> $DIR/redundant_clone.rs:132:19
|
--> $DIR/redundant_clone.rs:133:19
|
||||||
|
|
|
|
||||||
LL | let _f = f.clone();
|
LL | let _f = f.clone();
|
||||||
| ^^^^^^^^ help: remove this
|
| ^^^^^^^^ help: remove this
|
||||||
|
|
|
|
||||||
note: this value is dropped without further use
|
note: this value is dropped without further use
|
||||||
--> $DIR/redundant_clone.rs:132:18
|
--> $DIR/redundant_clone.rs:133:18
|
||||||
|
|
|
|
||||||
LL | let _f = f.clone();
|
LL | let _f = f.clone();
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: redundant clone
|
error: redundant clone
|
||||||
--> $DIR/redundant_clone.rs:144:14
|
--> $DIR/redundant_clone.rs:145:14
|
||||||
|
|
|
|
||||||
LL | let y = x.clone().join("matthias");
|
LL | let y = x.clone().join("matthias");
|
||||||
| ^^^^^^^^ help: remove this
|
| ^^^^^^^^ help: remove this
|
||||||
|
|
|
|
||||||
note: cloned value is neither consumed nor mutated
|
note: cloned value is neither consumed nor mutated
|
||||||
--> $DIR/redundant_clone.rs:144:13
|
--> $DIR/redundant_clone.rs:145:13
|
||||||
|
|
|
|
||||||
LL | let y = x.clone().join("matthias");
|
LL | let y = x.clone().join("matthias");
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
error: Closure called just once immediately after it was declared
|
|
||||||
--> $DIR/redundant_closure_call.rs:12:5
|
|
||||||
|
|
|
||||||
LL | i = closure();
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
|
|
||||||
|
|
||||||
error: Closure called just once immediately after it was declared
|
|
||||||
--> $DIR/redundant_closure_call.rs:15:5
|
|
||||||
|
|
|
||||||
LL | i = closure(3);
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: Try not to call a closure in the expression where it is declared.
|
|
||||||
--> $DIR/redundant_closure_call.rs:7:17
|
|
||||||
|
|
|
||||||
LL | let mut k = (|m| m + 1)(i);
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: Try not to call a closure in the expression where it is declared.
|
|
||||||
--> $DIR/redundant_closure_call.rs:9:9
|
|
||||||
|
|
|
||||||
LL | k = (|a, b| a * b)(1, 5);
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
|
||||||
|
|
|
@ -4,18 +4,14 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
|
|
||||||
|
// lint here
|
||||||
let mut k = (|m| m + 1)(i);
|
let mut k = (|m| m + 1)(i);
|
||||||
|
|
||||||
|
// lint here
|
||||||
k = (|a, b| a * b)(1, 5);
|
k = (|a, b| a * b)(1, 5);
|
||||||
|
|
||||||
let closure = || 32;
|
// don't lint these
|
||||||
i = closure();
|
|
||||||
|
|
||||||
let closure = |i| i + 1;
|
|
||||||
i = closure(3);
|
|
||||||
|
|
||||||
i = closure(4);
|
|
||||||
|
|
||||||
#[allow(clippy::needless_return)]
|
#[allow(clippy::needless_return)]
|
||||||
(|| return 2)();
|
(|| return 2)();
|
||||||
(|| -> Option<i32> { None? })();
|
(|| -> Option<i32> { None? })();
|
|
@ -0,0 +1,16 @@
|
||||||
|
error: try not to call a closure in the expression where it is declared.
|
||||||
|
--> $DIR/redundant_closure_call_early.rs:9:17
|
||||||
|
|
|
||||||
|
LL | let mut k = (|m| m + 1)(i);
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: try not to call a closure in the expression where it is declared.
|
||||||
|
--> $DIR/redundant_closure_call_early.rs:12:9
|
||||||
|
|
|
||||||
|
LL | k = (|a, b| a * b)(1, 5);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error: Try not to call a closure in the expression where it is declared.
|
error: try not to call a closure in the expression where it is declared.
|
||||||
--> $DIR/redundant_closure_call_fixable.rs:7:13
|
--> $DIR/redundant_closure_call_fixable.rs:7:13
|
||||||
|
|
|
|
||||||
LL | let a = (|| 42)();
|
LL | let a = (|| 42)();
|
||||||
| ^^^^^^^^^ help: Try doing something like: : `42`
|
| ^^^^^^^^^ help: try doing something like: `42`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
|
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
|
||||||
|
|
||||||
|
|
27
src/tools/clippy/tests/ui/redundant_closure_call_late.rs
Normal file
27
src/tools/clippy/tests/ui/redundant_closure_call_late.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// non rustfixable, see redundant_closure_call_fixable.rs
|
||||||
|
|
||||||
|
#![warn(clippy::redundant_closure_call)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut i = 1;
|
||||||
|
|
||||||
|
// don't lint here, the closure is used more than once
|
||||||
|
let closure = |i| i + 1;
|
||||||
|
i = closure(3);
|
||||||
|
i = closure(4);
|
||||||
|
|
||||||
|
// lint here
|
||||||
|
let redun_closure = || 1;
|
||||||
|
i = redun_closure();
|
||||||
|
|
||||||
|
// shadowed closures are supported, lint here
|
||||||
|
let shadowed_closure = || 1;
|
||||||
|
i = shadowed_closure();
|
||||||
|
let shadowed_closure = || 2;
|
||||||
|
i = shadowed_closure();
|
||||||
|
|
||||||
|
// don't lint here
|
||||||
|
let shadowed_closure = || 2;
|
||||||
|
i = shadowed_closure();
|
||||||
|
i = shadowed_closure();
|
||||||
|
}
|
22
src/tools/clippy/tests/ui/redundant_closure_call_late.stderr
Normal file
22
src/tools/clippy/tests/ui/redundant_closure_call_late.stderr
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
error: closure called just once immediately after it was declared
|
||||||
|
--> $DIR/redundant_closure_call_late.rs:15:5
|
||||||
|
|
|
||||||
|
LL | i = redun_closure();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: closure called just once immediately after it was declared
|
||||||
|
--> $DIR/redundant_closure_call_late.rs:19:5
|
||||||
|
|
|
||||||
|
LL | i = shadowed_closure();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: closure called just once immediately after it was declared
|
||||||
|
--> $DIR/redundant_closure_call_late.rs:21:5
|
||||||
|
|
|
||||||
|
LL | i = shadowed_closure();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let result: Result<usize, usize> = Err(5);
|
||||||
|
if result.is_ok() {}
|
||||||
|
|
||||||
if Ok::<i32, i32>(42).is_ok() {}
|
if Ok::<i32, i32>(42).is_ok() {}
|
||||||
|
|
||||||
if Err::<i32, i32>(42).is_err() {}
|
if Err::<i32, i32>(42).is_err() {}
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let result: Result<usize, usize> = Err(5);
|
||||||
|
if let Ok(_) = &result {}
|
||||||
|
|
||||||
if let Ok(_) = Ok::<i32, i32>(42) {}
|
if let Ok(_) = Ok::<i32, i32>(42) {}
|
||||||
|
|
||||||
if let Err(_) = Err::<i32, i32>(42) {}
|
if let Err(_) = Err::<i32, i32>(42) {}
|
||||||
|
|
|
@ -1,73 +1,79 @@
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:14:12
|
--> $DIR/redundant_pattern_matching.rs:15:12
|
||||||
|
|
|
|
||||||
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
|
LL | if let Ok(_) = &result {}
|
||||||
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
|
| -------^^^^^---------- help: try this: `if result.is_ok()`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
|
--> $DIR/redundant_pattern_matching.rs:17:12
|
||||||
|
|
|
||||||
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
|
||||||
|
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_err()`
|
error: redundant pattern matching, consider using `is_err()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:16:12
|
--> $DIR/redundant_pattern_matching.rs:19:12
|
||||||
|
|
|
|
||||||
LL | if let Err(_) = Err::<i32, i32>(42) {}
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
|
||||||
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
|
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:18:12
|
--> $DIR/redundant_pattern_matching.rs:21:12
|
||||||
|
|
|
|
||||||
LL | if let None = None::<()> {}
|
LL | if let None = None::<()> {}
|
||||||
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
|
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:20:12
|
--> $DIR/redundant_pattern_matching.rs:23:12
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = Some(42) {}
|
LL | if let Some(_) = Some(42) {}
|
||||||
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:22:12
|
--> $DIR/redundant_pattern_matching.rs:25:12
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = Some(42) {
|
LL | if let Some(_) = Some(42) {
|
||||||
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:28:15
|
--> $DIR/redundant_pattern_matching.rs:31:15
|
||||||
|
|
|
|
||||||
LL | while let Some(_) = Some(42) {}
|
LL | while let Some(_) = Some(42) {}
|
||||||
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
|
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:30:15
|
--> $DIR/redundant_pattern_matching.rs:33:15
|
||||||
|
|
|
|
||||||
LL | while let None = Some(42) {}
|
LL | while let None = Some(42) {}
|
||||||
| ----------^^^^----------- help: try this: `while Some(42).is_none()`
|
| ----------^^^^----------- help: try this: `while Some(42).is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:32:15
|
--> $DIR/redundant_pattern_matching.rs:35:15
|
||||||
|
|
|
|
||||||
LL | while let None = None::<()> {}
|
LL | while let None = None::<()> {}
|
||||||
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
|
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:34:15
|
--> $DIR/redundant_pattern_matching.rs:37:15
|
||||||
|
|
|
|
||||||
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
|
||||||
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
|
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_err()`
|
error: redundant pattern matching, consider using `is_err()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:36:15
|
--> $DIR/redundant_pattern_matching.rs:39:15
|
||||||
|
|
|
|
||||||
LL | while let Err(_) = Ok::<i32, i32>(10) {}
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
|
||||||
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
|
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:39:15
|
--> $DIR/redundant_pattern_matching.rs:42:15
|
||||||
|
|
|
|
||||||
LL | while let Some(_) = v.pop() {
|
LL | while let Some(_) = v.pop() {
|
||||||
| ----------^^^^^^^---------- help: try this: `while v.pop().is_some()`
|
| ----------^^^^^^^---------- help: try this: `while v.pop().is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:55:5
|
--> $DIR/redundant_pattern_matching.rs:58:5
|
||||||
|
|
|
|
||||||
LL | / match Ok::<i32, i32>(42) {
|
LL | / match Ok::<i32, i32>(42) {
|
||||||
LL | | Ok(_) => true,
|
LL | | Ok(_) => true,
|
||||||
|
@ -76,7 +82,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
|
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_err()`
|
error: redundant pattern matching, consider using `is_err()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:60:5
|
--> $DIR/redundant_pattern_matching.rs:63:5
|
||||||
|
|
|
|
||||||
LL | / match Ok::<i32, i32>(42) {
|
LL | / match Ok::<i32, i32>(42) {
|
||||||
LL | | Ok(_) => false,
|
LL | | Ok(_) => false,
|
||||||
|
@ -85,7 +91,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
|
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_err()`
|
error: redundant pattern matching, consider using `is_err()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:65:5
|
--> $DIR/redundant_pattern_matching.rs:68:5
|
||||||
|
|
|
|
||||||
LL | / match Err::<i32, i32>(42) {
|
LL | / match Err::<i32, i32>(42) {
|
||||||
LL | | Ok(_) => false,
|
LL | | Ok(_) => false,
|
||||||
|
@ -94,7 +100,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
|
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:70:5
|
--> $DIR/redundant_pattern_matching.rs:73:5
|
||||||
|
|
|
|
||||||
LL | / match Err::<i32, i32>(42) {
|
LL | / match Err::<i32, i32>(42) {
|
||||||
LL | | Ok(_) => true,
|
LL | | Ok(_) => true,
|
||||||
|
@ -103,7 +109,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
|
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:75:5
|
--> $DIR/redundant_pattern_matching.rs:78:5
|
||||||
|
|
|
|
||||||
LL | / match Some(42) {
|
LL | / match Some(42) {
|
||||||
LL | | Some(_) => true,
|
LL | | Some(_) => true,
|
||||||
|
@ -112,7 +118,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Some(42).is_some()`
|
| |_____^ help: try this: `Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:80:5
|
--> $DIR/redundant_pattern_matching.rs:83:5
|
||||||
|
|
|
|
||||||
LL | / match None::<()> {
|
LL | / match None::<()> {
|
||||||
LL | | Some(_) => false,
|
LL | | Some(_) => false,
|
||||||
|
@ -121,7 +127,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `None::<()>.is_none()`
|
| |_____^ help: try this: `None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:85:13
|
--> $DIR/redundant_pattern_matching.rs:88:13
|
||||||
|
|
|
|
||||||
LL | let _ = match None::<()> {
|
LL | let _ = match None::<()> {
|
||||||
| _____________^
|
| _____________^
|
||||||
|
@ -131,64 +137,64 @@ LL | | };
|
||||||
| |_____^ help: try this: `None::<()>.is_none()`
|
| |_____^ help: try this: `None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:90:20
|
--> $DIR/redundant_pattern_matching.rs:93:20
|
||||||
|
|
|
|
||||||
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
|
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
|
||||||
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
|
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:93:20
|
--> $DIR/redundant_pattern_matching.rs:96:20
|
||||||
|
|
|
|
||||||
LL | let x = if let Some(_) = opt { true } else { false };
|
LL | let x = if let Some(_) = opt { true } else { false };
|
||||||
| -------^^^^^^^------ help: try this: `if opt.is_some()`
|
| -------^^^^^^^------ help: try this: `if opt.is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:99:20
|
--> $DIR/redundant_pattern_matching.rs:102:20
|
||||||
|
|
|
|
||||||
LL | let _ = if let Some(_) = gen_opt() {
|
LL | let _ = if let Some(_) = gen_opt() {
|
||||||
| -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
|
| -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:101:19
|
--> $DIR/redundant_pattern_matching.rs:104:19
|
||||||
|
|
|
|
||||||
LL | } else if let None = gen_opt() {
|
LL | } else if let None = gen_opt() {
|
||||||
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
|
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_ok()`
|
error: redundant pattern matching, consider using `is_ok()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:103:19
|
--> $DIR/redundant_pattern_matching.rs:106:19
|
||||||
|
|
|
|
||||||
LL | } else if let Ok(_) = gen_res() {
|
LL | } else if let Ok(_) = gen_res() {
|
||||||
| -------^^^^^------------ help: try this: `if gen_res().is_ok()`
|
| -------^^^^^------------ help: try this: `if gen_res().is_ok()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_err()`
|
error: redundant pattern matching, consider using `is_err()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:105:19
|
--> $DIR/redundant_pattern_matching.rs:108:19
|
||||||
|
|
|
|
||||||
LL | } else if let Err(_) = gen_res() {
|
LL | } else if let Err(_) = gen_res() {
|
||||||
| -------^^^^^^------------ help: try this: `if gen_res().is_err()`
|
| -------^^^^^^------------ help: try this: `if gen_res().is_err()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:138:19
|
--> $DIR/redundant_pattern_matching.rs:141:19
|
||||||
|
|
|
|
||||||
LL | while let Some(_) = r#try!(result_opt()) {}
|
LL | while let Some(_) = r#try!(result_opt()) {}
|
||||||
| ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()`
|
| ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:139:16
|
--> $DIR/redundant_pattern_matching.rs:142:16
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = r#try!(result_opt()) {}
|
LL | if let Some(_) = r#try!(result_opt()) {}
|
||||||
| -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
|
| -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:145:12
|
--> $DIR/redundant_pattern_matching.rs:148:12
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = m!() {}
|
LL | if let Some(_) = m!() {}
|
||||||
| -------^^^^^^^------- help: try this: `if m!().is_some()`
|
| -------^^^^^^^------- help: try this: `if m!().is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching.rs:146:15
|
--> $DIR/redundant_pattern_matching.rs:149:15
|
||||||
|
|
|
|
||||||
LL | while let Some(_) = m!() {}
|
LL | while let Some(_) = m!() {}
|
||||||
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
|
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
|
||||||
|
|
||||||
error: aborting due to 28 previous errors
|
error: aborting due to 29 previous errors
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ note: previous binding is here
|
||||||
LL | let x = (1, x);
|
LL | let x = (1, x);
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: `x` is shadowed by `y`
|
error: `x` is being shadowed
|
||||||
--> $DIR/shadow.rs:34:9
|
--> $DIR/shadow.rs:34:9
|
||||||
|
|
|
|
||||||
LL | let x = y;
|
LL | let x = y;
|
||||||
|
|
36
src/tools/clippy/tests/ui/unit_return_expecting_ord.rs
Normal file
36
src/tools/clippy/tests/ui/unit_return_expecting_ord.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#![warn(clippy::unit_return_expecting_ord)]
|
||||||
|
#![allow(clippy::needless_return)]
|
||||||
|
#![allow(clippy::unused_unit)]
|
||||||
|
#![feature(is_sorted)]
|
||||||
|
|
||||||
|
struct Struct {
|
||||||
|
field: isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn double(i: isize) -> isize {
|
||||||
|
i * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unit(_i: isize) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }];
|
||||||
|
structs.sort_by_key(|s| {
|
||||||
|
double(s.field);
|
||||||
|
});
|
||||||
|
structs.sort_by_key(|s| double(s.field));
|
||||||
|
structs.is_sorted_by_key(|s| {
|
||||||
|
double(s.field);
|
||||||
|
});
|
||||||
|
structs.is_sorted_by_key(|s| {
|
||||||
|
if s.field > 0 {
|
||||||
|
()
|
||||||
|
} else {
|
||||||
|
return ();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
structs.sort_by_key(|s| {
|
||||||
|
return double(s.field);
|
||||||
|
});
|
||||||
|
structs.sort_by_key(|s| unit(s.field));
|
||||||
|
}
|
39
src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
Normal file
39
src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
error: this closure returns the unit type which also implements Ord
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:18:25
|
||||||
|
|
|
||||||
|
LL | structs.sort_by_key(|s| {
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
|
||||||
|
help: probably caused by this trailing semicolon
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:19:24
|
||||||
|
|
|
||||||
|
LL | double(s.field);
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: this closure returns the unit type which also implements PartialOrd
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:22:30
|
||||||
|
|
|
||||||
|
LL | structs.is_sorted_by_key(|s| {
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: probably caused by this trailing semicolon
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:23:24
|
||||||
|
|
|
||||||
|
LL | double(s.field);
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: this closure returns the unit type which also implements PartialOrd
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:25:30
|
||||||
|
|
|
||||||
|
LL | structs.is_sorted_by_key(|s| {
|
||||||
|
| ^^^
|
||||||
|
|
||||||
|
error: this closure returns the unit type which also implements Ord
|
||||||
|
--> $DIR/unit_return_expecting_ord.rs:35:25
|
||||||
|
|
|
||||||
|
LL | structs.sort_by_key(|s| unit(s.field));
|
||||||
|
| ^^^
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
|
@ -32,11 +32,20 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_issue_5833() -> Result<(), ()> {
|
||||||
|
let text = "foo\r\nbar\n\nbaz\n";
|
||||||
|
let lines = text.lines();
|
||||||
|
if Some("ok") == lines.into_iter().next() {}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
test_generic(10i32);
|
test_generic(10i32);
|
||||||
test_generic2::<i32, i32>(10i32);
|
test_generic2::<i32, i32>(10i32);
|
||||||
test_questionmark().unwrap();
|
test_questionmark().unwrap();
|
||||||
test_issue_3913().unwrap();
|
test_issue_3913().unwrap();
|
||||||
|
test_issue_5833().unwrap();
|
||||||
|
|
||||||
let _: String = "foo".into();
|
let _: String = "foo".into();
|
||||||
let _: String = From::from("foo");
|
let _: String = From::from("foo");
|
||||||
|
|
|
@ -32,11 +32,20 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_issue_5833() -> Result<(), ()> {
|
||||||
|
let text = "foo\r\nbar\n\nbaz\n";
|
||||||
|
let lines = text.lines();
|
||||||
|
if Some("ok") == lines.into_iter().next() {}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
test_generic(10i32);
|
test_generic(10i32);
|
||||||
test_generic2::<i32, i32>(10i32);
|
test_generic2::<i32, i32>(10i32);
|
||||||
test_questionmark().unwrap();
|
test_questionmark().unwrap();
|
||||||
test_issue_3913().unwrap();
|
test_issue_3913().unwrap();
|
||||||
|
test_issue_5833().unwrap();
|
||||||
|
|
||||||
let _: String = "foo".into();
|
let _: String = "foo".into();
|
||||||
let _: String = From::from("foo");
|
let _: String = From::from("foo");
|
||||||
|
|
|
@ -23,43 +23,43 @@ LL | let _: i32 = 0i32.into();
|
||||||
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
|
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:51:21
|
--> $DIR/useless_conversion.rs:60:21
|
||||||
|
|
|
|
||||||
LL | let _: String = "foo".to_string().into();
|
LL | let _: String = "foo".to_string().into();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:52:21
|
--> $DIR/useless_conversion.rs:61:21
|
||||||
|
|
|
|
||||||
LL | let _: String = From::from("foo".to_string());
|
LL | let _: String = From::from("foo".to_string());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:53:13
|
--> $DIR/useless_conversion.rs:62:13
|
||||||
|
|
|
|
||||||
LL | let _ = String::from("foo".to_string());
|
LL | let _ = String::from("foo".to_string());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:54:13
|
--> $DIR/useless_conversion.rs:63:13
|
||||||
|
|
|
|
||||||
LL | let _ = String::from(format!("A: {:04}", 123));
|
LL | let _ = String::from(format!("A: {:04}", 123));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:55:13
|
--> $DIR/useless_conversion.rs:64:13
|
||||||
|
|
|
|
||||||
LL | let _ = "".lines().into_iter();
|
LL | let _ = "".lines().into_iter();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:56:13
|
--> $DIR/useless_conversion.rs:65:13
|
||||||
|
|
|
|
||||||
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
|
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
|
||||||
|
|
||||||
error: useless conversion to the same type
|
error: useless conversion to the same type
|
||||||
--> $DIR/useless_conversion.rs:57:21
|
--> $DIR/useless_conversion.rs:66:21
|
||||||
|
|
|
|
||||||
LL | let _: String = format!("Hello {}", "world").into();
|
LL | let _: String = format!("Hello {}", "world").into();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
||||||
// not applicable
|
// not applicable
|
||||||
vec![1, 2, 3, 4, 5].resize(2, 5);
|
vec![1, 2, 3, 4, 5].resize(2, 5);
|
||||||
|
|
||||||
// applicable here, but only implemented for integer litterals for now
|
// applicable here, but only implemented for integer literals for now
|
||||||
vec!["foo", "bar", "baz"].resize(0, "bar");
|
vec!["foo", "bar", "baz"].resize(0, "bar");
|
||||||
|
|
||||||
// not applicable
|
// not applicable
|
||||||
|
|
Loading…
Add table
Reference in a new issue