Commit 6c8927b0 authored by bors's avatar bors

Auto merge of #74792 - flip1995:clippyup, r=Manishearth

Update Clippy

Biweekly Clippy Sync

r? @Manishearth
parents 62392966 e4e1b8c6
......@@ -19,7 +19,7 @@ fi
if [[ $BETA = "true" ]]; then
echo "Update documentation for the beta release"
cp -r out/master out/beta
cp -r out/master/* out/beta
fi
# Generate version index that is shown as root index page
......@@ -33,12 +33,13 @@ cd out
git config user.name "GHA CI"
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
# track files, so that the following check works
git add --intent-to-add "$TAG_NAME"
if git diff --exit-code --quiet -- $TAG_NAME/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
# Add the new dir
git add "$TAG_NAME"
# Update the symlink
......@@ -47,9 +48,17 @@ if [[ -n $TAG_NAME ]]; then
git add versions.json
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
elif [[ $BETA = "true" ]]; then
if git diff --exit-code --quiet -- beta/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add beta
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
else
if git diff --exit-code --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add .
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
fi
......
# Change Log
# Changelog
All notable changes to this project will be documented in this file.
See [Changelog Update](doc/changelog_update.md) if you want to update this
......@@ -6,11 +6,73 @@ document.
## Unreleased / In Rust Nightly
[7ea7cd1...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
[c2c07fa...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
## Rust 1.46
Current beta, release 2020-08-27
[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
### New lints
* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378)
* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597)
* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623)
* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637)
### Moves and Deprecations
* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667)
### Enhancements
* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695)
### False Positive Fixes
* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled
[#5656](https://github.com/rust-lang/rust-clippy/pull/5656)
* [`let_and_return`]: Don't lint if a temporary borrow is involved
[#5680](https://github.com/rust-lang/rust-clippy/pull/5680)
* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
* [`if_same_then_else`]: Don't assume multiplication is always commutative
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
* [`blacklisted_name`]: Remove `bar` from the default configuration
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
### Suggestion Fixes/Improvements
* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code
[#4455](https://github.com/rust-lang/rust-clippy/pull/4455)
* Add auto applicable suggestion to [`macro_use_imports`]
[#5279](https://github.com/rust-lang/rust-clippy/pull/5279)
### ICE Fixes
* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709)
### Documentation Improvements
* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664)
### Others
* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver`
into `rustc` and passes all the given arguments to `rustc`. This is especially
useful for tools that need the `rustc` version Clippy was compiled with,
instead of the Clippy version. E.g. `clippy-driver --rustc --version` will
print the output of `rustc --version`.
[#5178](https://github.com/rust-lang/rust-clippy/pull/5178)
* New issue templates now make it easier to complain if Clippy is too annoying
or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735)
## Rust 1.45
Current beta, release 2020-07-16
Current stable, released 2020-07-16
[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)
......@@ -87,7 +149,7 @@ and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/565
## Rust 1.44
Current stable, released 2020-06-04
Released 2020-06-04
[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)
......@@ -1679,6 +1741,7 @@ Released 2018-09-13
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
......
......@@ -42,10 +42,8 @@ Table of contents:
## Usage
Since this is a tool for helping the developer of a library or application
write better code, it is recommended not to include Clippy as a hard dependency.
Options include using it as an optional dependency, as a cargo subcommand, or
as an included feature during build. These options are detailed below.
Below are instructions on how to use Clippy as a subcommand, compiled from source
or in Travis CI.
### As a cargo subcommand (`cargo clippy`)
......
......@@ -153,7 +153,7 @@ declare_deprecated_lint! {
///
/// **Deprecation reason:** Associated-constants are now preferred.
pub REPLACE_CONSTS,
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants"
}
declare_deprecated_lint! {
......
......@@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls.
///
/// **Why is this bad?** Derefencing by `&*x` or `&mut *x` is clearer and more concise,
/// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise,
/// when not part of a method chain.
///
/// **Example:**
......
......@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
..
} = item.kind
{
// Remember for each inherent implementation encoutered its span and generics
// Remember for each inherent implementation encountered its span and generics
// but filter out implementations that have generic params (type or lifetime)
// or are derived from a macro
if !in_macro(item.span) && generics.params.is_empty() {
......
......@@ -276,6 +276,7 @@ mod ptr_offset_with_cast;
mod question_mark;
mod ranges;
mod redundant_clone;
mod redundant_closure_call;
mod redundant_field_names;
mod redundant_pub_crate;
mod redundant_static_lifetimes;
......@@ -300,6 +301,7 @@ mod trivially_copy_pass_by_ref;
mod try_err;
mod types;
mod unicode;
mod unit_return_expecting_ord;
mod unnamed_address;
mod unnecessary_sort_by;
mod unnested_or_patterns;
......@@ -462,7 +464,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
);
store.register_removed(
"clippy::replace_consts",
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants",
);
store.register_removed(
"clippy::regex_macro",
......@@ -701,7 +703,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&misc_early::DOUBLE_NEG,
&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
&misc_early::MIXED_CASE_HEX_LITERALS,
&misc_early::REDUNDANT_CLOSURE_CALL,
&misc_early::REDUNDANT_PATTERN,
&misc_early::UNNEEDED_FIELD_PATTERN,
&misc_early::UNNEEDED_WILDCARD_PATTERN,
......@@ -758,6 +759,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&ranges::RANGE_ZIP_WITH_LEN,
&ranges::REVERSED_EMPTY_RANGES,
&redundant_clone::REDUNDANT_CLONE,
&redundant_closure_call::REDUNDANT_CLOSURE_CALL,
&redundant_field_names::REDUNDANT_FIELD_NAMES,
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
......@@ -826,6 +828,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&unicode::NON_ASCII_LITERAL,
&unicode::UNICODE_NOT_NFC,
&unicode::ZERO_WIDTH_SPACE,
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
&unnamed_address::FN_ADDRESS_COMPARISONS,
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
......@@ -891,6 +894,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box attrs::Attributes);
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
store.register_late_pass(|| box unicode::Unicode);
store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd);
store.register_late_pass(|| box strings::StringAdd);
store.register_late_pass(|| box implicit_return::ImplicitReturn);
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
......@@ -1015,6 +1019,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_early_pass(|| box int_plus_one::IntPlusOne);
store.register_early_pass(|| box formatting::Formatting);
store.register_early_pass(|| box misc_early::MiscEarlyLints);
store.register_early_pass(|| box redundant_closure_call::RedundantClosureCall);
store.register_late_pass(|| box redundant_closure_call::RedundantClosureCall);
store.register_early_pass(|| box returns::Return);
store.register_late_pass(|| box let_and_return::LetReturn);
store.register_early_pass(|| box collapsible_if::CollapsibleIf);
......@@ -1356,7 +1362,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&misc_early::DOUBLE_NEG),
LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT),
LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS),
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
LintId::of(&misc_early::REDUNDANT_PATTERN),
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
......@@ -1390,6 +1395,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
LintId::of(&redundant_clone::REDUNDANT_CLONE),
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
LintId::of(&reference::DEREF_ADDROF),
......@@ -1436,6 +1442,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::UNNECESSARY_CAST),
LintId::of(&types::VEC_BOX),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
......@@ -1589,7 +1596,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::UNNECESSARY_FILTER_MAP),
LintId::of(&methods::USELESS_ASREF),
LintId::of(&misc::SHORT_CIRCUIT_STATEMENT),
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
LintId::of(&needless_bool::BOOL_COMPARISON),
......@@ -1604,6 +1610,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&precedence::PRECEDENCE),
LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST),
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
LintId::of(&reference::DEREF_ADDROF),
LintId::of(&reference::REF_IN_DEREF),
LintId::of(&repeat_once::REPEAT_ONCE),
......@@ -1692,6 +1699,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::CAST_REF_TO_MUT),
LintId::of(&types::UNIT_CMP),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
......
......@@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
}
}
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then(
cx,
REDUNDANT_PATTERN_MATCHING,
......@@ -1524,7 +1528,7 @@ mod redundant_pattern_match {
// while let ... = ... { ... }
// ^^^
let op_span = op.span.source_callsite();
let op_span = result_expr.span.source_callsite();
// while let ... = ... { ... }
// ^^^^^^^^^^^^^^^^^^^
......@@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
};
if let Some(good_method) = found_good_method {
let span = expr.span.to(op.span);
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then(
cx,
REDUNDANT_PATTERN_MATCHING,
expr.span,
&format!("redundant pattern matching, consider using `{}`", good_method),
|diag| {
let span = expr.span.to(op.span);
diag.span_suggestion(
span,
"try this",
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
Applicability::MaybeIncorrect, // snippet
);
},
......
......@@ -2354,8 +2354,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
cx,
ITER_NTH_ZERO,
expr.span,
"called `.nth(0)` on a `std::iter::Iterator`",
"try calling",
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
"try calling `.next()` instead of `.nth(0)`",
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
applicability,
);
......@@ -3290,7 +3290,12 @@ fn lint_option_as_ref_deref<'tcx>(
if let hir::ExprKind::Path(qpath) = &args[0].kind;
if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
if closure_body.params[0].pat.hir_id == local_id;
let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
let adj = cx
.typeck_results()
.expr_adjustments(&args[0])
.iter()
.map(|x| &x.kind)
.collect::<Box<[_]>>();
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
......
......@@ -99,7 +99,9 @@ declare_clippy_lint! {
/// if y != x {} // where both are floats
///
/// // Good
/// let error = 0.01f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (y - 1.23f64).abs() < error { }
/// if (y - x).abs() > error { }
/// ```
......@@ -237,10 +239,12 @@ declare_clippy_lint! {
/// const ONE: f64 = 1.00;
///
/// // Bad
/// if x == ONE { } // where both are floats
/// if x == ONE { } // where both are floats
///
/// // Good
/// let error = 0.1f64; // Use an epsilon for comparison
/// let error = f64::EPSILON; // Use an epsilon for comparison
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
/// // let error = std::f64::EPSILON;
/// if (x - ONE).abs() < error { }
/// ```
pub FLOAT_CMP_CONST,
......
use crate::utils::{
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 crate::utils::{constants, snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
use rustc_ast::ast::{
BindingMode, Block, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
NodeId, Pat, PatKind, StmtKind, UnOp,
BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
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_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
......@@ -70,28 +66,6 @@ declare_clippy_lint! {
"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! {
/// **What it does:** Detects expressions of the form `--x`.
///
......@@ -278,7 +252,6 @@ declare_clippy_lint! {
declare_lint_pass!(MiscEarlyLints => [
UNNEEDED_FIELD_PATTERN,
DUPLICATE_UNDERSCORE_ARGUMENT,
REDUNDANT_CLOSURE_CALL,
DOUBLE_NEG,
MIXED_CASE_HEX_LITERALS,
UNSEPARATED_LITERAL_SUFFIX,
......@@ -288,30 +261,6 @@ declare_lint_pass!(MiscEarlyLints => [
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 {
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
for param in &gen.params {
......@@ -453,30 +402,6 @@ impl EarlyLintPass for MiscEarlyLints {
return;
}
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) => {
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
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 {
......
......@@ -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
/// can't be made const then, because `drop` can't be const-evaluated.
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| {
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
has_drop(cx, ty_ty)
......
......@@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::fmt::Display;
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
/// 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;
match existing_name.len.cmp(&count) {
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;
}
},
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;
}
},
......
......@@ -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.
struct OptionIfLetElseOccurence {
option: String,
......
......@@ -96,23 +96,20 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
if_chain! {
if let ExprKind::Block(ref block, _) = expr.kind;
if let Some(ref ex) = block.expr;
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC);
if params.len() == 1;
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC)
.or_else(|| match_function_call(cx, ex, &paths::BEGIN_PANIC_FMT));
then {
let span = get_outer_span(expr);
if is_expn_of(expr.span, "unimplemented").is_some() {
let span = get_outer_span(expr);
span_lint(cx, UNIMPLEMENTED, span,
"`unimplemented` should not be present in production code");
} else if is_expn_of(expr.span, "todo").is_some() {
let span = get_outer_span(expr);
span_lint(cx, TODO, span,
"`todo` should not be present in production code");
} else if is_expn_of(expr.span, "unreachable").is_some() {
let span = get_outer_span(expr);
span_lint(cx, UNREACHABLE, span,
"`unreachable` should not be present in production code");
} else if is_expn_of(expr.span, "panic").is_some() {
let span = get_outer_span(expr);
span_lint(cx, PANIC, span,