Skip to content

Commit 507e6f0

Browse files
committed
Migrate clippy_lints to new MSRV API
1 parent 72c69e1 commit 507e6f0

File tree

85 files changed

+310
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+310
-461
lines changed

clippy_lints/src/almost_complete_range.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_then;
3-
use clippy_utils::msrvs::{self, Msrv};
3+
use clippy_utils::msrvs::{self, MsrvStack};
44
use clippy_utils::source::{trim_span, walk_span_to_context};
55
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};
66
use rustc_errors::Applicability;
@@ -32,12 +32,12 @@ declare_clippy_lint! {
3232
impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]);
3333

3434
pub struct AlmostCompleteRange {
35-
msrv: Msrv,
35+
msrv: MsrvStack,
3636
}
3737
impl AlmostCompleteRange {
3838
pub fn new(conf: &'static Conf) -> Self {
3939
Self {
40-
msrv: conf.msrv.clone(),
40+
msrv: MsrvStack::new(conf.msrv),
4141
}
4242
}
4343
}
@@ -97,7 +97,7 @@ impl EarlyLintPass for AlmostCompleteRange {
9797
}
9898
}
9999

100-
extract_msrv_attr!(EarlyContext);
100+
extract_msrv_attr!();
101101
}
102102

103103
fn is_incomplete_range(start: &Expr, end: &Expr) -> bool {

clippy_lints/src/approx_const.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ pub struct ApproxConstant {
6868

6969
impl ApproxConstant {
7070
pub fn new(conf: &'static Conf) -> Self {
71-
Self {
72-
msrv: conf.msrv.clone(),
73-
}
71+
Self { msrv: conf.msrv }
7472
}
7573

7674
fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) {
@@ -91,7 +89,7 @@ impl ApproxConstant {
9189
let s = s.as_str();
9290
if s.parse::<f64>().is_ok() {
9391
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
94-
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) {
92+
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv)) {
9593
span_lint_and_help(
9694
cx,
9795
APPROX_CONSTANT,
@@ -115,8 +113,6 @@ impl<'tcx> LateLintPass<'tcx> for ApproxConstant {
115113
self.check_lit(cx, &lit.node, e);
116114
}
117115
}
118-
119-
extract_msrv_attr!(LateContext);
120116
}
121117

122118
/// Returns `false` if the number of significant figures in `value` are

clippy_lints/src/assigning_clones.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ pub struct AssigningClones {
5959

6060
impl AssigningClones {
6161
pub fn new(conf: &'static Conf) -> Self {
62-
Self {
63-
msrv: conf.msrv.clone(),
64-
}
62+
Self { msrv: conf.msrv }
6563
}
6664
}
6765

@@ -90,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
9088
sym::clone if is_diag_trait_item(cx, fn_id, sym::Clone) => CloneTrait::Clone,
9189
_ if fn_name.as_str() == "to_owned"
9290
&& is_diag_trait_item(cx, fn_id, sym::ToOwned)
93-
&& self.msrv.meets(msrvs::CLONE_INTO) =>
91+
&& self.msrv.meets(cx, msrvs::CLONE_INTO) =>
9492
{
9593
CloneTrait::ToOwned
9694
},
@@ -143,8 +141,6 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
143141
);
144142
}
145143
}
146-
147-
extract_msrv_attr!(LateContext);
148144
}
149145

150146
/// Checks if the data being cloned borrows from the place that is being assigned to:

clippy_lints/src/attrs/deprecated_cfg_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
3-
use clippy_utils::msrvs::{self, Msrv};
3+
use clippy_utils::msrvs::{self, MsrvStack};
44
use rustc_ast::AttrStyle;
55
use rustc_errors::Applicability;
66
use rustc_lint::EarlyContext;
77
use rustc_span::sym;
88

9-
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msrv) {
9+
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
1010
// check cfg_attr
1111
if attr.has_name(sym::cfg_attr)
1212
&& let Some(items) = attr.meta_item_list()

clippy_lints/src/attrs/mod.rs

+13-27
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ mod useless_attribute;
1313
mod utils;
1414

1515
use clippy_config::Conf;
16-
use clippy_utils::msrvs::{self, Msrv};
16+
use clippy_utils::msrvs::{self, MsrvStack};
1717
use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind};
1818
use rustc_hir::{ImplItem, Item, TraitItem};
1919
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
20-
use rustc_session::impl_lint_pass;
20+
use rustc_session::{declare_lint_pass, impl_lint_pass};
2121
use rustc_span::sym;
2222
use utils::{is_lint_level, is_relevant_impl, is_relevant_item, is_relevant_trait};
2323

@@ -409,22 +409,10 @@ declare_clippy_lint! {
409409
"duplicated attribute"
410410
}
411411

