From 507e6f058dbe00e27e5a7fdebe1d3524faeeb5ed Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Fri, 13 Dec 2024 17:40:11 +0000 Subject: [PATCH] Migrate clippy_lints to new MSRV API --- clippy_lints/src/almost_complete_range.rs | 8 +-- clippy_lints/src/approx_const.rs | 8 +-- clippy_lints/src/assigning_clones.rs | 8 +-- clippy_lints/src/attrs/deprecated_cfg_attr.rs | 4 +- clippy_lints/src/attrs/mod.rs | 40 +++++-------- clippy_lints/src/booleans.rs | 22 ++++--- clippy_lints/src/casts/borrow_as_ptr.rs | 4 +- .../src/casts/cast_abs_to_unsigned.rs | 4 +- clippy_lints/src/casts/cast_lossless.rs | 6 +- .../src/casts/cast_slice_different_sizes.rs | 4 +- .../src/casts/cast_slice_from_raw_parts.rs | 4 +- clippy_lints/src/casts/mod.rs | 24 ++++---- clippy_lints/src/casts/ptr_as_ptr.rs | 4 +- clippy_lints/src/casts/ptr_cast_constness.rs | 4 +- clippy_lints/src/checked_conversions.rs | 8 +-- clippy_lints/src/derivable_impls.rs | 8 +-- clippy_lints/src/format_args.rs | 6 +- clippy_lints/src/from_over_into.rs | 8 +-- clippy_lints/src/if_then_some_else_none.rs | 10 +--- clippy_lints/src/implicit_saturating_sub.rs | 16 ++--- clippy_lints/src/incompatible_msrv.rs | 31 +++++----- clippy_lints/src/index_refutable_slice.rs | 6 +- clippy_lints/src/instant_subtraction.rs | 8 +-- clippy_lints/src/legacy_numeric_constants.rs | 10 +--- clippy_lints/src/lib.rs | 7 +-- clippy_lints/src/loops/explicit_iter_loop.rs | 11 ++-- clippy_lints/src/loops/mod.rs | 6 +- clippy_lints/src/manual_bits.rs | 8 +-- clippy_lints/src/manual_clamp.rs | 9 +-- clippy_lints/src/manual_div_ceil.rs | 8 +-- clippy_lints/src/manual_float_methods.rs | 8 +-- clippy_lints/src/manual_hash_one.rs | 8 +-- clippy_lints/src/manual_is_ascii_check.rs | 10 +--- clippy_lints/src/manual_let_else.rs | 2 +- clippy_lints/src/manual_main_separator_str.rs | 8 +-- clippy_lints/src/manual_non_exhaustive.rs | 6 +- clippy_lints/src/manual_rem_euclid.rs | 10 +--- clippy_lints/src/manual_retain.rs | 24 ++++---- clippy_lints/src/manual_strip.rs | 8 +-- clippy_lints/src/matches/collapsible_match.rs | 8 +-- clippy_lints/src/matches/mod.rs | 20 +++---- clippy_lints/src/matches/redundant_guards.rs | 6 +- clippy_lints/src/mem_replace.rs | 7 +-- .../src/methods/cloned_instead_of_copied.rs | 6 +- clippy_lints/src/methods/err_expect.rs | 4 +- clippy_lints/src/methods/filter_map_next.rs | 4 +- .../src/methods/is_digit_ascii_radix.rs | 4 +- clippy_lints/src/methods/iter_kv_map.rs | 4 +- .../src/methods/manual_c_str_literals.rs | 8 +-- clippy_lints/src/methods/manual_inspect.rs | 4 +- .../src/methods/manual_is_variant_and.rs | 4 +- clippy_lints/src/methods/manual_try_fold.rs | 4 +- clippy_lints/src/methods/map_clone.rs | 6 +- clippy_lints/src/methods/map_unwrap_or.rs | 4 +- .../map_with_unused_argument_over_ranges.rs | 6 +- clippy_lints/src/methods/mod.rs | 58 +++++++++---------- .../src/methods/option_as_ref_deref.rs | 4 +- .../src/methods/option_map_unwrap_or.rs | 4 +- .../src/methods/path_ends_with_ext.rs | 4 +- clippy_lints/src/methods/str_splitn.rs | 4 +- .../src/methods/string_lit_chars_any.rs | 4 +- .../src/methods/unnecessary_map_or.rs | 6 +- .../src/methods/unnecessary_to_owned.rs | 6 +- clippy_lints/src/missing_const_for_fn.rs | 20 +++---- .../src/missing_const_for_thread_local.rs | 14 ++--- .../src/needless_borrows_for_generic_args.rs | 10 ++-- clippy_lints/src/question_mark.rs | 3 +- clippy_lints/src/ranges.rs | 7 +-- clippy_lints/src/redundant_field_names.rs | 8 +-- .../src/redundant_static_lifetimes.rs | 8 +-- clippy_lints/src/std_instead_of_core.rs | 12 ++-- clippy_lints/src/string_patterns.rs | 12 ++-- clippy_lints/src/trait_bounds.rs | 6 +- clippy_lints/src/transmute/mod.rs | 16 ++--- .../src/transmute/transmute_float_to_int.rs | 4 +- .../src/transmute/transmute_int_to_float.rs | 4 +- .../src/transmute/transmute_num_to_bytes.rs | 5 +- .../src/transmute/transmute_ptr_to_ptr.rs | 6 +- .../src/transmute/transmute_ptr_to_ref.rs | 6 +- clippy_lints/src/tuple_array_conversions.rs | 8 +-- clippy_lints/src/unnested_or_patterns.rs | 8 +-- clippy_lints/src/unused_trait_names.rs | 8 +-- clippy_lints/src/use_self.rs | 10 ++-- .../utils/internal_lints/msrv_attr_impl.rs | 13 ++--- clippy_lints/src/vec.rs | 6 +- 85 files changed, 310 insertions(+), 461 deletions(-) diff --git a/clippy_lints/src/almost_complete_range.rs b/clippy_lints/src/almost_complete_range.rs index 2af5178920d9..0f5df270252c 100644 --- a/clippy_lints/src/almost_complete_range.rs +++ b/clippy_lints/src/almost_complete_range.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::source::{trim_span, walk_span_to_context}; use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits}; use rustc_errors::Applicability; @@ -32,12 +32,12 @@ declare_clippy_lint! { impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]); pub struct AlmostCompleteRange { - msrv: Msrv, + msrv: MsrvStack, } impl AlmostCompleteRange { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -97,7 +97,7 @@ impl EarlyLintPass for AlmostCompleteRange { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } fn is_incomplete_range(start: &Expr, end: &Expr) -> bool { diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index ebd35fd2b27f..a5413ee6a2f9 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -68,9 +68,7 @@ pub struct ApproxConstant { impl ApproxConstant { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { @@ -91,7 +89,7 @@ impl ApproxConstant { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { - if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) { + if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv)) { span_lint_and_help( cx, APPROX_CONSTANT, @@ -115,8 +113,6 @@ impl<'tcx> LateLintPass<'tcx> for ApproxConstant { self.check_lit(cx, &lit.node, e); } } - - extract_msrv_attr!(LateContext); } /// Returns `false` if the number of significant figures in `value` are diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs index c8dd77d9578d..29b791c6610e 100644 --- a/clippy_lints/src/assigning_clones.rs +++ b/clippy_lints/src/assigning_clones.rs @@ -59,9 +59,7 @@ pub struct AssigningClones { impl AssigningClones { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -90,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { sym::clone if is_diag_trait_item(cx, fn_id, sym::Clone) => CloneTrait::Clone, _ if fn_name.as_str() == "to_owned" && is_diag_trait_item(cx, fn_id, sym::ToOwned) - && self.msrv.meets(msrvs::CLONE_INTO) => + && self.msrv.meets(cx, msrvs::CLONE_INTO) => { CloneTrait::ToOwned }, @@ -143,8 +141,6 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { ); } } - - extract_msrv_attr!(LateContext); } /// Checks if the data being cloned borrows from the place that is being assigned to: diff --git a/clippy_lints/src/attrs/deprecated_cfg_attr.rs b/clippy_lints/src/attrs/deprecated_cfg_attr.rs index 3a462018e3e0..cd38aed26a3e 100644 --- a/clippy_lints/src/attrs/deprecated_cfg_attr.rs +++ b/clippy_lints/src/attrs/deprecated_cfg_attr.rs @@ -1,12 +1,12 @@ use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::AttrStyle; use rustc_errors::Applicability; use rustc_lint::EarlyContext; use rustc_span::sym; -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msrv) { +pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) { // check cfg_attr if attr.has_name(sym::cfg_attr) && let Some(items) = attr.meta_item_list() diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index a9766597d50d..6dbbbf40df18 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -13,11 +13,11 @@ mod useless_attribute; mod utils; use clippy_config::Conf; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind}; use rustc_hir::{ImplItem, Item, TraitItem}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; +use rustc_session::{declare_lint_pass, impl_lint_pass}; use rustc_span::sym; use utils::{is_lint_level, is_relevant_impl, is_relevant_item, is_relevant_trait}; @@ -409,22 +409,10 @@ declare_clippy_lint! { "duplicated attribute" } -pub struct Attributes { - msrv: Msrv, -} - -impl_lint_pass!(Attributes => [ +declare_lint_pass!(Attributes => [ INLINE_ALWAYS, ]); -impl Attributes { - pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } - } -} - impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); @@ -444,47 +432,45 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); } } - - extract_msrv_attr!(LateContext); } -pub struct EarlyAttributes { - msrv: Msrv, +pub struct PreExpansionEarlyAttributes { + msrv: MsrvStack, } -impl EarlyAttributes { +impl PreExpansionEarlyAttributes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } -impl_lint_pass!(EarlyAttributes => [ +impl_lint_pass!(PreExpansionEarlyAttributes => [ DEPRECATED_CFG_ATTR, NON_MINIMAL_CFG, DEPRECATED_CLIPPY_CFG_ATTR, UNNECESSARY_CLIPPY_CFG, ]); -impl EarlyLintPass for EarlyAttributes { +impl EarlyLintPass for PreExpansionEarlyAttributes { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { deprecated_cfg_attr::check(cx, attr, &self.msrv); deprecated_cfg_attr::check_clippy(cx, attr); non_minimal_cfg::check(cx, attr); } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } pub struct PostExpansionEarlyAttributes { - msrv: Msrv, + msrv: MsrvStack, } impl PostExpansionEarlyAttributes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -548,5 +534,5 @@ impl EarlyLintPass for PostExpansionEarlyAttributes { duplicated_attributes::check(cx, &item.attrs); } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 6eef0d42a550..cc8c8658b08b 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -83,9 +83,7 @@ pub struct NonminimalBool { impl NonminimalBool { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -101,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _: Span, _: LocalDefId, ) { - NonminimalBoolVisitor { cx, msrv: &self.msrv }.visit_body(body); + NonminimalBoolVisitor { cx, msrv: self.msrv }.visit_body(body); } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { @@ -118,8 +116,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _ => {}, } } - - extract_msrv_attr!(LateContext); } fn inverted_bin_op_eq_str(op: BinOpKind) -> Option<&'static str> { @@ -196,7 +192,7 @@ fn check_inverted_bool_in_condition( ); } -fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) { +fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) { if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind && !expr.span.from_expansion() && !inner.span.from_expansion() @@ -232,7 +228,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) { struct NonminimalBoolVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, - msrv: &'a Msrv, + msrv: Msrv, } use quine_mc_cluskey::Bool; @@ -325,7 +321,7 @@ impl<'v> Hir2Qmm<'_, '_, 'v> { struct SuggestContext<'a, 'tcx, 'v> { terminals: &'v [&'v Expr<'v>], cx: &'a LateContext<'tcx>, - msrv: &'a Msrv, + msrv: Msrv, output: String, } @@ -395,7 +391,7 @@ impl SuggestContext<'_, '_, '_> { } } -fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Option { +fn simplify_not(cx: &LateContext<'_>, curr_msrv: Msrv, expr: &Expr<'_>) -> Option { match &expr.kind { ExprKind::Binary(binop, lhs, rhs) => { if !implements_ord(cx, lhs) { @@ -437,7 +433,9 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti .iter() .copied() .flat_map(|(msrv, a, b)| vec![(msrv, a, b), (msrv, b, a)]) - .find(|&(msrv, a, _)| msrv.is_none_or(|msrv| curr_msrv.meets(msrv)) && a == path.ident.name.as_str()) + .find(|&(msrv, a, _)| { + msrv.is_none_or(|msrv| curr_msrv.meets(cx, msrv)) && a == path.ident.name.as_str() + }) .and_then(|(_, _, neg_method)| { let negated_args = args .iter() @@ -466,7 +464,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti } } -fn suggest(cx: &LateContext<'_>, msrv: &Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { +fn suggest(cx: &LateContext<'_>, msrv: Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { let mut suggest_context = SuggestContext { terminals, cx, diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs index 67aa33ca06c3..9406167fd494 100644 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ b/clippy_lints/src/casts/borrow_as_ptr.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'_>, cast_expr: &'tcx Expr<'_>, cast_to: &'tcx Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { if matches!(cast_to.kind, TyKind::Ptr(_)) && let ExprKind::AddrOf(BorrowKind::Ref, mutability, e) = cast_expr.kind @@ -32,7 +32,7 @@ pub(super) fn check<'tcx>( return false; } - let suggestion = if msrv.meets(msrvs::RAW_REF_OP) { + let suggestion = if msrv.meets(cx, msrvs::RAW_REF_OP) { let operator_kind = match mutability { Mutability::Not => "const", Mutability::Mut => "mut", diff --git a/clippy_lints/src/casts/cast_abs_to_unsigned.rs b/clippy_lints/src/casts/cast_abs_to_unsigned.rs index ae433773193a..7f0421bd366e 100644 --- a/clippy_lints/src/casts/cast_abs_to_unsigned.rs +++ b/clippy_lints/src/casts/cast_abs_to_unsigned.rs @@ -14,9 +14,9 @@ pub(super) fn check( cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::UNSIGNED_ABS) + if msrv.meets(cx, msrvs::UNSIGNED_ABS) && let ty::Int(from) = cast_from.kind() && let ty::Uint(to) = cast_to.kind() && let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index 4ad39d9160de..16142c904cc9 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -19,7 +19,7 @@ pub(super) fn check( cast_from: Ty<'_>, cast_to: Ty<'_>, cast_to_hir: &rustc_hir::Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) { if !should_lint(cx, cast_from, cast_to, msrv) { return; @@ -70,7 +70,7 @@ pub(super) fn check( ); } -fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool { +fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: Msrv) -> bool { // Do not suggest using From in consts/statics until it is valid to do so (see #2267). if is_in_const_context(cx) { return false; @@ -96,7 +96,7 @@ fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: & }; !is_isize_or_usize(cast_from) && from_nbits < to_nbits }, - (false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(msrvs::FROM_BOOL) => true, + (false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(cx, msrvs::FROM_BOOL) => true, (_, _) => { matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64)) }, diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 030c2d322db6..c247840ad042 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -9,9 +9,9 @@ use rustc_middle::ty::{self, Ty, TypeAndMut}; use super::CAST_SLICE_DIFFERENT_SIZES; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Msrv) { // suggestion is invalid if `ptr::slice_from_raw_parts` does not exist - if !msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) { + if !msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) { return; } diff --git a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs index c3bc5c0c9f2a..f40b8d0d9de8 100644 --- a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs +++ b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs @@ -23,8 +23,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option { } } -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) { - if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: Msrv) { + if msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) && let ty::RawPtr(ptrty, _) = cast_to.kind() && let ty::Slice(_) = ptrty.kind() && let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index c64c0e15144d..0e1385cefbd5 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -760,9 +760,7 @@ pub struct Casts { impl Casts { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -812,8 +810,8 @@ impl<'tcx> LateLintPass<'tcx> for Casts { if !expr.span.from_expansion() && unnecessary_cast::check(cx, expr, cast_from_expr, cast_from, cast_to) { return; } - cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, &self.msrv); - ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, &self.msrv); + cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv); + ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv); as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to); fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to); fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to); @@ -826,32 +824,30 @@ impl<'tcx> LateLintPass<'tcx> for Casts { cast_possible_wrap::check(cx, expr, cast_from, cast_to); cast_precision_loss::check(cx, expr, cast_from, cast_to); cast_sign_loss::check(cx, expr, cast_from_expr, cast_from, cast_to); - cast_abs_to_unsigned::check(cx, expr, cast_from_expr, cast_from, cast_to, &self.msrv); + cast_abs_to_unsigned::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv); cast_nan_to_int::check(cx, expr, cast_from_expr, cast_from, cast_to); } - cast_lossless::check(cx, expr, cast_from_expr, cast_from, cast_to, cast_to_hir, &self.msrv); + cast_lossless::check(cx, expr, cast_from_expr, cast_from, cast_to, cast_to_hir, self.msrv); cast_enum_constructor::check(cx, expr, cast_from_expr, cast_from); } as_underscore::check(cx, expr, cast_to_hir); as_pointer_underscore::check(cx, cast_to, cast_to_hir); - let was_borrow_as_ptr_emitted = if self.msrv.meets(msrvs::BORROW_AS_PTR) { - borrow_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir, &self.msrv) + let was_borrow_as_ptr_emitted = if self.msrv.meets(cx, msrvs::BORROW_AS_PTR) { + borrow_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir, self.msrv) } else { false }; - if self.msrv.meets(msrvs::PTR_FROM_REF) && !was_borrow_as_ptr_emitted { + if self.msrv.meets(cx, msrvs::PTR_FROM_REF) && !was_borrow_as_ptr_emitted { ref_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir); } } cast_ptr_alignment::check(cx, expr); char_lit_as_u8::check(cx, expr); - ptr_as_ptr::check(cx, expr, &self.msrv); - cast_slice_different_sizes::check(cx, expr, &self.msrv); + ptr_as_ptr::check(cx, expr, self.msrv); + cast_slice_different_sizes::check(cx, expr, self.msrv); ptr_cast_constness::check_null_ptr_cast_method(cx, expr); } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index a138ade54aad..290609750a47 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -26,8 +26,8 @@ impl OmitFollowedCastReason<'_> { } } -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { - if !msrv.meets(msrvs::POINTER_CAST) { +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) { + if !msrv.meets(cx, msrvs::POINTER_CAST) { return; } diff --git a/clippy_lints/src/casts/ptr_cast_constness.rs b/clippy_lints/src/casts/ptr_cast_constness.rs index 945c05ee9436..cad9c1df273f 100644 --- a/clippy_lints/src/casts/ptr_cast_constness.rs +++ b/clippy_lints/src/casts/ptr_cast_constness.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( cast_expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { if let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind() && let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind() @@ -52,7 +52,7 @@ pub(super) fn check<'tcx>( return; } - if msrv.meets(msrvs::POINTER_CAST_CONSTNESS) { + if msrv.meets(cx, msrvs::POINTER_CAST_CONSTNESS) { let sugg = Sugg::hir(cx, cast_expr, "_"); let constness = match *to_mutbl { Mutability::Not => "const", diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 364f5c7dc7a0..7dda01f0680c 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -40,9 +40,7 @@ pub struct CheckedConversions { impl CheckedConversions { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -66,7 +64,7 @@ impl LateLintPass<'_> for CheckedConversions { } && !in_external_macro(cx.sess(), item.span) && !is_in_const_context(cx) - && self.msrv.meets(msrvs::TRY_FROM) + && self.msrv.meets(cx, msrvs::TRY_FROM) && let Some(cv) = match op2 { // todo: check for case signed -> larger unsigned == only x >= 0 None => check_upper_bound(lt1, gt1).filter(|cv| cv.cvt == ConversionType::FromUnsigned), @@ -94,8 +92,6 @@ impl LateLintPass<'_> for CheckedConversions { ); } } - - extract_msrv_attr!(LateContext); } /// Contains the result of a tried conversion check diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 9569081ad088..148f84de5cf2 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -62,9 +62,7 @@ pub struct DerivableImpls { impl DerivableImpls { pub fn new(conf: &'static Conf) -> Self { - DerivableImpls { - msrv: conf.msrv.clone(), - } + DerivableImpls { msrv: conf.msrv } } } @@ -205,11 +203,9 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { { if adt_def.is_struct() { check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b)); - } else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) { + } else if adt_def.is_enum() && self.msrv.meets(cx, msrvs::DEFAULT_ENUM_ATTRIBUTE) { check_enum(cx, item, func_expr, adt_def); } } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index da5825b7ab21..ff313e8d4c79 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -180,7 +180,7 @@ impl FormatArgs { pub fn new(conf: &'static Conf, format_args: FormatArgsStorage) -> Self { Self { format_args, - msrv: conf.msrv.clone(), + msrv: conf.msrv, ignore_mixed: conf.allow_mixed_uninlined_format_args, } } @@ -202,13 +202,11 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { linter.check_templates(); - if self.msrv.meets(msrvs::FORMAT_ARGS_CAPTURE) { + if self.msrv.meets(cx, msrvs::FORMAT_ARGS_CAPTURE) { linter.check_uninlined_args(); } } } - - extract_msrv_attr!(LateContext); } struct FormatArgsExpr<'a, 'tcx> { diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index e43c311eb854..2d8e2b8b78ea 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -58,9 +58,7 @@ pub struct FromOverInto { impl FromOverInto { pub fn new(conf: &'static Conf) -> Self { - FromOverInto { - msrv: conf.msrv.clone(), - } + FromOverInto { msrv: conf.msrv } } } @@ -77,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && self.msrv.meets(msrvs::RE_REBALANCING_COHERENCE) + && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) && span_is_local(item.span) && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) .map(ty::EarlyBinder::instantiate_identity) @@ -112,8 +110,6 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { ); } } - - extract_msrv_attr!(LateContext); } /// Finds the occurrences of `Self` and `self` diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 3fc0a6965224..f0c3a3cb096d 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -55,9 +55,7 @@ pub struct IfThenSomeElseNone { impl IfThenSomeElseNone { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -80,10 +78,10 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { && !is_else_clause(cx.tcx, expr) && !is_in_const_context(cx) && !in_external_macro(cx.sess(), expr.span) - && self.msrv.meets(msrvs::BOOL_THEN) + && self.msrv.meets(cx, msrvs::BOOL_THEN) && !contains_return(then_block.stmts) { - let method_name = if switch_to_eager_eval(cx, expr) && self.msrv.meets(msrvs::BOOL_THEN_SOME) { + let method_name = if switch_to_eager_eval(cx, expr) && self.msrv.meets(cx, msrvs::BOOL_THEN_SOME) { "then_some" } else { "then" @@ -121,6 +119,4 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 37481dc7feb7..d01fa2fa3167 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -83,9 +83,7 @@ impl_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB, INVERTED_SATU impl ImplicitSaturatingSub { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -108,12 +106,10 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { && let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind { check_manual_check( - cx, expr, cond_op, cond_left, cond_right, if_block, else_block, &self.msrv, + cx, expr, cond_op, cond_left, cond_right, if_block, else_block, self.msrv, ); } } - - extract_msrv_attr!(LateContext); } #[allow(clippy::too_many_arguments)] @@ -125,7 +121,7 @@ fn check_manual_check<'tcx>( right_hand: &Expr<'tcx>, if_block: &Expr<'tcx>, else_block: &Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { let ty = cx.typeck_results().expr_ty(left_hand); if ty.is_numeric() && !ty.is_signed() { @@ -178,7 +174,7 @@ fn check_gt( little_var: &Expr<'_>, if_block: &Expr<'_>, else_block: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, is_composited: bool, ) { if let Some(big_var) = Var::new(big_var) @@ -221,7 +217,7 @@ fn check_subtraction( little_var: Var, if_block: &Expr<'_>, else_block: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, is_composited: bool, ) { let if_block = peel_blocks(if_block); @@ -258,7 +254,7 @@ fn check_subtraction( // if `snippet_opt` fails, it won't try the next conditions. if let Some(big_var_snippet) = snippet_opt(cx, big_var.span) && let Some(little_var_snippet) = snippet_opt(cx, little_var.span) - && (!is_in_const_context(cx) || msrv.meets(msrvs::SATURATING_SUB_CONST)) + && (!is_in_const_context(cx) || msrv.meets(cx, msrvs::SATURATING_SUB_CONST)) { let sugg = format!( "{}{big_var_snippet}.saturating_sub({little_var_snippet}){}", diff --git a/clippy_lints/src/incompatible_msrv.rs b/clippy_lints/src/incompatible_msrv.rs index f3467adacc55..7b34ada6fed0 100644 --- a/clippy_lints/src/incompatible_msrv.rs +++ b/clippy_lints/src/incompatible_msrv.rs @@ -49,7 +49,7 @@ impl_lint_pass!(IncompatibleMsrv => [INCOMPATIBLE_MSRV]); impl IncompatibleMsrv { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, is_above_msrv: FxHashMap::default(), } } @@ -87,7 +87,7 @@ impl IncompatibleMsrv { return; } let version = self.get_def_id_version(cx.tcx, def_id); - if self.msrv.meets(version) || is_in_test(cx.tcx, node) { + if self.msrv.meets(cx, version) || is_in_test(cx.tcx, node) { return; } if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind { @@ -95,27 +95,22 @@ impl IncompatibleMsrv { // Intentionally not using `.from_expansion()`, since we do still care about macro expansions return; } - self.emit_lint_for(cx, span, version); - } - - fn emit_lint_for(&self, cx: &LateContext<'_>, span: Span, version: RustcVersion) { - span_lint( - cx, - INCOMPATIBLE_MSRV, - span, - format!( - "current MSRV (Minimum Supported Rust Version) is `{}` but this item is stable since `{version}`", - self.msrv - ), - ); + if let Some(current) = self.msrv.current(cx) { + span_lint( + cx, + INCOMPATIBLE_MSRV, + span, + format!( + "current MSRV (Minimum Supported Rust Version) is `{current}` but this item is stable since `{version}`", + ), + ); + } } } impl<'tcx> LateLintPass<'tcx> for IncompatibleMsrv { - extract_msrv_attr!(LateContext); - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if self.msrv.current().is_none() { + if self.msrv.current(cx).is_none() { // If there is no MSRV, then no need to check anything... return; } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index c2030a5ab090..8ec22811dc06 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -62,7 +62,7 @@ impl IndexRefutableSlice { pub fn new(conf: &'static Conf) -> Self { Self { max_suggested_slice: conf.max_suggested_slice_pattern_length, - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { if let Some(IfLet { let_pat, if_then, .. }) = IfLet::hir(cx, expr) && (!expr.span.from_expansion() || is_expn_of(expr.span, "if_chain").is_some()) && !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id) - && self.msrv.meets(msrvs::SLICE_PATTERNS) + && self.msrv.meets(cx, msrvs::SLICE_PATTERNS) && let found_slices = find_slice_values(cx, let_pat) && !found_slices.is_empty() && let filtered_slices = filter_lintable_slices(cx, found_slices, self.max_suggested_slice, if_then) @@ -85,8 +85,6 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { } } } - - extract_msrv_attr!(LateContext); } fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { diff --git a/clippy_lints/src/instant_subtraction.rs b/clippy_lints/src/instant_subtraction.rs index f4e41dc826b0..4ae1119ab3a2 100644 --- a/clippy_lints/src/instant_subtraction.rs +++ b/clippy_lints/src/instant_subtraction.rs @@ -70,9 +70,7 @@ pub struct InstantSubtraction { impl InstantSubtraction { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -99,14 +97,12 @@ impl LateLintPass<'_> for InstantSubtraction { print_manual_instant_elapsed_sugg(cx, expr, sugg); } else if ty::is_type_diagnostic_item(cx, rhs_ty, sym::Duration) && !expr.span.from_expansion() - && self.msrv.meets(msrvs::TRY_FROM) + && self.msrv.meets(cx, msrvs::TRY_FROM) { print_unchecked_duration_subtraction_sugg(cx, lhs, rhs, expr); } } } - - extract_msrv_attr!(LateContext); } fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool { diff --git a/clippy_lints/src/legacy_numeric_constants.rs b/clippy_lints/src/legacy_numeric_constants.rs index fb46bdcab6e1..ba9be6677e97 100644 --- a/clippy_lints/src/legacy_numeric_constants.rs +++ b/clippy_lints/src/legacy_numeric_constants.rs @@ -40,9 +40,7 @@ pub struct LegacyNumericConstants { impl LegacyNumericConstants { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -53,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { // Integer modules are "TBD" deprecated, and the contents are too, // so lint on the `use` statement directly. if let ItemKind::Use(path, kind @ (UseKind::Single | UseKind::Glob)) = item.kind - && self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) + && self.msrv.meets(cx, msrvs::NUMERIC_ASSOCIATED_CONSTANTS) && !in_external_macro(cx.sess(), item.span) && let Some(def_id) = path.res[0].opt_def_id() { @@ -138,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { return; }; - if self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) + if self.msrv.meets(cx, msrvs::NUMERIC_ASSOCIATED_CONSTANTS) && !in_external_macro(cx.sess(), expr.span) && !is_from_proc_macro(cx, expr) { @@ -152,8 +150,6 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { }); } } - - extract_msrv_attr!(LateContext); } fn is_integer_module(cx: &LateContext<'_>, did: DefId) -> bool { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 017e6e2a1423..853d5603b488 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -416,9 +416,7 @@ use utils::attr_collector::{AttrCollector, AttrStorage}; /// Used in `./src/driver.rs`. pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { // NOTE: Do not add any more pre-expansion passes. These should be removed eventually. - store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes::new(conf))); - - store.register_early_pass(move || Box::new(attrs::PostExpansionEarlyAttributes::new(conf))); + store.register_pre_expansion_pass(move || Box::new(attrs::PreExpansionEarlyAttributes::new(conf))); } #[derive(Default)] @@ -640,7 +638,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(mut_reference::UnnecessaryMutPassed)); store.register_late_pass(|_| Box::>::default()); store.register_late_pass(|_| Box::new(len_zero::LenZero)); - store.register_late_pass(move |_| Box::new(attrs::Attributes::new(conf))); + store.register_late_pass(move |_| Box::new(attrs::Attributes)); + store.register_early_pass(move || Box::new(attrs::PostExpansionEarlyAttributes::new(conf))); store.register_late_pass(|_| Box::new(blocks_in_conditions::BlocksInConditions)); store.register_late_pass(|_| Box::new(unicode::Unicode)); store.register_late_pass(|_| Box::new(uninit_vec::UninitVec)); diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 06cf901bfb23..5fce6b179d89 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -17,7 +17,7 @@ pub(super) fn check( cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, enforce_iter_loop_reborrow: bool, ) { let Some((adjust, ty)) = is_ref_iterable(cx, self_arg, call_expr, enforce_iter_loop_reborrow, msrv) else { @@ -26,10 +26,11 @@ pub(super) fn check( if let ty::Array(_, count) = *ty.peel_refs().kind() { if !ty.is_ref() { - if !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) { + if !msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) { return; } - } else if count.try_to_target_usize(cx.tcx).is_none_or(|x| x > 32) && !msrv.meets(msrvs::ARRAY_IMPL_ANY_LEN) { + } else if count.try_to_target_usize(cx.tcx).is_none_or(|x| x > 32) && !msrv.meets(cx, msrvs::ARRAY_IMPL_ANY_LEN) + { return; } } @@ -106,7 +107,7 @@ fn is_ref_iterable<'tcx>( self_arg: &Expr<'_>, call_expr: &Expr<'_>, enforce_iter_loop_reborrow: bool, - msrv: &Msrv, + msrv: Msrv, ) -> Option<(AdjustKind, Ty<'tcx>)> { let typeck = cx.typeck_results(); if let Some(trait_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator) @@ -126,7 +127,7 @@ fn is_ref_iterable<'tcx>( let self_ty = typeck.expr_ty(self_arg); let self_is_copy = is_copy(cx, self_ty); - if !msrv.meets(msrvs::BOX_INTO_ITER) + if !msrv.meets(cx, msrvs::BOX_INTO_ITER) && is_type_lang_item(cx, self_ty.peel_refs(), rustc_hir::LangItem::OwnedBox) { return None; diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index f3ca4a4a5715..cddc7d071411 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -721,7 +721,7 @@ pub struct Loops { impl Loops { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, enforce_iter_loop_reborrow: conf.enforce_iter_loop_reborrow, } } @@ -805,8 +805,6 @@ impl<'tcx> LateLintPass<'tcx> for Loops { manual_while_let_some::check(cx, condition, body, span); } } - - extract_msrv_attr!(LateContext); } impl Loops { @@ -840,7 +838,7 @@ impl Loops { if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind { match method.ident.as_str() { "iter" | "iter_mut" => { - explicit_iter_loop::check(cx, self_arg, arg, &self.msrv, self.enforce_iter_loop_reborrow); + explicit_iter_loop::check(cx, self_arg, arg, self.msrv, self.enforce_iter_loop_reborrow); }, "into_iter" => { explicit_into_iter_loop::check(cx, self_arg, arg); diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index c31656f8a05e..392ef7465e6a 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -40,9 +40,7 @@ pub struct ManualBits { impl ManualBits { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -53,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { if let ExprKind::Binary(bin_op, left_expr, right_expr) = expr.kind && let BinOpKind::Mul = &bin_op.node && !expr.span.from_expansion() - && self.msrv.meets(msrvs::MANUAL_BITS) + && self.msrv.meets(cx, msrvs::MANUAL_BITS) && let ctxt = expr.span.ctxt() && left_expr.span.ctxt() == ctxt && right_expr.span.ctxt() == ctxt @@ -77,8 +75,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { ); } } - - extract_msrv_attr!(LateContext); } fn get_one_size_of_ty<'tcx>( diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 484a7ba256bd..3944b51cbf43 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -99,9 +99,7 @@ pub struct ManualClamp { impl ManualClamp { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -144,7 +142,7 @@ struct InputMinMax<'tcx> { impl<'tcx> LateLintPass<'tcx> for ManualClamp { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if !self.msrv.meets(msrvs::CLAMP) { + if !self.msrv.meets(cx, msrvs::CLAMP) { return; } if !expr.span.from_expansion() && !is_in_const_context(cx) { @@ -160,14 +158,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualClamp { } fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) { - if !self.msrv.meets(msrvs::CLAMP) || is_in_const_context(cx) { + if !self.msrv.meets(cx, msrvs::CLAMP) || is_in_const_context(cx) { return; } for suggestion in is_two_if_pattern(cx, block) { maybe_emit_suggestion(cx, &suggestion); } } - extract_msrv_attr!(LateContext); } fn maybe_emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'tcx>) { diff --git a/clippy_lints/src/manual_div_ceil.rs b/clippy_lints/src/manual_div_ceil.rs index bbb89bee8355..938313228e7c 100644 --- a/clippy_lints/src/manual_div_ceil.rs +++ b/clippy_lints/src/manual_div_ceil.rs @@ -48,9 +48,7 @@ pub struct ManualDivCeil { impl ManualDivCeil { #[must_use] pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -58,7 +56,7 @@ impl_lint_pass!(ManualDivCeil => [MANUAL_DIV_CEIL]); impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if !self.msrv.meets(msrvs::MANUAL_DIV_CEIL) { + if !self.msrv.meets(cx, msrvs::MANUAL_DIV_CEIL) { return; } @@ -103,8 +101,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { } } } - - extract_msrv_attr!(LateContext); } fn check_int_ty_and_feature(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index b12f575e81a3..073c7048035c 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -88,9 +88,7 @@ pub struct ManualFloatMethods { impl ManualFloatMethods { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -106,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { && !in_external_macro(cx.sess(), expr.span) && ( matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst) - || self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY) + || self.msrv.meets(cx, msrvs::CONST_FLOAT_CLASSIFY) ) && let [first, second, const_1, const_2] = exprs && let ecx = ConstEvalCtxt::new(cx) @@ -164,8 +162,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { }); } } - - extract_msrv_attr!(LateContext); } fn is_infinity(constant: &Constant<'_>) -> bool { diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index 7e092d11f1b4..f71264a93ca8 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -53,9 +53,7 @@ pub struct ManualHashOne { impl ManualHashOne { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -98,7 +96,7 @@ impl LateLintPass<'_> for ManualHashOne { && let ExprKind::MethodCall(seg, _, [], _) = finish_expr.kind && seg.ident.name.as_str() == "finish" - && self.msrv.meets(msrvs::BUILD_HASHER_HASH_ONE) + && self.msrv.meets(cx, msrvs::BUILD_HASHER_HASH_ONE) { span_lint_hir_and_then( cx, @@ -129,6 +127,4 @@ impl LateLintPass<'_> for ManualHashOne { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_is_ascii_check.rs b/clippy_lints/src/manual_is_ascii_check.rs index 3f01f3cf30ae..a7534b42f862 100644 --- a/clippy_lints/src/manual_is_ascii_check.rs +++ b/clippy_lints/src/manual_is_ascii_check.rs @@ -64,9 +64,7 @@ pub struct ManualIsAsciiCheck { impl ManualIsAsciiCheck { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -91,11 +89,11 @@ enum CharRange { impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !self.msrv.meets(msrvs::IS_ASCII_DIGIT) { + if !self.msrv.meets(cx, msrvs::IS_ASCII_DIGIT) { return; } - if is_in_const_context(cx) && !self.msrv.meets(msrvs::IS_ASCII_DIGIT_CONST) { + if is_in_const_context(cx) && !self.msrv.meets(cx, msrvs::IS_ASCII_DIGIT_CONST) { return; } @@ -119,8 +117,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck { check_is_ascii(cx, expr.span, arg, &range, ty_sugg); } } - - extract_msrv_attr!(LateContext); } fn get_ty_sugg(cx: &LateContext<'_>, arg: &Expr<'_>, bound_expr: &Expr<'_>) -> Option<(Span, &'static str)> { diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index a70955a7c78d..c62becfbb820 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -54,7 +54,7 @@ impl<'tcx> QuestionMark { && local.ty.is_none() && init.span.eq_ctxt(stmt.span) && let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) - && self.msrv.meets(msrvs::LET_ELSE) + && self.msrv.meets(cx, msrvs::LET_ELSE) && !in_external_macro(cx.sess(), stmt.span) { match if_let_or_match { diff --git a/clippy_lints/src/manual_main_separator_str.rs b/clippy_lints/src/manual_main_separator_str.rs index b7563a2508d0..4ee335cd77a7 100644 --- a/clippy_lints/src/manual_main_separator_str.rs +++ b/clippy_lints/src/manual_main_separator_str.rs @@ -39,9 +39,7 @@ pub struct ManualMainSeparatorStr { impl ManualMainSeparatorStr { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -55,7 +53,7 @@ impl LateLintPass<'_> for ManualMainSeparatorStr { && let ExprKind::Path(QPath::Resolved(None, path)) = receiver.kind && let Res::Def(DefKind::Const, receiver_def_id) = path.res && is_trait_method(cx, target, sym::ToString) - && self.msrv.meets(msrvs::PATH_MAIN_SEPARATOR_STR) + && self.msrv.meets(cx, msrvs::PATH_MAIN_SEPARATOR_STR) && cx.tcx.is_diagnostic_item(sym::path_main_separator, receiver_def_id) && let ty::Ref(_, ty, Mutability::Not) = cx.typeck_results().expr_ty_adjusted(expr).kind() && ty.is_str() @@ -71,6 +69,4 @@ impl LateLintPass<'_> for ManualMainSeparatorStr { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 00800231fe46..c43cfb790590 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -71,7 +71,7 @@ pub struct ManualNonExhaustive { impl ManualNonExhaustive { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, constructed_enum_variants: FxHashSet::default(), potential_enums: Vec::new(), } @@ -82,7 +82,7 @@ impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]); impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if !self.msrv.meets(msrvs::NON_EXHAUSTIVE) || !cx.effective_visibilities.is_exported(item.owner_id.def_id) { + if !self.msrv.meets(cx, msrvs::NON_EXHAUSTIVE) || !cx.effective_visibilities.is_exported(item.owner_id.def_id) { return; } @@ -171,6 +171,4 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 5e58054a9866..8947f0e5bd68 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -40,9 +40,7 @@ pub struct ManualRemEuclid { impl ManualRemEuclid { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -61,8 +59,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && add_lhs.span.ctxt() == ctxt && add_rhs.span.ctxt() == ctxt && !in_external_macro(cx.sess(), expr.span) - && self.msrv.meets(msrvs::REM_EUCLID) - && (self.msrv.meets(msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx)) + && self.msrv.meets(cx, msrvs::REM_EUCLID) + && (self.msrv.meets(cx, msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx)) && let Some(const1) = check_for_unsigned_int_constant(cx, rem_rhs) && let Some((const2, add_other)) = check_for_either_unsigned_int_constant(cx, add_lhs, add_rhs) && let ExprKind::Binary(rem2_op, rem2_lhs, rem2_rhs) = add_other.kind @@ -100,8 +98,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { ); } } - - extract_msrv_attr!(LateContext); } // Checks if either the left or right expressions can be an unsigned int constant and returns that diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 708980ac503d..b280e13a42c1 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -50,9 +50,7 @@ pub struct ManualRetain { impl ManualRetain { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -66,13 +64,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualRetain { && let Some(collect_def_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id) && cx.tcx.is_diagnostic_item(sym::iterator_collect_fn, collect_def_id) { - check_into_iter(cx, left_expr, target_expr, expr.span, &self.msrv); - check_iter(cx, left_expr, target_expr, expr.span, &self.msrv); - check_to_owned(cx, left_expr, target_expr, expr.span, &self.msrv); + check_into_iter(cx, left_expr, target_expr, expr.span, self.msrv); + check_iter(cx, left_expr, target_expr, expr.span, self.msrv); + check_to_owned(cx, left_expr, target_expr, expr.span, self.msrv); } } - - extract_msrv_attr!(LateContext); } fn check_into_iter( @@ -80,7 +76,7 @@ fn check_into_iter( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if let hir::ExprKind::MethodCall(_, into_iter_expr, [_], _) = &target_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) @@ -123,7 +119,7 @@ fn check_iter( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(copied_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) @@ -181,9 +177,9 @@ fn check_to_owned( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::STRING_RETAIN) + if msrv.meets(cx, msrvs::STRING_RETAIN) && let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(to_owned_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) && cx.tcx.is_diagnostic_item(sym::to_owned_method, to_owned_def_id) @@ -253,7 +249,7 @@ fn match_acceptable_sym(cx: &LateContext<'_>, collect_def_id: DefId) -> bool { .any(|&method| cx.tcx.is_diagnostic_item(method, collect_def_id)) } -fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: &Msrv) -> bool { +fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: Msrv) -> bool { let ty = cx.typeck_results().expr_ty(expr).peel_refs(); let required = match get_type_diagnostic_name(cx, ty) { Some(sym::BinaryHeap) => msrvs::BINARY_HEAP_RETAIN, @@ -264,7 +260,7 @@ fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: &Msrv Some(sym::Vec | sym::VecDeque) => return true, _ => return false, }; - msrv.meets(required) + msrv.meets(cx, required) } fn match_map_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 79de41db3438..d8e0bdea933b 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -54,9 +54,7 @@ pub struct ManualStrip { impl ManualStrip { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -73,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr) && let ExprKind::MethodCall(_, target_arg, [pattern], _) = cond.kind && let ExprKind::Path(target_path) = &target_arg.kind - && self.msrv.meets(msrvs::STR_STRIP_PREFIX) + && self.msrv.meets(cx, msrvs::STR_STRIP_PREFIX) && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id) { let strip_kind = if cx.tcx.is_diagnostic_item(sym::str_starts_with, method_def_id) { @@ -129,8 +127,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } } } - - extract_msrv_attr!(LateContext); } // Returns `Some(arg)` if `expr` matches `arg.len()` and `None` otherwise. diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs index 99a7b8c74be8..f043be504957 100644 --- a/clippy_lints/src/matches/collapsible_match.rs +++ b/clippy_lints/src/matches/collapsible_match.rs @@ -14,7 +14,7 @@ use rustc_span::Span; use super::{COLLAPSIBLE_MATCH, pat_contains_disallowed_or}; -pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], msrv: &Msrv) { +pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], msrv: Msrv) { if let Some(els_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) { for arm in arms { check_arm(cx, true, arm.pat, arm.body, arm.guard, Some(els_arm.body), msrv); @@ -27,7 +27,7 @@ pub(super) fn check_if_let<'tcx>( pat: &'tcx Pat<'_>, body: &'tcx Expr<'_>, else_expr: Option<&'tcx Expr<'_>>, - msrv: &Msrv, + msrv: Msrv, ) { check_arm(cx, false, pat, body, None, else_expr, msrv); } @@ -39,7 +39,7 @@ fn check_arm<'tcx>( outer_then_body: &'tcx Expr<'tcx>, outer_guard: Option<&'tcx Expr<'tcx>>, outer_else_body: Option<&'tcx Expr<'tcx>>, - msrv: &Msrv, + msrv: Msrv, ) { let inner_expr = peel_blocks_with_stmt(outer_then_body); if let Some(inner) = IfLetOrMatch::parse(cx, inner_expr) @@ -60,7 +60,7 @@ fn check_arm<'tcx>( // match expression must be a local binding // match { .. } && let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_scrutinee)) - && !pat_contains_disallowed_or(inner_then_pat, msrv) + && !pat_contains_disallowed_or(cx, inner_then_pat, msrv) // the binding must come from the pattern of the containing match arm // .... => match { .. } && let (Some(binding_span), is_innermost_parent_pat_struct) diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 64969271764c..ce401dc52b3a 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -983,7 +983,7 @@ pub struct Matches { impl Matches { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, infallible_destructuring_match_linted: false, } } @@ -1041,7 +1041,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { significant_drop_in_scrutinee::check_match(cx, expr, ex, arms, source); } - collapsible_match::check_match(cx, arms, &self.msrv); + collapsible_match::check_match(cx, arms, self.msrv); if !from_expansion { // These don't depend on a relationship between multiple arms match_wild_err_arm::check(cx, ex, arms); @@ -1054,7 +1054,9 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if !from_expansion && !contains_cfg_arm(cx, expr, ex, arms) { if source == MatchSource::Normal { - if !(self.msrv.meets(msrvs::MATCHES_MACRO) && match_like_matches::check_match(cx, expr, ex, arms)) { + if !(self.msrv.meets(cx, msrvs::MATCHES_MACRO) + && match_like_matches::check_match(cx, expr, ex, arms)) + { match_same_arms::check(cx, arms); } @@ -1067,7 +1069,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { needless_match::check_match(cx, ex, arms, expr); match_on_vec_items::check(cx, ex); match_str_case_mismatch::check(cx, ex, arms); - redundant_guards::check(cx, arms, &self.msrv); + redundant_guards::check(cx, arms, self.msrv); if !is_in_const_context(cx) { manual_unwrap_or::check_match(cx, expr, ex, arms); @@ -1084,11 +1086,11 @@ impl<'tcx> LateLintPass<'tcx> for Matches { match_ref_pats::check(cx, ex, arms.iter().map(|el| el.pat), expr); } } else if let Some(if_let) = higher::IfLet::hir(cx, expr) { - collapsible_match::check_if_let(cx, if_let.let_pat, if_let.if_then, if_let.if_else, &self.msrv); + collapsible_match::check_if_let(cx, if_let.let_pat, if_let.if_then, if_let.if_else, self.msrv); significant_drop_in_scrutinee::check_if_let(cx, expr, if_let.let_expr, if_let.if_then, if_let.if_else); if !from_expansion { if let Some(else_expr) = if_let.if_else { - if self.msrv.meets(msrvs::MATCHES_MACRO) { + if self.msrv.meets(cx, msrvs::MATCHES_MACRO) { match_like_matches::check_if_let( cx, expr, @@ -1146,8 +1148,6 @@ impl<'tcx> LateLintPass<'tcx> for Matches { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { rest_pat_in_fully_bound_struct::check(cx, pat); } - - extract_msrv_attr!(LateContext); } /// Checks if there are any arms with a `#[cfg(..)]` attribute. @@ -1212,8 +1212,8 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar } /// Checks if `pat` contains OR patterns that cannot be nested due to a too low MSRV. -fn pat_contains_disallowed_or(pat: &Pat<'_>, msrv: &Msrv) -> bool { - if msrv.meets(msrvs::OR_PATTERNS) { +fn pat_contains_disallowed_or(cx: &LateContext<'_>, pat: &Pat<'_>, msrv: Msrv) -> bool { + if msrv.meets(cx, msrvs::OR_PATTERNS) { return false; } diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index dfc0513add93..ab53ad98572e 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -16,7 +16,7 @@ use std::ops::ControlFlow; use super::{REDUNDANT_GUARDS, pat_contains_disallowed_or}; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: &Msrv) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: Msrv) { for outer_arm in arms { let Some(guard) = outer_arm.guard else { continue; @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: if let ExprKind::Match(scrutinee, [arm, _], MatchSource::Normal) = guard.kind && matching_root_macro_call(cx, guard.span, sym::matches_macro).is_some() && let Some(binding) = get_pat_binding(cx, scrutinee, outer_arm) - && !pat_contains_disallowed_or(arm.pat, msrv) + && !pat_contains_disallowed_or(cx, arm.pat, msrv) { let pat_span = match (arm.pat.kind, binding.byref_ident) { (PatKind::Ref(pat, _), Some(_)) => pat.span, @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: // `Some(x) if let Some(2) = x` else if let ExprKind::Let(let_expr) = guard.kind && let Some(binding) = get_pat_binding(cx, let_expr.init, outer_arm) - && !pat_contains_disallowed_or(let_expr.pat, msrv) + && !pat_contains_disallowed_or(cx, let_expr.pat, msrv) { let pat_span = match (let_expr.pat.kind, binding.byref_ident) { (PatKind::Ref(pat, _), Some(_)) => pat.span, diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 5597cd85abc9..2483d1b50af5 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -219,9 +219,7 @@ pub struct MemReplace { impl MemReplace { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -236,11 +234,10 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace { // Check that second argument is `Option::None` if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) { check_replace_option_with_none(cx, dest, expr.span); - } else if self.msrv.meets(msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) { + } else if self.msrv.meets(cx, msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) { check_replace_with_default(cx, src, dest, expr.span); } check_replace_with_uninit(cx, src, dest, expr.span); } } - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index 2a0a9d3710dc..6d4b2d0350b1 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -10,16 +10,16 @@ use rustc_span::{Span, sym}; use super::CLONED_INSTEAD_OF_COPIED; -pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: &Msrv) { +pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Msrv) { let recv_ty = cx.typeck_results().expr_ty_adjusted(recv); let inner_ty = match recv_ty.kind() { // `Option` -> `T` ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && msrv.meets(msrvs::OPTION_COPIED) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && msrv.meets(cx, msrvs::OPTION_COPIED) => { subst.type_at(0) }, - _ if is_trait_method(cx, expr, sym::Iterator) && msrv.meets(msrvs::ITERATOR_COPIED) => { + _ if is_trait_method(cx, expr, sym::Iterator) && msrv.meets(cx, msrvs::ITERATOR_COPIED) => { match get_iterator_item_ty(cx, recv_ty) { // ::Item Some(ty) => ty, diff --git a/clippy_lints/src/methods/err_expect.rs b/clippy_lints/src/methods/err_expect.rs index 44b55570eead..08f22a1c5625 100644 --- a/clippy_lints/src/methods/err_expect.rs +++ b/clippy_lints/src/methods/err_expect.rs @@ -14,12 +14,12 @@ pub(super) fn check( recv: &rustc_hir::Expr<'_>, expect_span: Span, err_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) // Test the version to make sure the lint can be showed (expect_err has been // introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982) - && msrv.meets(msrvs::EXPECT_ERR) + && msrv.meets(cx, msrvs::EXPECT_ERR) // Grabs the `Result` type && let result_type = cx.typeck_results().expr_ty(recv) diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 3f89e5931487..9f3c346042ff 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -14,10 +14,10 @@ pub(super) fn check<'tcx>( expr: &'tcx hir::Expr<'_>, recv: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { if is_trait_method(cx, expr, sym::Iterator) { - if !msrv.meets(msrvs::ITERATOR_FIND_MAP) { + if !msrv.meets(cx, msrvs::ITERATOR_FIND_MAP) { return; } diff --git a/clippy_lints/src/methods/is_digit_ascii_radix.rs b/clippy_lints/src/methods/is_digit_ascii_radix.rs index d8bb9e377a0c..36830cd5ee36 100644 --- a/clippy_lints/src/methods/is_digit_ascii_radix.rs +++ b/clippy_lints/src/methods/is_digit_ascii_radix.rs @@ -12,9 +12,9 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'_>, self_arg: &'tcx Expr<'_>, radix: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if !msrv.meets(msrvs::IS_ASCII_DIGIT) { + if !msrv.meets(cx, msrvs::IS_ASCII_DIGIT) { return; } diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 299f6d101123..04477364691e 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -20,9 +20,9 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'tcx>, // .iter().map(|(_, v_| v)) recv: &'tcx Expr<'tcx>, // hashmap m_arg: &'tcx Expr<'tcx>, // |(_, v)| v - msrv: &Msrv, + msrv: Msrv, ) { - if map_type == "into_iter" && !msrv.meets(msrvs::INTO_KEYS) { + if map_type == "into_iter" && !msrv.meets(cx, msrvs::INTO_KEYS) { return; } if !expr.span.from_expansion() diff --git a/clippy_lints/src/methods/manual_c_str_literals.rs b/clippy_lints/src/methods/manual_c_str_literals.rs index 7d5ebdedd0c3..4d14a1f3b6fe 100644 --- a/clippy_lints/src/methods/manual_c_str_literals.rs +++ b/clippy_lints/src/methods/manual_c_str_literals.rs @@ -22,7 +22,7 @@ pub(super) fn check_as_ptr<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, receiver: &'tcx Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { if let ExprKind::Lit(lit) = receiver.kind && let LitKind::ByteStr(_, StrStyle::Cooked) | LitKind::Str(_, StrStyle::Cooked) = lit.node @@ -32,7 +32,7 @@ pub(super) fn check_as_ptr<'tcx>( |parent| matches!(parent.kind, ExprKind::Call(func, _) if is_c_str_function(cx, func).is_some()), ) && let Some(sugg) = rewrite_as_cstr(cx, lit.span) - && msrv.meets(msrvs::C_STR_LITERALS) + && msrv.meets(cx, msrvs::C_STR_LITERALS) { span_lint_and_sugg( cx, @@ -65,11 +65,11 @@ fn is_c_str_function(cx: &LateContext<'_>, func: &Expr<'_>) -> Option { /// - `CStr::from_bytes_with_nul(..)` /// - `CStr::from_bytes_with_nul_unchecked(..)` /// - `CStr::from_ptr(..)` -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args: &[Expr<'_>], msrv: &Msrv) { +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args: &[Expr<'_>], msrv: Msrv) { if let Some(fn_name) = is_c_str_function(cx, func) && let [arg] = args && cx.tcx.sess.edition() >= Edition2021 - && msrv.meets(msrvs::C_STR_LITERALS) + && msrv.meets(cx, msrvs::C_STR_LITERALS) { match fn_name.as_str() { name @ ("from_bytes_with_nul" | "from_bytes_with_nul_unchecked") diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index 865a42b65c62..0bd2b6a2ca3d 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -14,13 +14,13 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym}; use super::MANUAL_INSPECT; #[expect(clippy::too_many_lines)] -pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: &str, name_span: Span, msrv: &Msrv) { +pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: &str, name_span: Span, msrv: Msrv) { if let ExprKind::Closure(c) = arg.kind && matches!(c.kind, ClosureKind::Closure) && let typeck = cx.typeck_results() && let Some(fn_id) = typeck.type_dependent_def_id(expr.hir_id) && (is_diag_trait_item(cx, fn_id, sym::Iterator) - || (msrv.meets(msrvs::OPTION_RESULT_INSPECT) + || (msrv.meets(cx, msrvs::OPTION_RESULT_INSPECT) && (is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result)))) && let body = cx.tcx.hir().body(c.body) && let [param] = body.params diff --git a/clippy_lints/src/methods/manual_is_variant_and.rs b/clippy_lints/src/methods/manual_is_variant_and.rs index 90e502f244fa..40aad03960c4 100644 --- a/clippy_lints/src/methods/manual_is_variant_and.rs +++ b/clippy_lints/src/methods/manual_is_variant_and.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>( map_recv: &'tcx rustc_hir::Expr<'_>, map_arg: &'tcx rustc_hir::Expr<'_>, map_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { // Don't lint if: @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>( } // 4. msrv doesn't meet `OPTION_RESULT_IS_VARIANT_AND` - if !msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) { + if !msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) { return; } diff --git a/clippy_lints/src/methods/manual_try_fold.rs b/clippy_lints/src/methods/manual_try_fold.rs index 4a48d4b547cc..fce237d74d9c 100644 --- a/clippy_lints/src/methods/manual_try_fold.rs +++ b/clippy_lints/src/methods/manual_try_fold.rs @@ -18,10 +18,10 @@ pub(super) fn check<'tcx>( init: &Expr<'_>, acc: &Expr<'_>, fold_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if !in_external_macro(cx.sess(), fold_span) - && msrv.meets(msrvs::ITERATOR_TRY_FOLD) + && msrv.meets(cx, msrvs::ITERATOR_TRY_FOLD) && is_trait_method(cx, expr, sym::Iterator) && let init_ty = cx.typeck_results().expr_ty(init) && let Some(try_trait) = cx.tcx.lang_items().try_trait() diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 1252f7ccd357..c735aca0c9bc 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -41,7 +41,7 @@ fn should_run_lint(cx: &LateContext<'_>, e: &hir::Expr<'_>, method_id: DefId) -> true } -pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, msrv: &Msrv) { +pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, msrv: Msrv) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && should_run_lint(cx, e, method_id) { @@ -169,10 +169,10 @@ fn lint_path(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool) { ); } -fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool, msrv: &Msrv) { +fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool, msrv: Msrv) { let mut applicability = Applicability::MachineApplicable; - let (message, sugg_method) = if is_copy && msrv.meets(msrvs::ITERATOR_COPIED) { + let (message, sugg_method) = if is_copy && msrv.meets(cx, msrvs::ITERATOR_COPIED) { ("you are using an explicit closure for copying elements", "copied") } else { ("you are using an explicit closure for cloning elements", "cloned") diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 428da0cf107e..df5a0de3392b 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -19,13 +19,13 @@ pub(super) fn check<'tcx>( recv: &'tcx hir::Expr<'_>, map_arg: &'tcx hir::Expr<'_>, unwrap_arg: &'tcx hir::Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { // lint if the caller of `map()` is an `Option` or a `Result`. let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); - if is_result && !msrv.meets(msrvs::RESULT_MAP_OR_ELSE) { + if is_result && !msrv.meets(cx, msrvs::RESULT_MAP_OR_ELSE) { return false; } diff --git a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs index 1ebb71e251ab..5ee2f0fc212b 100644 --- a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs +++ b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs @@ -62,7 +62,7 @@ pub(super) fn check( ex: &Expr<'_>, receiver: &Expr<'_>, arg: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, method_call_span: Span, ) { let mut applicability = Applicability::MaybeIncorrect; @@ -81,7 +81,7 @@ pub(super) fn check( let use_take; if eager_or_lazy::switch_to_eager_eval(cx, body_expr) { - if msrv.meets(msrvs::REPEAT_N) { + if msrv.meets(cx, msrvs::REPEAT_N) { method_to_use_name = "repeat_n"; let body_snippet = snippet_with_applicability(cx, body_expr.span, "..", &mut applicability); new_span = (arg.span, format!("{body_snippet}, {count}")); @@ -92,7 +92,7 @@ pub(super) fn check( new_span = (arg.span, body_snippet.to_string()); use_take = true; } - } else if msrv.meets(msrvs::REPEAT_WITH) { + } else if msrv.meets(cx, msrvs::REPEAT_WITH) { method_to_use_name = "repeat_with"; new_span = (param.span, String::new()); use_take = true; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 810287fa5416..78ce2029fd61 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4300,7 +4300,7 @@ impl Methods { Self { avoid_breaking_exported_api: conf.avoid_breaking_exported_api, - msrv: conf.msrv.clone(), + msrv: conf.msrv, allow_expect_in_tests: conf.allow_expect_in_tests, allow_unwrap_in_tests: conf.allow_unwrap_in_tests, allowed_dotfiles, @@ -4476,7 +4476,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { ExprKind::Call(func, args) => { from_iter_instead_of_collect::check(cx, expr, args, func); unnecessary_fallible_conversions::check_function(cx, expr, func); - manual_c_str_literals::check(cx, expr, func, args, &self.msrv); + manual_c_str_literals::check(cx, expr, func, args, self.msrv); }, ExprKind::MethodCall(method_call, receiver, args, _) => { let method_span = method_call.ident.span; @@ -4495,7 +4495,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { inefficient_to_string::check(cx, expr, method_call.ident.name, receiver, args); single_char_add_str::check(cx, expr, receiver, args); into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, receiver); - unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, &self.msrv); + unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, self.msrv); }, ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => { let mut info = BinaryExprInfo { @@ -4641,8 +4641,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods { ); } } - - extract_msrv_attr!(LateContext); } impl Methods { @@ -4697,7 +4695,7 @@ impl Methods { && let body = cx.tcx.hir().body(arg.body) && let [param] = body.params => { - string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); + string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), self.msrv); }, Some(("map", _, [map_arg], _, map_call_span)) => { map_all_any_identity::check(cx, expr, recv, map_call_span, map_arg, call_span, arg, "any"); @@ -4717,11 +4715,11 @@ impl Methods { } }, ("as_mut", []) => useless_asref::check(cx, expr, "as_mut", recv), - ("as_ptr", []) => manual_c_str_literals::check_as_ptr(cx, expr, recv, &self.msrv), + ("as_ptr", []) => manual_c_str_literals::check_as_ptr(cx, expr, recv, self.msrv), ("as_ref", []) => useless_asref::check(cx, expr, "as_ref", recv), ("assume_init", []) => uninit_assumed_init::check(cx, expr, recv), ("cloned", []) => { - cloned_instead_of_copied::check(cx, expr, recv, span, &self.msrv); + cloned_instead_of_copied::check(cx, expr, recv, span, self.msrv); option_as_ref_cloned::check(cx, recv, span); }, ("collect", []) if is_trait_method(cx, expr, sym::Iterator) => { @@ -4735,7 +4733,7 @@ impl Methods { format_collect::check(cx, expr, m_arg, m_ident_span); }, Some(("take", take_self_arg, [take_arg], _, _)) => { - if self.msrv.meets(msrvs::STR_REPEAT) { + if self.msrv.meets(cx, msrvs::STR_REPEAT) { manual_str_repeat::check(cx, expr, recv, take_self_arg, take_arg); } }, @@ -4774,13 +4772,13 @@ impl Methods { if let ExprKind::MethodCall(.., span) = expr.kind { case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg); } - path_ends_with_ext::check(cx, recv, arg, expr, &self.msrv, &self.allowed_dotfiles); + path_ends_with_ext::check(cx, recv, arg, expr, self.msrv, &self.allowed_dotfiles); }, ("expect", [_]) => { match method_call(recv) { Some(("ok", recv, [], _, _)) => ok_expect::check(cx, expr, recv), Some(("err", recv, [], err_span, _)) => { - err_expect::check(cx, expr, recv, span, err_span, &self.msrv); + err_expect::check(cx, expr, recv, span, err_span, self.msrv); }, _ => unwrap_expect_used::check( cx, @@ -4820,7 +4818,7 @@ impl Methods { false, ); } - if self.msrv.meets(msrvs::ITER_FLATTEN) { + if self.msrv.meets(cx, msrvs::ITER_FLATTEN) { // use the sourcemap to get the span of the closure iter_filter::check(cx, expr, arg, span); } @@ -4868,7 +4866,7 @@ impl Methods { _ => {}, }, ("fold", [init, acc]) => { - manual_try_fold::check(cx, expr, init, acc, call_span, &self.msrv); + manual_try_fold::check(cx, expr, init, acc, call_span, self.msrv); unnecessary_fold::check(cx, expr, init, acc, span); }, ("for_each", [arg]) => { @@ -4907,7 +4905,7 @@ impl Methods { is_empty::check(cx, expr, recv); }, ("is_file", []) => filetype_is_file::check(cx, expr, recv), - ("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, &self.msrv), + ("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv), ("is_none", []) => check_is_some_is_none(cx, expr, recv, call_span, false), ("is_some", []) => check_is_some_is_none(cx, expr, recv, call_span, true), ("iter" | "iter_mut" | "into_iter", []) => { @@ -4943,11 +4941,11 @@ impl Methods { (name @ ("map" | "map_err"), [m_arg]) => { if name == "map" { unused_enumerate_index::check(cx, expr, recv, m_arg); - map_clone::check(cx, expr, recv, m_arg, &self.msrv); - map_with_unused_argument_over_ranges::check(cx, expr, recv, m_arg, &self.msrv, span); + map_clone::check(cx, expr, recv, m_arg, self.msrv); + map_with_unused_argument_over_ranges::check(cx, expr, recv, m_arg, self.msrv, span); match method_call(recv) { Some((map_name @ ("iter" | "into_iter"), recv2, _, _, _)) => { - iter_kv_map::check(cx, map_name, expr, recv2, m_arg, &self.msrv); + iter_kv_map::check(cx, map_name, expr, recv2, m_arg, self.msrv); }, Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( cx, @@ -4964,8 +4962,8 @@ impl Methods { } if let Some((name, recv2, args, span2, _)) = method_call(recv) { match (name, args) { - ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, &self.msrv), - ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, &self.msrv), + ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, self.msrv), + ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, self.msrv), ("filter", [f_arg]) => { filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false); }, @@ -4976,7 +4974,7 @@ impl Methods { } } map_identity::check(cx, expr, recv, m_arg, name, span); - manual_inspect::check(cx, expr, m_arg, name, span, &self.msrv); + manual_inspect::check(cx, expr, m_arg, name, span, self.msrv); crate::useless_conversion::check_function_application(cx, expr, recv, m_arg); }, ("map_break" | "map_continue", [m_arg]) => { @@ -4986,7 +4984,7 @@ impl Methods { option_map_or_none::check(cx, expr, recv, def, map); manual_ok_or::check(cx, expr, recv, def, map); option_map_or_err_ok::check(cx, expr, recv, def, map); - unnecessary_map_or::check(cx, expr, recv, def, map, &self.msrv); + unnecessary_map_or::check(cx, expr, recv, def, map, self.msrv); }, ("map_or_else", [def, map]) => { result_map_or_else_none::check(cx, expr, recv, def, map); @@ -5004,7 +5002,7 @@ impl Methods { false, ), ("filter", [arg]) => filter_next::check(cx, expr, recv2, arg), - ("filter_map", [arg]) => filter_map_next::check(cx, expr, recv2, arg, &self.msrv), + ("filter_map", [arg]) => filter_map_next::check(cx, expr, recv2, arg, self.msrv), ("iter", []) => iter_next_slice::check(cx, expr, recv2), ("skip", [arg]) => iter_skip_next::check(cx, expr, recv2, arg), ("skip_while", [_]) => skip_while_next::check(cx, expr), @@ -5058,7 +5056,7 @@ impl Methods { no_effect_replace::check(cx, expr, arg1, arg2); // Check for repeated `str::replace` calls to perform `collapsible_str_replace` lint - if self.msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) + if self.msrv.meets(cx, msrvs::PATTERN_TRAIT_CHAR_ARRAY) && name == "replace" && let Some(("replace", ..)) = method_call(recv) { @@ -5069,10 +5067,10 @@ impl Methods { vec_resize_to_zero::check(cx, expr, count_arg, default_arg, span); }, ("seek", [arg]) => { - if self.msrv.meets(msrvs::SEEK_FROM_CURRENT) { + if self.msrv.meets(cx, msrvs::SEEK_FROM_CURRENT) { seek_from_current::check(cx, expr, recv, arg); } - if self.msrv.meets(msrvs::SEEK_REWIND) { + if self.msrv.meets(cx, msrvs::SEEK_REWIND) { seek_to_start_instead_of_rewind::check(cx, expr, recv, arg, span); } }, @@ -5106,7 +5104,7 @@ impl Methods { ("splitn" | "rsplitn", [count_arg, pat_arg]) => { if let Some(Constant::Int(count)) = ConstEvalCtxt::new(cx).eval(count_arg) { suspicious_splitn::check(cx, name, expr, recv, count); - str_splitn::check(cx, name, expr, recv, pat_arg, count, &self.msrv); + str_splitn::check(cx, name, expr, recv, pat_arg, count, self.msrv); } }, ("splitn_mut" | "rsplitn_mut", [count_arg, _]) => { @@ -5130,7 +5128,7 @@ impl Methods { }, ("take", []) => needless_option_take::check(cx, expr, recv), ("then", [arg]) => { - if !self.msrv.meets(msrvs::BOOL_THEN_SOME) { + if !self.msrv.meets(cx, msrvs::BOOL_THEN_SOME) { return; } unnecessary_lazy_eval::check(cx, expr, recv, arg, "then_some"); @@ -5189,7 +5187,7 @@ impl Methods { manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]); }, Some(("map", m_recv, [m_arg], span, _)) => { - option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, &self.msrv); + option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, self.msrv); }, Some(("then_some", t_recv, [t_arg], _, _)) => { obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg); @@ -5200,7 +5198,7 @@ impl Methods { }, ("unwrap_or_default", []) => { if let Some(("map", m_recv, [arg], span, _)) = method_call(recv) { - manual_is_variant_and::check(cx, expr, m_recv, arg, span, &self.msrv); + manual_is_variant_and::check(cx, expr, m_recv, arg, span, self.msrv); } unnecessary_literal_unwrap::check(cx, expr, recv, name, args); }, @@ -5210,7 +5208,7 @@ impl Methods { ("unwrap_or_else", [u_arg]) => { match method_call(recv) { Some(("map", recv, [map_arg], _, _)) - if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {}, + if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, self.msrv) => {}, _ => { unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or"); }, diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 8d97d1c72a6b..5f144fc28f11 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -18,9 +18,9 @@ pub(super) fn check( as_ref_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>, is_mut: bool, - msrv: &Msrv, + msrv: Msrv, ) { - if !msrv.meets(msrvs::OPTION_AS_DEREF) { + if !msrv.meets(cx, msrvs::OPTION_AS_DEREF) { return; } diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 7c4dc4ffb202..e10f8ac40e61 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( unwrap_recv: &rustc_hir::Expr<'_>, unwrap_arg: &'tcx rustc_hir::Expr<'_>, map_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { // lint if the caller of `map()` is an `Option` if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) { @@ -72,7 +72,7 @@ pub(super) fn check<'tcx>( } // is_some_and is stabilised && `unwrap_or` argument is false; suggest `is_some_and` instead - let suggest_is_some_and = msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) + let suggest_is_some_and = msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) && matches!(&unwrap_arg.kind, ExprKind::Lit(lit) if matches!(lit.node, rustc_ast::LitKind::Bool(false))); diff --git a/clippy_lints/src/methods/path_ends_with_ext.rs b/clippy_lints/src/methods/path_ends_with_ext.rs index febd7fd5cf2f..470550b779a2 100644 --- a/clippy_lints/src/methods/path_ends_with_ext.rs +++ b/clippy_lints/src/methods/path_ends_with_ext.rs @@ -20,7 +20,7 @@ pub(super) fn check( recv: &Expr<'_>, path: &Expr<'_>, expr: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, allowed_dotfiles: &FxHashSet<&'static str>, ) { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv).peel_refs(), sym::Path) @@ -33,7 +33,7 @@ pub(super) fn check( && path.chars().all(char::is_alphanumeric) { let mut sugg = snippet(cx, recv.span, "..").into_owned(); - if msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) { + if msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) { let _ = write!(sugg, r#".extension().is_some_and(|ext| ext == "{path}")"#); } else { let _ = write!(sugg, r#".extension().map_or(false, |ext| ext == "{path}")"#); diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index c6d4ef5911ee..41034e9e8c6a 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -23,7 +23,7 @@ pub(super) fn check( self_arg: &Expr<'_>, pat_arg: &Expr<'_>, count: u128, - msrv: &Msrv, + msrv: Msrv, ) { if count < 2 || !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_str() { return; @@ -33,7 +33,7 @@ pub(super) fn check( IterUsageKind::Nth(n) => count > n + 1, IterUsageKind::NextTuple => count > 2, }; - let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE); + let manual = count == 2 && msrv.meets(cx, msrvs::STR_SPLIT_ONCE); match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) { Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg), diff --git a/clippy_lints/src/methods/string_lit_chars_any.rs b/clippy_lints/src/methods/string_lit_chars_any.rs index cb719b34b1f0..ec0214842bac 100644 --- a/clippy_lints/src/methods/string_lit_chars_any.rs +++ b/clippy_lints/src/methods/string_lit_chars_any.rs @@ -17,9 +17,9 @@ pub(super) fn check<'tcx>( recv: &Expr<'_>, param: &'tcx Param<'tcx>, body: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::MATCHES_MACRO) + if msrv.meets(cx, msrvs::MATCHES_MACRO) && is_trait_method(cx, expr, sym::Iterator) && let PatKind::Binding(_, arg, _, _) = param.pat.kind && let ExprKind::Lit(lit_kind) = recv.kind diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index 1199d2897610..508df28db8e0 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -42,7 +42,7 @@ pub(super) fn check<'a>( recv: &Expr<'_>, def: &Expr<'_>, map: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { let ExprKind::Lit(def_kind) = def.kind else { return; @@ -102,7 +102,7 @@ pub(super) fn check<'a>( (binop, "a standard comparison", Applicability::MaybeIncorrect) } else if !def_bool - && msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) + && msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) && let Some(recv_callsite) = snippet_opt(cx, recv.span.source_callsite()) && let Some(span_callsite) = snippet_opt(cx, map.span.source_callsite()) { @@ -114,7 +114,7 @@ pub(super) fn check<'a>( ) } else if def_bool && matches!(variant, Variant::Some) - && msrv.meets(msrvs::IS_NONE_OR) + && msrv.meets(cx, msrvs::IS_NONE_OR) && let Some(recv_callsite) = snippet_opt(cx, recv.span.source_callsite()) && let Some(span_callsite) = snippet_opt(cx, map.span.source_callsite()) { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index d19064fd57e3..ba6cdf119576 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -31,7 +31,7 @@ pub fn check<'tcx>( method_name: Symbol, receiver: &'tcx Expr<'_>, args: &'tcx [Expr<'_>], - msrv: &Msrv, + msrv: Msrv, ) { if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && args.is_empty() @@ -207,7 +207,7 @@ fn check_into_iter_call_arg( expr: &Expr<'_>, method_name: Symbol, receiver: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { if let Some(parent) = get_parent_expr(cx, expr) && let Some(callee_def_id) = fn_def_id(cx, parent) @@ -221,7 +221,7 @@ fn check_into_iter_call_arg( if unnecessary_iter_cloned::check_for_loop_iter(cx, parent, method_name, receiver, true) { return true; } - let cloned_or_copied = if is_copy(cx, item_ty) && msrv.meets(msrvs::ITERATOR_COPIED) { + let cloned_or_copied = if is_copy(cx, item_ty) && msrv.meets(cx, msrvs::ITERATOR_COPIED) { "copied" } else { "cloned" diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 121c4326d648..4f6b410a0083 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -81,9 +81,7 @@ pub struct MissingConstForFn { impl MissingConstForFn { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -97,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { span: Span, def_id: LocalDefId, ) { - if !self.msrv.meets(msrvs::CONST_IF_MATCH) { + if !self.msrv.meets(cx, msrvs::CONST_IF_MATCH) { return; } @@ -119,7 +117,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { .iter() .any(|param| matches!(param.kind, GenericParamKind::Const { .. })); - if already_const(header) || has_const_generic_params || !could_be_const_with_abi(&self.msrv, header.abi) + if already_const(header) + || has_const_generic_params + || !could_be_const_with_abi(cx, self.msrv, header.abi) { return; } @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { let mir = cx.tcx.optimized_mir(def_id); - if let Ok(()) = is_min_const_fn(cx.tcx, mir, &self.msrv) + if let Ok(()) = is_min_const_fn(cx, mir, self.msrv) && let hir::Node::Item(hir::Item { vis_span, .. }) | hir::Node::ImplItem(hir::ImplItem { vis_span, .. }) = cx.tcx.hir_node_by_def_id(def_id) { @@ -171,8 +171,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { }); } } - - extract_msrv_attr!(LateContext); } // We don't have to lint on something that's already `const` @@ -181,13 +179,13 @@ fn already_const(header: hir::FnHeader) -> bool { header.constness == Constness::Const } -fn could_be_const_with_abi(msrv: &Msrv, abi: Abi) -> bool { +fn could_be_const_with_abi(cx: &LateContext<'_>, msrv: Msrv, abi: Abi) -> bool { match abi { Abi::Rust => true, // `const extern "C"` was stabilized after 1.62.0 - Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), + Abi::C { unwind: false } => msrv.meets(cx, msrvs::CONST_EXTERN_C_FN), // Rest ABIs are still unstable and need the `const_extern_fn` feature enabled. - _ => msrv.meets(msrvs::CONST_EXTERN_FN), + _ => msrv.meets(cx, msrvs::CONST_EXTERN_FN), } } diff --git a/clippy_lints/src/missing_const_for_thread_local.rs b/clippy_lints/src/missing_const_for_thread_local.rs index e2ca4458edaa..4912110a03b1 100644 --- a/clippy_lints/src/missing_const_for_thread_local.rs +++ b/clippy_lints/src/missing_const_for_thread_local.rs @@ -49,9 +49,7 @@ pub struct MissingConstForThreadLocal { impl MissingConstForThreadLocal { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -91,11 +89,11 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } #[inline] -fn initializer_can_be_made_const(cx: &LateContext<'_>, defid: rustc_span::def_id::DefId, msrv: &Msrv) -> bool { +fn initializer_can_be_made_const(cx: &LateContext<'_>, defid: rustc_span::def_id::DefId, msrv: Msrv) -> bool { // Building MIR for `fn`s with unsatisfiable preds results in ICE. if !fn_has_unsatisfiable_preds(cx, defid) && let mir = cx.tcx.optimized_mir(defid) - && let Ok(()) = is_min_const_fn(cx.tcx, mir, msrv) + && let Ok(()) = is_min_const_fn(cx, mir, msrv) { return true; } @@ -113,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { local_defid: rustc_span::def_id::LocalDefId, ) { let defid = local_defid.to_def_id(); - if self.msrv.meets(msrvs::THREAD_LOCAL_CONST_INIT) + if self.msrv.meets(cx, msrvs::THREAD_LOCAL_CONST_INIT) && is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false) // Some implementations of `thread_local!` include an initializer fn. // In the case of a const initializer, the init fn is also const, @@ -131,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { // https://github.com/rust-lang/rust-clippy/issues/12637 // we ensure that this is reachable before we check in mir && !is_unreachable(cx, ret_expr) - && initializer_can_be_made_const(cx, defid, &self.msrv) + && initializer_can_be_made_const(cx, defid, self.msrv) // we know that the function is const-qualifiable, so now // we need only to get the initializer expression to span-lint it. && let initializer_snippet = snippet(cx, ret_expr.span, "thread_local! { ... }") @@ -148,6 +146,4 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index f69913ddbfd9..0022ac45c36c 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -72,7 +72,7 @@ impl NeedlessBorrowsForGenericArgs<'_> { pub fn new(conf: &'static Conf) -> Self { Self { possible_borrowers: Vec::new(), - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { i, param_ty, expr, - &self.msrv, + self.msrv, ) && count != 0 { @@ -142,8 +142,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { self.possible_borrowers.pop(); } } - - extract_msrv_attr!(LateContext); } fn path_has_args(p: &QPath<'_>) -> bool { @@ -172,7 +170,7 @@ fn needless_borrow_count<'tcx>( arg_index: usize, param_ty: ParamTy, mut expr: &Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) -> usize { let destruct_trait_def_id = cx.tcx.lang_items().destruct_trait(); let sized_trait_def_id = cx.tcx.lang_items().sized_trait(); @@ -273,7 +271,7 @@ fn needless_borrow_count<'tcx>( && let ty::Param(param_ty) = trait_predicate.self_ty().kind() && let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack() && ty.is_array() - && !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) + && !msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) { return false; } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index d8bff0c62711..340a38bcef98 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -68,7 +68,7 @@ impl_lint_pass!(QuestionMark => [QUESTION_MARK, MANUAL_LET_ELSE]); impl QuestionMark { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, matches_behaviour: conf.matches_for_let_else, try_block_depth_stack: Vec::new(), inferred_ret_closure_stack: 0, @@ -543,5 +543,4 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark { .expect("blocks are always part of bodies and must have a depth") -= 1; } } - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 1b0c0a4956f7..cc423eca74fb 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -166,9 +166,7 @@ pub struct Ranges { impl Ranges { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -182,7 +180,7 @@ impl_lint_pass!(Ranges => [ impl<'tcx> LateLintPass<'tcx> for Ranges { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, l, r) = expr.kind { - if self.msrv.meets(msrvs::RANGE_CONTAINS) { + if self.msrv.meets(cx, msrvs::RANGE_CONTAINS) { check_possible_range_contains(cx, op.node, l, r, expr, expr.span); } } @@ -191,7 +189,6 @@ impl<'tcx> LateLintPass<'tcx> for Ranges { check_inclusive_range_minus_one(cx, expr); check_reversed_empty_range(cx, expr); } - extract_msrv_attr!(LateContext); } fn check_possible_range_contains( diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 347540e7344f..2f1f89039ebb 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; @@ -37,13 +37,13 @@ declare_clippy_lint! { } pub struct RedundantFieldNames { - msrv: Msrv, + msrv: MsrvStack, } impl RedundantFieldNames { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -81,5 +81,5 @@ impl EarlyLintPass for RedundantFieldNames { } } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 06c854338066..b4e1f70d1535 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::source::snippet; use rustc_ast::ast::{ConstItem, Item, ItemKind, StaticItem, Ty, TyKind}; use rustc_errors::Applicability; @@ -35,13 +35,13 @@ declare_clippy_lint! { } pub struct RedundantStaticLifetimes { - msrv: Msrv, + msrv: MsrvStack, } impl RedundantStaticLifetimes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -115,5 +115,5 @@ impl EarlyLintPass for RedundantStaticLifetimes { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs index 2941b9c39607..ec73418492be 100644 --- a/clippy_lints/src/std_instead_of_core.rs +++ b/clippy_lints/src/std_instead_of_core.rs @@ -100,7 +100,7 @@ impl StdReexports { pub fn new(conf: &'static Conf) -> Self { Self { prev_span: Span::default(), - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { fn check_path(&mut self, cx: &LateContext<'tcx>, path: &Path<'tcx>, _: HirId) { if let Res::Def(_, def_id) = path.res && let Some(first_segment) = get_first_segment(path) - && is_stable(cx, def_id, &self.msrv) + && is_stable(cx, def_id, self.msrv) && !in_external_macro(cx.sess(), path.span) && !is_from_proc_macro(cx, &first_segment.ident) { @@ -154,8 +154,6 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { } } } - - extract_msrv_attr!(LateContext); } /// Returns the first named segment of a [`Path`]. @@ -175,7 +173,7 @@ fn get_first_segment<'tcx>(path: &Path<'tcx>) -> Option<&'tcx PathSegment<'tcx>> /// or now stable moves that were once unstable. /// /// Does not catch individually moved items -fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool { +fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: Msrv) -> bool { loop { if let Some(stability) = cx.tcx.lookup_stability(def_id) && let StabilityLevel::Stable { @@ -184,8 +182,8 @@ fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool { } = stability.level { let stable = match since { - StableSince::Version(v) => msrv.meets(v), - StableSince::Current => msrv.current().is_none(), + StableSince::Version(v) => msrv.meets(cx, v), + StableSince::Current => msrv.current(cx).is_none(), StableSince::Err => false, }; diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 0d85b1b858a4..2d3e0d5f04e0 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -77,9 +77,7 @@ pub struct StringPatterns { impl StringPatterns { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -136,7 +134,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio } } -fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) { +fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: Msrv) { if let ExprKind::Closure(closure) = method_arg.kind && let body = cx.tcx.hir().body(closure.body) && let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind) @@ -192,7 +190,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr< { return; } - if set_char_spans.len() > 1 && !msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) { + if set_char_spans.len() > 1 && !msrv.meets(cx, msrvs::PATTERN_TRAIT_CHAR_ARRAY) { return; } span_lint_and_then( @@ -238,9 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for StringPatterns { { check_single_char_pattern_lint(cx, arg); - check_manual_pattern_char_comparison(cx, arg, &self.msrv); + check_manual_pattern_char_comparison(cx, arg, self.msrv); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 99844beb8f00..7fd9e4afe2e6 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -95,7 +95,7 @@ impl TraitBounds { pub fn new(conf: &'static Conf) -> Self { Self { max_trait_bounds: conf.max_trait_bounds, - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -223,15 +223,13 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { } } } - - extract_msrv_attr!(LateContext); } impl TraitBounds { /// Is the given bound a `?Sized` bound, and is combining it (i.e. `T: X + ?Sized`) an error on /// this MSRV? See for details. fn cannot_combine_maybe_bound(&self, cx: &LateContext<'_>, bound: &GenericBound<'_>) -> bool { - if !self.msrv.meets(msrvs::MAYBE_BOUND_IN_WHERE) + if !self.msrv.meets(cx, msrvs::MAYBE_BOUND_IN_WHERE) && let GenericBound::Trait(tr) = bound && let BoundPolarity::Maybe(_) = tr.modifiers.polarity { diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 1cb0f837227d..5ad29bf06d57 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -599,9 +599,7 @@ impl_lint_pass!(Transmute => [ ]); impl Transmute { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } impl<'tcx> LateLintPass<'tcx> for Transmute { @@ -633,16 +631,16 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { | crosspointer_transmute::check(cx, e, from_ty, to_ty) | transmuting_null::check(cx, e, arg, to_ty) | transmute_null_to_fn::check(cx, e, arg, to_ty) - | transmute_ptr_to_ref::check(cx, e, from_ty, to_ty, arg, path, &self.msrv) + | transmute_ptr_to_ref::check(cx, e, from_ty, to_ty, arg, path, self.msrv) | missing_transmute_annotations::check(cx, path, from_ty, to_ty, e.hir_id) | transmute_int_to_char::check(cx, e, from_ty, to_ty, arg, const_context) | transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context) - | transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, &self.msrv) + | transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, self.msrv) | transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg) - | transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) + | transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) | transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg) - | transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) - | transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) + | transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) + | transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) | (unsound_collection_transmute::check(cx, e, from_ty, to_ty) || transmute_undefined_repr::check(cx, e, from_ty, to_ty)) | (eager_transmute::check(cx, e, arg, from_ty, to_ty)); @@ -652,6 +650,4 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { } } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index f0b8abf9af66..f2c757952af3 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -17,11 +17,11 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, mut arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) - if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => + if !const_context || msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) => { span_lint_and_then( cx, diff --git a/clippy_lints/src/transmute/transmute_int_to_float.rs b/clippy_lints/src/transmute/transmute_int_to_float.rs index e5b9aea6423a..aaa95396b4b4 100644 --- a/clippy_lints/src/transmute/transmute_int_to_float.rs +++ b/clippy_lints/src/transmute/transmute_int_to_float.rs @@ -16,10 +16,10 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => { + (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_FLOAT, diff --git a/clippy_lints/src/transmute/transmute_num_to_bytes.rs b/clippy_lints/src/transmute/transmute_num_to_bytes.rs index 6d828bad9b32..d72be270b731 100644 --- a/clippy_lints/src/transmute/transmute_num_to_bytes.rs +++ b/clippy_lints/src/transmute/transmute_num_to_bytes.rs @@ -16,14 +16,15 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => { if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) { return false; } - if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) { + if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) + { return false; } diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index c4a2e20fa9d3..fcc763763bd2 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>( from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (from_ty.kind(), to_ty.kind()) { (ty::RawPtr(from_pointee_ty, from_mutbl), ty::RawPtr(to_pointee_ty, to_mutbl)) => { @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { if from_mutbl == to_mutbl && to_pointee_ty.is_sized(cx.tcx, cx.typing_env()) - && msrv.meets(msrvs::POINTER_CAST) + && msrv.meets(cx, msrvs::POINTER_CAST) { diag.span_suggestion_verbose( e.span, @@ -43,7 +43,7 @@ pub(super) fn check<'tcx>( _ => None, } && !from_pointee_ty.has_erased_regions() - && msrv.meets(msrvs::POINTER_CAST_CONSTNESS) + && msrv.meets(cx, msrvs::POINTER_CAST_CONSTNESS) { diag.span_suggestion_verbose( e.span, diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index ef18633d945f..45ee83c78ab6 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, path: &'tcx Path<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::RawPtr(from_ptr_ty, _), ty::Ref(_, to_ref_ty, mutbl)) => { @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( let sugg = if let Some(ty) = get_explicit_type(path) { let ty_snip = snippet_with_applicability(cx, ty.span, "..", &mut app); - if msrv.meets(msrvs::POINTER_CAST) { + if msrv.meets(cx, msrvs::POINTER_CAST) { format!("{deref}{}.cast::<{ty_snip}>()", arg.maybe_par()) } else if from_ptr_ty.has_erased_regions() { sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {ty_snip}"))).to_string() @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>( } } else if *from_ptr_ty == *to_ref_ty { if from_ptr_ty.has_erased_regions() { - if msrv.meets(msrvs::POINTER_CAST) { + if msrv.meets(cx, msrvs::POINTER_CAST) { format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par()) } else { sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {to_ref_ty}"))) diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 99a55f9fc357..1e769771b815 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -48,15 +48,13 @@ pub struct TupleArrayConversions { } impl TupleArrayConversions { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } impl LateLintPass<'_> for TupleArrayConversions { fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if in_external_macro(cx.sess(), expr.span) || !self.msrv.meets(msrvs::TUPLE_ARRAY_CONVERSIONS) { + if in_external_macro(cx.sess(), expr.span) || !self.msrv.meets(cx, msrvs::TUPLE_ARRAY_CONVERSIONS) { return; } @@ -66,8 +64,6 @@ impl LateLintPass<'_> for TupleArrayConversions { _ => {}, } } - - extract_msrv_attr!(LateContext); } fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: &'tcx [Expr<'tcx>]) { diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 9d26bf930a1a..5dd324275090 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -3,7 +3,7 @@ use clippy_config::Conf; use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_maybe_qself, eq_pat, eq_path}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::over; use rustc_ast::PatKind::*; use rustc_ast::mut_visit::*; @@ -48,13 +48,13 @@ declare_clippy_lint! { } pub struct UnnestedOrPatterns { - msrv: Msrv, + msrv: MsrvStack, } impl UnnestedOrPatterns { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -88,7 +88,7 @@ impl EarlyLintPass for UnnestedOrPatterns { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { diff --git a/clippy_lints/src/unused_trait_names.rs b/clippy_lints/src/unused_trait_names.rs index 17ee5fc20ca2..c9ee3f3fb877 100644 --- a/clippy_lints/src/unused_trait_names.rs +++ b/clippy_lints/src/unused_trait_names.rs @@ -52,9 +52,7 @@ pub struct UnusedTraitNames { impl UnusedTraitNames { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -62,7 +60,7 @@ impl_lint_pass!(UnusedTraitNames => [UNUSED_TRAIT_NAMES]); impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if self.msrv.meets(msrvs::UNDERSCORE_IMPORTS) + if self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS) && !in_external_macro(cx.sess(), item.span) && let ItemKind::Use(path, UseKind::Single) = item.kind // Ignore imports that already use Underscore @@ -89,6 +87,4 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 05c5be030028..ddadeeffd86b 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -63,7 +63,7 @@ pub struct UseSelf { impl UseSelf { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, stack: Vec::new(), } } @@ -203,7 +203,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &Ty<'tcx>) { if !hir_ty.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, in_body, @@ -233,7 +233,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if !expr.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, .. }) = self.stack.last() && cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).instantiate_identity() { @@ -254,7 +254,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { if !pat.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, .. }) = self.stack.last() // get the path from the pattern && let PatKind::Path(QPath::Resolved(_, path)) @@ -265,8 +265,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { check_path(cx, path); } } - - extract_msrv_attr!(LateContext); } #[derive(Default)] diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 686922461530..558acacb9724 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -30,8 +30,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { .tcx .impl_trait_ref(item.owner_id) .map(EarlyBinder::instantiate_identity) - && let is_late_pass = match_def_path(cx, trait_ref.def_id, &paths::LATE_LINT_PASS) - && (is_late_pass || match_def_path(cx, trait_ref.def_id, &paths::EARLY_LINT_PASS)) + && match_def_path(cx, trait_ref.def_id, &paths::EARLY_LINT_PASS) && let ty::Adt(self_ty_def, _) = trait_ref.self_ty().kind() && self_ty_def.is_struct() && self_ty_def.all_fields().any(|f| { @@ -40,20 +39,18 @@ impl LateLintPass<'_> for MsrvAttrImpl { .instantiate_identity() .walk() .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) - .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV)) + .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV_STACK)) }) && !items.iter().any(|item| item.ident.name.as_str() == "check_attributes") { - let context = if is_late_pass { "LateContext" } else { "EarlyContext" }; - let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" }; let span = cx.sess().source_map().span_through_char(item.span, '{'); span_lint_and_sugg( cx, MISSING_MSRV_ATTR_IMPL, span, - format!("`extract_msrv_attr!` macro missing from `{lint_pass}` implementation"), - format!("add `extract_msrv_attr!({context})` to the `{lint_pass}` implementation"), - format!("{}\n extract_msrv_attr!({context});", snippet(cx, span, "..")), + "`extract_msrv_attr!` macro missing from `EarlyLintPass` implementation", + "add `extract_msrv_attr!()` to the `EarlyLintPass` implementation", + format!("{}\n extract_msrv_attr!();", snippet(cx, span, "..")), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index ef1c46154d29..edfbc90ca141 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -27,7 +27,7 @@ impl UselessVec { pub fn new(conf: &'static Conf) -> Self { Self { too_large_for_stack: conf.too_large_for_stack, - msrv: conf.msrv.clone(), + msrv: conf.msrv, span_to_lint_map: BTreeMap::new(), allow_in_test: conf.allow_useless_vec_in_tests, } @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { }, // search for `for _ in vec![...]` Node::Expr(Expr { span, .. }) - if span.is_desugaring(DesugaringKind::ForLoop) && self.msrv.meets(msrvs::ARRAY_INTO_ITERATOR) => + if span.is_desugaring(DesugaringKind::ForLoop) && self.msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) => { let suggest_slice = suggest_type(expr); self.check_vec_macro(cx, &vec_args, callsite, expr.hir_id, suggest_slice); @@ -139,8 +139,6 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { } } } - - extract_msrv_attr!(LateContext); } impl UselessVec {