Merge commit '7901289135' into clippy-subtree-update

This commit is contained in:
Philipp Krones 2024-09-24 11:58:04 +02:00
parent 249210e8d8
commit b61fcbee76
566 changed files with 7442 additions and 2576 deletions

View file

@ -1,4 +1,4 @@
use super::{contains_return, BIND_INSTEAD_OF_MAP};
use super::{BIND_INSTEAD_OF_MAP, contains_return};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::peel_blocks;
use clippy_utils::source::{snippet, snippet_with_context};

View file

@ -1,12 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::{indent_of, reindent_multiline, SpanRangeExt};
use clippy_utils::source::{SpanRangeExt, indent_of, reindent_multiline};
use clippy_utils::ty::is_type_lang_item;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem};
use rustc_lint::LateContext;
use rustc_span::source_map::Spanned;
use rustc_span::Span;
use rustc_span::source_map::Spanned;
use super::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS;

View file

@ -4,8 +4,8 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem, QPath};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::CLEAR_WITH_DRAIN;

View file

@ -7,7 +7,7 @@ use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_middle::ty::{self};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{Symbol, sym};
use super::CLONE_ON_COPY;

View file

@ -4,7 +4,7 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{Symbol, sym};
use super::CLONE_ON_REF_PTR;

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::CLONED_INSTEAD_OF_COPIED;

View file

@ -8,7 +8,7 @@ use rustc_hir as hir;
use rustc_lint::LateContext;
use std::collections::VecDeque;
use super::{method_call, COLLAPSIBLE_STR_REPLACE};
use super::{COLLAPSIBLE_STR_REPLACE, method_call};
pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,

View file