412-
pub struct Attributes {
413-
msrv: Msrv,
414-
}
415-
416-
impl_lint_pass!(Attributes => [
412+
declare_lint_pass!(Attributes => [
417413
INLINE_ALWAYS,
418414
]);
419415

420-
impl Attributes {
421-
pub fn new(conf: &'static Conf) -> Self {
422-
Self {
423-
msrv: conf.msrv.clone(),
424-
}
425-
}
426-
}
427-
428416
impl<'tcx> LateLintPass<'tcx> for Attributes {
429417
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
430418
let attrs = cx.tcx.hir().attrs(item.hir_id());
@@ -444,47 +432,45 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
444432
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
445433
}
446434
}
447-
448-
extract_msrv_attr!(LateContext);
449435
}
450436

451-
pub struct EarlyAttributes {
452-
msrv: Msrv,
437+
pub struct PreExpansionEarlyAttributes {
438+
msrv: MsrvStack,
453439
}
454440

455-
impl EarlyAttributes {
441+
impl PreExpansionEarlyAttributes {
456442
pub fn new(conf: &'static Conf) -> Self {
457443
Self {
458-
msrv: conf.msrv.clone(),
444+
msrv: MsrvStack::new(conf.msrv),
459445
}
460446
}
461447
}
462448

463-
impl_lint_pass!(EarlyAttributes => [
449+
impl_lint_pass!(PreExpansionEarlyAttributes => [
464450
DEPRECATED_CFG_ATTR,
465451
NON_MINIMAL_CFG,
466452
DEPRECATED_CLIPPY_CFG_ATTR,
467453
UNNECESSARY_CLIPPY_CFG,
468454
]);
469455

470-
impl EarlyLintPass for EarlyAttributes {
456+
impl EarlyLintPass for PreExpansionEarlyAttributes {
471457
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
472458
deprecated_cfg_attr::check(cx, attr, &self.msrv);
473459
deprecated_cfg_attr::check_clippy(cx, attr);
474460
non_minimal_cfg::check(cx, attr);
475461
}
476462

477-
extract_msrv_attr!(EarlyContext);
463+
extract_msrv_attr!();
478464
}
479465

480466
pub struct PostExpansionEarlyAttributes {
481-
msrv: Msrv,
467+
msrv: MsrvStack,
482468
}
483469

484470
impl PostExpansionEarlyAttributes {
485471
pub fn new(conf: &'static Conf) -> Self {
486472
Self {
487-
msrv: conf.msrv.clone(),
473+
msrv: MsrvStack::new(conf.msrv),
488474
}
489475
}
490476
}
@@ -548,5 +534,5 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
548534
duplicated_attributes::check(cx, &item.attrs);
549535
}
550536

551-
extract_msrv_attr!(EarlyContext);
537+
extract_msrv_attr!();
552538
}

clippy_lints/src/booleans.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ pub struct NonminimalBool {
8383

8484
impl NonminimalBool {
8585
pub fn new(conf: &'static Conf) -> Self {
86-
Self {
87-
msrv: conf.msrv.clone(),
88-
}
86+
Self { msrv: conf.msrv }
8987
}
9088
}
9189

@@ -101,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
10199
_: Span,
102100
_: LocalDefId,
103101
) {
104-
NonminimalBoolVisitor { cx, msrv: &self.msrv }.visit_body(body);
102+
NonminimalBoolVisitor { cx, msrv: self.msrv }.visit_body(body);
105103
}
106104

107105
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
@@ -118,8 +116,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
118116
_ => {},
119117
}
120118
}
121-
122-
extract_msrv_attr!(LateContext);
123119
}
124120

125121
fn inverted_bin_op_eq_str(op: BinOpKind) -> Option<&'static str> {
@@ -196,7 +192,7 @@ fn check_inverted_bool_in_condition(
196192
);
197193
}
198194

199-
fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) {
195+
fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) {
200196
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
201197
&& !expr.span.from_expansion()
202198
&& !inner.span.from_expansion()
@@ -232,7 +228,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) {
232228

233229
struct NonminimalBoolVisitor<'a, 'tcx> {
234230
cx: &'a LateContext<'tcx>,
235-
msrv: &'a Msrv,
231+
msrv: Msrv,
236232
}
237233

238234
use quine_mc_cluskey::Bool;
@@ -325,7 +321,7 @@ impl<'v> Hir2Qmm<'_, '_, 'v> {
325321
struct SuggestContext<'a, 'tcx, 'v> {
326322
terminals: &'v [&'v Expr<'v>],
327323
cx: &'a LateContext<'tcx>,
328-
msrv: &'a Msrv,
324+
msrv: Msrv,
329325
output: String,
330326
}
331327

@@ -395,7 +391,7 @@ impl SuggestContext<'_, '_, '_> {
395391
}
396392
}
397393