@ -8,7 +8,7 @@ use rustc_hir::{Expr, ExprKind, LangItem, Path, QPath};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_middle::ty::Ty;
use rustc_span::{sym, Symbol};
use rustc_span::{Symbol, sym};
/// Checks if both types match the given diagnostic item, e.g.:
///

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_middle::ty::Ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
pub(super) fn check(
cx: &LateContext<'_>,

View file

@ -1,13 +1,13 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::macros::{format_args_inputs_span, root_macro_call_first_node, FormatArgsStorage};
use clippy_utils::macros::{FormatArgsStorage, format_args_inputs_span, root_macro_call_first_node};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use std::borrow::Cow;
use super::EXPECT_FUN_CALL;

View file

@ -3,7 +3,7 @@ use clippy_utils::get_parent_expr;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::FILETYPE_IS_FILE;

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::macros::{is_panic, matching_root_macro_call, root_macro_call};
use clippy_utils::source::{indent_of, reindent_multiline, snippet};
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{higher, is_trait_method, path_to_local_id, peel_blocks, SpanlessEq};
use clippy_utils::{SpanlessEq, higher, is_trait_method, path_to_local_id, peel_blocks};
use hir::{Body, HirId, MatchSource, Pat};
use rustc_errors::Applicability;
use rustc_hir as hir;
@ -10,8 +10,8 @@ use rustc_hir::def::Res;
use rustc_hir::{Closure, Expr, ExprKind, PatKind, PathSegment, QPath, UnOp};
use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::Adjust;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;
use rustc_span::symbol::{Ident, Symbol, sym};
use std::borrow::Cow;
use super::{MANUAL_FILTER_MAP, MANUAL_FIND_MAP, OPTION_FILTER_MAP, RESULT_FILTER_MAP};

View file

@ -7,9 +7,9 @@ use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::Binder;
use rustc_span::{sym, Span};
use rustc_middle::ty::adjustment::Adjust;
use rustc_span::{Span, sym};
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) {
if !in_external_macro(cx.sess(), expr.span)

View file

@ -3,7 +3,7 @@ use clippy_utils::{is_expr_identity_function, is_expr_untyped_identity_function,
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::FILTER_MAP_IDENTITY;

View file

@ -3,7 +3,7 @@ use clippy_utils::{is_expr_untyped_identity_function, is_trait_method};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::FLAT_MAP_IDENTITY;

View file

@ -4,7 +4,7 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::FLAT_MAP_OPTION;
use clippy_utils::ty::is_type_diagnostic_item;

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{is_integer_literal, SpanlessEq};
use clippy_utils::{SpanlessEq, is_integer_literal};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::LateContext;

View file

@ -5,7 +5,7 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{Symbol, sym};
use super::INEFFICIENT_TO_STRING;

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_trait_method;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::INSPECT_FOR_EACH;

View file

@ -5,8 +5,8 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
use rustc_span::symbol::{Symbol, sym};
use super::INTO_ITER_ON_REF;

View file

@ -10,8 +10,8 @@ use clippy_utils::{get_parent_expr, is_trait_method, peel_blocks, span_contains_
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::QPath;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;
use rustc_span::symbol::{Ident, Symbol, sym};
use std::borrow::Cow;
///

View file

@ -14,7 +14,6 @@ use rustc_span::sym;
/// - `hashmap.into_iter().map(|(_, v)| v)`
///
/// on `HashMaps` and `BTreeMaps` in std
pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,
map_type: &'tcx str, // iter / into_iter

View file

@ -3,8 +3,8 @@ use clippy_utils::ty::get_type_diagnostic_name;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::ITER_NTH;

View file

@ -5,9 +5,9 @@ use clippy_utils::source::snippet;
use clippy_utils::{get_expr_use_or_unification_node, is_res_lang_ctor, path_res, std_or_core};
use rustc_errors::Applicability;
use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::def_id::DefId;
use rustc_hir::hir_id::HirId;
use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::{Expr, ExprKind, Node};
use rustc_lint::LateContext;

View file

@ -3,8 +3,8 @@ use clippy_utils::is_range_full;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::ITER_WITH_DRAIN;

View file

@ -6,8 +6,8 @@ use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::JOIN_ABSOLUTE_PATHS;

View file

@ -6,7 +6,7 @@ use rustc_ast::{LitKind, StrStyle};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Node, QPath, TyKind};
use rustc_lint::LateContext;
use rustc_span::{sym, Span, Symbol};
use rustc_span::{Span, Symbol, sym};
use super::MANUAL_C_STR_LITERALS;

View file

@ -3,13 +3,13 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::{IntoSpan, SpanRangeExt};
use clippy_utils::ty::get_field_by_name;
use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures};
use clippy_utils::{expr_use_ctxt, is_diag_item_method, is_diag_trait_item, path_to_local_id, ExprUseNode};
use clippy_utils::{ExprUseNode, expr_use_ctxt, is_diag_item_method, is_diag_trait_item, path_to_local_id};
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir::{BindingMode, BorrowKind, ByRef, ClosureKind, Expr, ExprKind, Mutability, Node, PatKind};
use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
use super::MANUAL_INSPECT;

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_errors::Applicability;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::MANUAL_IS_VARIANT_AND;

View file

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{indent_of, reindent_multiline, SpanRangeExt};
use clippy_utils::source::{SpanRangeExt, indent_of, reindent_multiline};
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{is_res_lang_ctor, path_res, path_to_local_id};
use rustc_errors::Applicability;

View file

@ -8,7 +8,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::MANUAL_TRY_FOLD;

View file

@ -11,7 +11,7 @@ use rustc_middle::mir::Mutability;
use rustc_middle::ty;
use rustc_middle::ty::adjustment::Adjust;
use rustc_span::symbol::Ident;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::MAP_CLONE;

View file

@ -6,8 +6,8 @@ use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::MAP_FLATTEN;

View file

@ -4,7 +4,7 @@ use clippy_utils::{is_expr_untyped_identity_function, is_trait_method};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::MAP_IDENTITY;

View file

@ -111,6 +111,7 @@ mod uninit_assumed_init;
mod unit_hash;
mod unnecessary_fallible_conversions;
mod unnecessary_filter_map;
mod unnecessary_first_then_check;
mod unnecessary_fold;
mod unnecessary_get_then_check;
mod unnecessary_iter_cloned;
@ -131,8 +132,8 @@ mod waker_clone_wake;
mod wrong_self_convention;
mod zst_offset;
use clippy_config::msrvs::{self, Msrv};
use clippy_config::Conf;
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::consts::{ConstEvalCtxt, Constant};
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
use clippy_utils::macros::FormatArgsStorage;
@ -146,7 +147,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, TraitRef, Ty};
use rustc_session::impl_lint_pass;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
declare_clippy_lint! {
/// ### What it does
@ -441,6 +442,17 @@ declare_clippy_lint! {
/// }
/// }
/// ```
///
/// Use instead:
/// ```no_run
/// # struct X;
/// impl X {
/// fn as_str(&self) -> &'static str {
/// // ..
/// # ""
/// }
/// }
/// ```
#[clippy::version = "pre 1.29.0"]
pub WRONG_SELF_CONVENTION,
style,
@ -3964,7 +3976,7 @@ declare_clippy_lint! {
/// ```no_run
/// let _ = 0;
/// ```
#[clippy::version = "1.78.0"]
#[clippy::version = "1.81.0"]
pub UNNECESSARY_MIN_OR_MAX,
complexity,
"using 'min()/max()' when there is no need for it"
@ -4025,7 +4037,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.78.0"]
pub MANUAL_C_STR_LITERALS,
pedantic,
complexity,
r#"creating a `CStr` through functions when `c""` literals can be used"#
}
@ -4099,7 +4111,7 @@ declare_clippy_lint! {
/// ```no_run
/// "foo".is_ascii();
/// ```
#[clippy::version = "1.80.0"]
#[clippy::version = "1.81.0"]
pub NEEDLESS_CHARACTER_ITERATION,
suspicious,
"is_ascii() called on a char iterator"
@ -4126,6 +4138,34 @@ declare_clippy_lint! {
"use of `map` returning the original item"
}
declare_clippy_lint! {
/// ### What it does
/// Checks the usage of `.first().is_some()` or `.first().is_none()` to check if a slice is
/// empty.
///
/// ### Why is this bad?
/// Using `.is_empty()` is shorter and better communicates the intention.
///
/// ### Example
/// ```no_run
/// let v = vec![1, 2, 3];
/// if v.first().is_none() {
/// // The vector is empty...
/// }
/// ```
/// Use instead:
/// ```no_run
/// let v = vec![1, 2, 3];
/// if v.is_empty() {
/// // The vector is empty...
/// }
/// ```
#[clippy::version = "1.83.0"]
pub UNNECESSARY_FIRST_THEN_CHECK,
complexity,
"calling `.first().is_some()` or `.first().is_none()` instead of `.is_empty()`"
}
pub struct Methods {
avoid_breaking_exported_api: bool,
msrv: Msrv,
@ -4283,6 +4323,7 @@ impl_lint_pass!(Methods => [
UNNECESSARY_RESULT_MAP_OR_ELSE,
MANUAL_C_STR_LITERALS,
UNNECESSARY_GET_THEN_CHECK,
UNNECESSARY_FIRST_THEN_CHECK,
NEEDLESS_CHARACTER_ITERATION,
MANUAL_INSPECT,
UNNECESSARY_MIN_OR_MAX,
@ -5055,6 +5096,9 @@ fn check_is_some_is_none(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>,
Some(("get", f_recv, [arg], _, _)) => {
unnecessary_get_then_check::check(cx, call_span, recv, f_recv, arg, is_some);
},
Some(("first", f_recv, [], _, _)) => {
unnecessary_first_then_check::check(cx, call_span, recv, f_recv, is_some);
},
_ => {},
}
}
@ -5130,12 +5174,9 @@ impl ShouldImplTraitCase {
fn lifetime_param_cond(&self, impl_item: &hir::ImplItem<'_>) -> bool {
self.lint_explicit_lifetime
|| !impl_item.generics.params.iter().any(|p| {
matches!(
p.kind,
hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Explicit
}
)
matches!(p.kind, hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Explicit
})
})
}
}

View file

@ -5,7 +5,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Expr, Mutability};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::MUT_MUTEX_LOCK;

View file

@ -4,8 +4,8 @@ use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::Span;
use super::utils::get_last_chain_binding_hir_id;
use super::NEEDLESS_CHARACTER_ITERATION;
use super::utils::get_last_chain_binding_hir_id;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::SpanRangeExt;
use clippy_utils::{match_def_path, path_to_local_id, peel_blocks};

View file

@ -4,12 +4,12 @@ use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{get_type_diagnostic_name, make_normalized_projection, make_projection};
use clippy_utils::{
can_move_expr_to_closure, fn_def_id, get_enclosing_block, higher, is_trait_method, path_to_local, path_to_local_id,
CaptureKind,
CaptureKind, can_move_expr_to_closure, fn_def_id, get_enclosing_block, higher, is_trait_method, path_to_local,
path_to_local_id,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::intravisit::{Visitor, walk_block, walk_expr};
use rustc_hir::{
BindingMode, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind,
};
@ -17,7 +17,7 @@ use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, AssocKind, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, Ty};
use rustc_span::symbol::Ident;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";

View file

@ -4,8 +4,8 @@ use clippy_utils::source::SpanRangeExt;
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::usage::local_used_after_expr;
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::Expr;
use rustc_hir::def::Res;
use rustc_lint::LateContext;
use rustc_span::sym;

View file

@ -1,6 +1,6 @@
use clippy_utils::SpanlessEq;
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::is_type_lang_item;
use clippy_utils::SpanlessEq;
use rustc_ast::LitKind;
use rustc_hir::{ExprKind, LangItem};
use rustc_lint::LateContext;

View file

@ -8,7 +8,7 @@ use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::Ty;
use rustc_span::source_map::Spanned;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::{NONSENSICAL_OPEN_OPTIONS, SUSPICIOUS_OPEN_OPTIONS};
@ -126,17 +126,13 @@ fn get_open_options(
&& let ExprKind::Path(path) = callee.kind
&& let Some(did) = cx.qpath_res(&path, callee.hir_id).opt_def_id()
{
let std_file_options = [
sym::file_options,
sym::open_options_new,
];
let std_file_options = [sym::file_options, sym::open_options_new];
let tokio_file_options: &[&[&str]] = &[
&paths::TOKIO_IO_OPEN_OPTIONS_NEW,
&paths::TOKIO_FILE_OPTIONS,
];
let tokio_file_options: &[&[&str]] = &[&paths::TOKIO_IO_OPEN_OPTIONS_NEW, &paths::TOKIO_FILE_OPTIONS];
let is_std_options = std_file_options.into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, did));
let is_std_options = std_file_options
.into_iter()
.any(|sym| cx.tcx.is_diagnostic_item(sym, did));
is_std_options || match_any_def_paths(cx, did, tokio_file_options).is_some()
} else {
false

View file

@ -3,9 +3,9 @@ use clippy_utils::ty::is_type_diagnostic_item;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::{method_call, OPTION_AS_REF_CLONED};
use super::{OPTION_AS_REF_CLONED, method_call};
pub(super) fn check(cx: &LateContext<'_>, cloned_recv: &Expr<'_>, cloned_ident_span: Span) {
if let Some((method @ ("as_ref" | "as_mut"), as_ref_recv, [], as_ref_ident_span, _)) = method_call(cloned_recv)

View file

@ -7,7 +7,7 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Symbol};
use rustc_span::{Symbol, sym};
use super::OPTION_AS_REF_DEREF;
@ -48,7 +48,9 @@ pub(super) fn check(
.map_or(false, |fun_def_id| {
cx.tcx.is_diagnostic_item(sym::deref_method, fun_def_id)
|| cx.tcx.is_diagnostic_item(sym::deref_mut_method, fun_def_id)
|| deref_aliases.iter().any(|&sym| cx.tcx.is_diagnostic_item(sym, fun_def_id))
|| deref_aliases
.iter()
.any(|&sym| cx.tcx.is_diagnostic_item(sym, fun_def_id))
})
},
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
@ -69,7 +71,9 @@ pub(super) fn check(
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
cx.tcx.is_diagnostic_item(sym::deref_method, method_did)
|| cx.tcx.is_diagnostic_item(sym::deref_mut_method, method_did)
|| deref_aliases.iter().any(|&sym| cx.tcx.is_diagnostic_item(sym, method_did))
|| deref_aliases
.iter()
.any(|&sym| cx.tcx.is_diagnostic_item(sym, method_did))
} else {
false
}

View file

@ -5,11 +5,11 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_path, Visitor};
use rustc_hir::intravisit::{Visitor, walk_path};
use rustc_hir::{ExprKind, HirId, Node, PatKind, Path, QPath};
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use std::ops::ControlFlow;
use super::MAP_UNWRAP_OR;

View file

@ -11,8 +11,8 @@ use clippy_utils::{
use rustc_errors::Applicability;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::symbol::{self, sym, Symbol};
use rustc_span::Span;
use rustc_span::symbol::{self, Symbol, sym};
use {rustc_ast as ast, rustc_hir as hir};
use super::{OR_FUN_CALL, UNWRAP_OR_DEFAULT};

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::OR_THEN_UNWRAP;

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::source::snippet;
use clippy_utils::{higher, is_integer_const, is_trait_method, SpanlessEq};
use clippy_utils::{SpanlessEq, higher, is_integer_const, is_trait_method};
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::LateContext;
use rustc_span::sym;

View file

@ -8,8 +8,8 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::PatKind;
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
use super::SEARCH_IS_SOME;

View file

@ -6,9 +6,9 @@ use rustc_lint::LateContext;
use rustc_span::sym;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::is_enum_variant_ctor;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::implements_trait;
use clippy_utils::is_enum_variant_ctor;
use super::SEEK_FROM_CURRENT;

View file

@ -1,12 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::implements_trait;
use clippy_utils::{is_expr_used_or_unified, is_enum_variant_ctor};
use clippy_utils::{is_enum_variant_ctor, is_expr_used_or_unified};
use rustc_ast::ast::{LitIntType, LitKind};
use rustc_data_structures::packed::Pu128;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::SEEK_TO_START_INSTEAD_OF_REWIND;

View file

@ -3,7 +3,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::snippet_with_context;
use clippy_utils::usage::local_used_after_expr;
use clippy_utils::visitors::{for_each_expr, Descend};
use clippy_utils::visitors::{Descend, for_each_expr};
use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths};
use core::ops::ControlFlow;
use rustc_errors::Applicability;
@ -12,7 +12,7 @@ use rustc_hir::{
};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Span, Symbol, SyntaxContext};
use rustc_span::{Span, Symbol, SyntaxContext, sym};
use super::{MANUAL_SPLIT_ONCE, NEEDLESS_SPLITN};

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_errors::{Applicability, Diag};
use rustc_lint::LateContext;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use {rustc_ast as ast, rustc_hir as hir};
use super::SUSPICIOUS_COMMAND_ARG_SPACE;

View file

@ -7,7 +7,7 @@ use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_middle::ty::{self, ExistentialPredicate, Ty};
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
/// Checks if the given type is `dyn Any`, or a trait object that has `Any` as a supertrait.
/// Only in those cases will its vtable have a `type_id` method that returns the implementor's

View file

@ -6,7 +6,7 @@ use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::UNNECESSARY_FALLIBLE_CONVERSIONS;

View file

@ -2,7 +2,7 @@ use super::utils::clone_or_copy_needed;
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::is_copy;
use clippy_utils::usage::mutated_variables;
use clippy_utils::visitors::{for_each_expr_without_closures, Descend};
use clippy_utils::visitors::{Descend, for_each_expr_without_closures};
use clippy_utils::{is_res_lang_ctor, is_trait_method, path_res, path_to_local_id};
use core::ops::ControlFlow;
use rustc_hir as hir;

View file

@ -0,0 +1,56 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::SpanRangeExt;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::Span;
use super::UNNECESSARY_FIRST_THEN_CHECK;
pub(super) fn check(
cx: &LateContext<'_>,
call_span: Span,
first_call: &Expr<'_>,
first_caller: &Expr<'_>,
is_some: bool,
) {
if !cx
.typeck_results()
.expr_ty_adjusted(first_caller)
.peel_refs()
.is_slice()
{
return;
}
let ExprKind::MethodCall(_, _, _, first_call_span) = first_call.kind else {
return;
};
let both_calls_span = first_call_span.with_hi(call_span.hi());
if let Some(both_calls_snippet) = both_calls_span.get_source_text(cx)
&& let Some(first_caller_snippet) = first_caller.span.get_source_text(cx)
{
let (sugg_span, suggestion) = if is_some {
(
first_caller.span.with_hi(call_span.hi()),
format!("!{first_caller_snippet}.is_empty()"),
)
} else {
(both_calls_span, "is_empty()".to_owned())
};
span_lint_and_sugg(
cx,
UNNECESSARY_FIRST_THEN_CHECK,
sugg_span,
format!(
"unnecessary use of `{both_calls_snippet}` to check if slice {}",
if is_some { "is not empty" } else { "is empty" }
),
"replace this with",
suggestion,
Applicability::MaybeIncorrect,
);
}
}