398-
fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Option<String> {
394+
fn simplify_not(cx: &LateContext<'_>, curr_msrv: Msrv, expr: &Expr<'_>) -> Option<String> {
399395
match &expr.kind {
400396
ExprKind::Binary(binop, lhs, rhs) => {
401397
if !implements_ord(cx, lhs) {
@@ -437,7 +433,9 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti
437433
.iter()
438434
.copied()
439435
.flat_map(|(msrv, a, b)| vec![(msrv, a, b), (msrv, b, a)])
440-
.find(|&(msrv, a, _)| msrv.is_none_or(|msrv| curr_msrv.meets(msrv)) && a == path.ident.name.as_str())
436+
.find(|&(msrv, a, _)| {
437+
msrv.is_none_or(|msrv| curr_msrv.meets(cx, msrv)) && a == path.ident.name.as_str()
438+
})
441439
.and_then(|(_, _, neg_method)| {
442440
let negated_args = args
443441
.iter()
@@ -466,7 +464,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti
466464
}
467465
}
468466

469-
fn suggest(cx: &LateContext<'_>, msrv: &Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
467+
fn suggest(cx: &LateContext<'_>, msrv: Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
470468
let mut suggest_context = SuggestContext {
471469
terminals,
472470
cx,

clippy_lints/src/casts/borrow_as_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(
1414
expr: &'tcx Expr<'_>,
1515
cast_expr: &'tcx Expr<'_>,
1616
cast_to: &'tcx Ty<'_>,
17-
msrv: &Msrv,
17+
msrv: Msrv,
1818
) -> bool {
1919
if matches!(cast_to.kind, TyKind::Ptr(_))
2020
&& let ExprKind::AddrOf(BorrowKind::Ref, mutability, e) = cast_expr.kind
@@ -32,7 +32,7 @@ pub(super) fn check<'tcx>(
3232
return false;
3333
}
3434

35-
let suggestion = if msrv.meets(msrvs::RAW_REF_OP) {
35+
let suggestion = if msrv.meets(cx, msrvs::RAW_REF_OP) {
3636
let operator_kind = match mutability {
3737
Mutability::Not => "const",
3838
Mutability::Mut => "mut",

clippy_lints/src/casts/cast_abs_to_unsigned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ pub(super) fn check(
1414
cast_expr: &Expr<'_>,
1515
cast_from: Ty<'_>,
1616
cast_to: Ty<'_>,
17-
msrv: &Msrv,
17+
msrv: Msrv,
1818
) {
19-
if msrv.meets(msrvs::UNSIGNED_ABS)
19+
if msrv.meets(cx, msrvs::UNSIGNED_ABS)
2020
&& let ty::Int(from) = cast_from.kind()
2121
&& let ty::Uint(to) = cast_to.kind()
2222
&& let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind

clippy_lints/src/casts/cast_lossless.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) fn check(
1919
cast_from: Ty<'_>,
2020
cast_to: Ty<'_>,
2121
cast_to_hir: &rustc_hir::Ty<'_>,
22-
msrv: &Msrv,
22+
msrv: Msrv,
2323
) {
2424
if !should_lint(cx, cast_from, cast_to, msrv) {
2525
return;
@@ -70,7 +70,7 @@ pub(super) fn check(
7070
);
7171
}
7272

73-
fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool {
73+
fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: Msrv) -> bool {
7474
// Do not suggest using From in consts/statics until it is valid to do so (see #2267).
7575
if is_in_const_context(cx) {
7676
return false;
@@ -96,7 +96,7 @@ fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &
9696
};
9797
!is_isize_or_usize(cast_from) && from_nbits < to_nbits
9898
},
99-
(false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(msrvs::FROM_BOOL) => true,
99+
(false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(cx, msrvs::FROM_BOOL) => true,
100100
(_, _) => {
101101
matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64))
102102
},

clippy_lints/src/casts/cast_slice_different_sizes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use rustc_middle::ty::{self, Ty, TypeAndMut};
99

1010
use super::CAST_SLICE_DIFFERENT_SIZES;
1111

12-
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv) {
12+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Msrv) {
1313
// suggestion is invalid if `ptr::slice_from_raw_parts` does not exist
14-
if !msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) {
14+
if !msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) {
1515
return;
1616
}
1717

clippy_lints/src/casts/cast_slice_from_raw_parts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option<RawPartsKind> {
2323
}
2424
}
2525

26-
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) {
27-
if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS)
26+
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: Msrv) {
27+
if msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS)
2828
&& let ty::RawPtr(ptrty, _) = cast_to.kind()
2929
&& let ty::Slice(_) = ptrty.kind()
3030
&& let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind

0 commit comments

Comments
 (0)