View file

@ -8,7 +8,7 @@ use rustc_hir as hir;
use rustc_hir::PatKind;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::UNNECESSARY_FOLD;
@ -123,58 +123,32 @@ pub(super) fn check(
if let hir::ExprKind::Lit(lit) = init.kind {
match lit.node {
ast::LitKind::Bool(false) => {
check_fold_with_op(
cx,
expr,
acc,
fold_span,
hir::BinOpKind::Or,
Replacement {
has_args: true,
has_generic_return: false,
method_name: "any",
},
);
check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Or, Replacement {
has_args: true,
has_generic_return: false,
method_name: "any",
});
},
ast::LitKind::Bool(true) => {
check_fold_with_op(
cx,
expr,
acc,
fold_span,
hir::BinOpKind::And,
Replacement {
has_args: true,
has_generic_return: false,
method_name: "all",
},
);
check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::And, Replacement {
has_args: true,
has_generic_return: false,
method_name: "all",
});
},
ast::LitKind::Int(Pu128(0), _) => check_fold_with_op(
cx,
expr,
acc,
fold_span,
hir::BinOpKind::Add,
Replacement {
ast::LitKind::Int(Pu128(0), _) => {
check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Add, Replacement {
has_args: false,
has_generic_return: needs_turbofish(cx, expr),
method_name: "sum",
},
),
});
},
ast::LitKind::Int(Pu128(1), _) => {
check_fold_with_op(
cx,
expr,
acc,
fold_span,
hir::BinOpKind::Mul,
Replacement {
has_args: false,
has_generic_return: needs_turbofish(cx, expr),
method_name: "product",
},
);
check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Mul, Replacement {
has_args: false,
has_generic_return: needs_turbofish(cx, expr),
method_name: "product",
});
},
_ => (),
}

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::Ty;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::UNNECESSARY_GET_THEN_CHECK;

View file

@ -10,7 +10,7 @@ use rustc_errors::Applicability;
use rustc_hir::def_id::DefId;
use rustc_hir::{BindingMode, Expr, ExprKind, Node, PatKind};
use rustc_lint::LateContext;
use rustc_span::{sym, Symbol};
use rustc_span::{Symbol, sym};
use super::UNNECESSARY_TO_OWNED;

View file

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{is_res_lang_ctor, last_path_segment, path_res, MaybePath};
use clippy_utils::{MaybePath, is_res_lang_ctor, last_path_segment, path_res};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;

View file

@ -1,16 +1,15 @@
use std::cmp::Ordering;
use super::UNNECESSARY_MIN_OR_MAX;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::consts::{ConstEvalCtxt, Constant, ConstantSource, FullInt};
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::Span;
use rustc_span::{Span, sym};
pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,
@ -21,26 +20,30 @@ pub(super) fn check<'tcx>(
) {
let typeck_results = cx.typeck_results();
let ecx = ConstEvalCtxt::with_env(cx.tcx, cx.param_env, typeck_results);
if let Some((left, ConstantSource::Local | ConstantSource::CoreConstant)) = ecx.eval_with_source(recv)
&& let Some((right, ConstantSource::Local | ConstantSource::CoreConstant)) = ecx.eval_with_source(arg)
if let Some(id) = typeck_results.type_dependent_def_id(expr.hir_id)
&& (cx.tcx.is_diagnostic_item(sym::cmp_ord_min, id) || cx.tcx.is_diagnostic_item(sym::cmp_ord_max, id))
{
let Some(ord) = Constant::partial_cmp(cx.tcx, typeck_results.expr_ty(recv), &left, &right) else {
return;
};
if let Some((left, ConstantSource::Local | ConstantSource::CoreConstant)) = ecx.eval_with_source(recv)
&& let Some((right, ConstantSource::Local | ConstantSource::CoreConstant)) = ecx.eval_with_source(arg)
{
let Some(ord) = Constant::partial_cmp(cx.tcx, typeck_results.expr_ty(recv), &left, &right) else {
return;
};
lint(cx, expr, name, recv.span, arg.span, ord);
} else if let Some(extrema) = detect_extrema(cx, recv) {
let ord = match extrema {
Extrema::Minimum => Ordering::Less,
Extrema::Maximum => Ordering::Greater,
};
lint(cx, expr, name, recv.span, arg.span, ord);
} else if let Some(extrema) = detect_extrema(cx, arg) {
let ord = match extrema {
Extrema::Minimum => Ordering::Greater,
Extrema::Maximum => Ordering::Less,
};
lint(cx, expr, name, recv.span, arg.span, ord);
lint(cx, expr, name, recv.span, arg.span, ord);
} else if let Some(extrema) = detect_extrema(cx, recv) {
let ord = match extrema {
Extrema::Minimum => Ordering::Less,
Extrema::Maximum => Ordering::Greater,
};
lint(cx, expr, name, recv.span, arg.span, ord);
} else if let Some(extrema) = detect_extrema(cx, arg) {
let ord = match extrema {
Extrema::Minimum => Ordering::Greater,
Extrema::Maximum => Ordering::Less,
};
lint(cx, expr, name, recv.span, arg.span, ord);
}
}
}

View file

@ -8,8 +8,8 @@ use rustc_hir::{Closure, Expr, ExprKind, HirId, QPath};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use super::utils::get_last_chain_binding_hir_id;
use super::UNNECESSARY_RESULT_MAP_OR_ELSE;
use super::utils::get_last_chain_binding_hir_id;
fn emit_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, def_arg: &Expr<'_>) {
let msg = "unused \"map closure\" when calling `Result::map_or_else` value";

View file

@ -2,12 +2,11 @@ use super::implicit_clone::is_clone_like;
use super::unnecessary_iter_cloned::{self, is_into_iter};
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::{snippet, SpanRangeExt};
use clippy_utils::source::{SpanRangeExt, snippet};
use clippy_utils::ty::{get_iterator_item_ty, implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item};
use clippy_utils::visitors::find_all_ret_expressions;
use clippy_utils::{
fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, peel_middle_ty_refs,
return_ty,
fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, peel_middle_ty_refs, return_ty,
};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
@ -20,7 +19,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
use rustc_middle::ty::{
self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty,
};
use rustc_span::{sym, Symbol};
use rustc_span::{Symbol, sym};
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
use rustc_trait_selection::traits::{Obligation, ObligationCause};
@ -717,7 +716,7 @@ fn check_if_applicable_to_argument<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'tcx
// check that:
// 1. This is a method with only one argument that doesn't come from a trait.
// 2. That it has `Borrow` in its generic predicates.
// 3. `Self` is a std "map type" (ie `HashSet`, `HashMap`, BTreeSet`, `BTreeMap`).
// 3. `Self` is a std "map type" (ie `HashSet`, `HashMap`, `BTreeSet`, `BTreeMap`).
fn check_borrow_predicate<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
if let ExprKind::MethodCall(_, caller, &[arg], _) = expr.kind
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)

View file

@ -1,11 +1,11 @@
use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::source::{snippet, SpanRangeExt};
use clippy_utils::source::{SpanRangeExt, snippet};
use clippy_utils::{expr_or_init, is_trait_method, pat_is_wild};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, FnDecl, PatKind, TyKind};
use rustc_lint::LateContext;
use rustc_middle::ty::AdtDef;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use crate::loops::UNUSED_ENUMERATE_INDEX;

View file

@ -9,7 +9,7 @@ use rustc_hir::{self as hir, LangItem};
use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use core::ops::ControlFlow;

View file

@ -1,12 +1,12 @@
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{get_parent_expr, path_to_local_id, usage};
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::intravisit::{Visitor, walk_expr};
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, QPath, Stmt, StmtKind};
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;
pub(super) fn derefs_to_slice<'tcx>(
cx: &LateContext<'tcx>,

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_span::source_map::Spanned;
use rustc_span::{sym, Span};
use rustc_span::{Span, sym};
use super::VEC_RESIZE_TO_ZERO;

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::is_trait_method;
use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;