Skip to content

Commit 5b0004c

Browse files
committed
Migrate clippy_lints to new MSRV API
1 parent 0972c3b commit 5b0004c

File tree

102 files changed

+430
-640
lines changed

Some content is hidden

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

102 files changed

+430
-640
lines changed

Diff for: 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;
@@ -31,12 +31,12 @@ declare_clippy_lint! {
3131
impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]);
3232

3333
pub struct AlmostCompleteRange {
34-
msrv: Msrv,
34+
msrv: MsrvStack,
3535
}
3636
impl AlmostCompleteRange {
3737
pub fn new(conf: &'static Conf) -> Self {
3838
Self {
39-
msrv: conf.msrv.clone(),
39+
msrv: MsrvStack::new(conf.msrv),
4040
}
4141
}
4242
}
@@ -96,7 +96,7 @@ impl EarlyLintPass for AlmostCompleteRange {
9696
}
9797
}
9898

99-
extract_msrv_attr!(EarlyContext);
99+
extract_msrv_attr!();
100100
}
101101

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

Diff for: clippy_lints/src/approx_const.rs

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

7070
impl ApproxConstant {
7171
pub fn new(conf: &'static Conf) -> Self {
72-
Self {
73-
msrv: conf.msrv.clone(),
74-
}
72+
Self { msrv: conf.msrv }
7573
}
7674
}
7775

@@ -89,16 +87,14 @@ impl LateLintPass<'_> for ApproxConstant {
8987
_ => (),
9088
}
9189
}
92-
93-
extract_msrv_attr!(LateContext);
9490
}
9591

9692
impl ApproxConstant {
9793
fn check_known_consts(&self, cx: &LateContext<'_>, span: Span, s: symbol::Symbol, module: &str) {
9894
let s = s.as_str();
9995
if s.parse::<f64>().is_ok() {
10096
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
101-
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) {
97+
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv)) {
10298
span_lint_and_help(
10399
cx,
104100
APPROX_CONSTANT,

Diff for: 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:

Diff for: 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()

Diff for: clippy_lints/src/attrs/mod.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod useless_attribute;
1414
mod utils;
1515

1616
use clippy_config::Conf;
17-
use clippy_utils::msrvs::{self, Msrv};
17+
use clippy_utils::msrvs::{self, Msrv, MsrvStack};
1818
use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind};
1919
use rustc_hir::{ImplItem, Item, TraitItem};
2020
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
@@ -459,9 +459,7 @@ impl_lint_pass!(Attributes => [
459459

460460
impl Attributes {
461461
pub fn new(conf: &'static Conf) -> Self {
462-
Self {
463-
msrv: conf.msrv.clone(),
464-
}
462+
Self { msrv: conf.msrv }
465463
}
466464
}
467465

@@ -471,7 +469,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
471469
if is_relevant_item(cx, item) {
472470
inline_always::check(cx, item.span, item.ident.name, attrs);
473471
}
474-
repr_attributes::check(cx, item.span, attrs, &self.msrv);
472+
repr_attributes::check(cx, item.span, attrs, self.msrv);
475473
}
476474

477475
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
@@ -485,18 +483,16 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
485483
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
486484
}
487485
}
488-
489-
extract_msrv_attr!(LateContext);
490486
}
491487

492488
pub struct EarlyAttributes {
493-
msrv: Msrv,
489+
msrv: MsrvStack,
494490
}
495491

496492
impl EarlyAttributes {
497493
pub fn new(conf: &'static Conf) -> Self {
498494
Self {
499-
msrv: conf.msrv.clone(),
495+
msrv: MsrvStack::new(conf.msrv),
500496
}
501497
}
502498
}
@@ -515,17 +511,17 @@ impl EarlyLintPass for EarlyAttributes {
515511
non_minimal_cfg::check(cx, attr);
516512
}
517513

518-
extract_msrv_attr!(EarlyContext);
514+
extract_msrv_attr!();
519515
}
520516

521517
pub struct PostExpansionEarlyAttributes {
522-
msrv: Msrv,
518+
msrv: MsrvStack,
523519
}
524520

525521
impl PostExpansionEarlyAttributes {
526522
pub fn new(conf: &'static Conf) -> Self {
527523
Self {
528-
msrv: conf.msrv.clone(),
524+
msrv: MsrvStack::new(conf.msrv),
529525
}
530526
}
531527
}
@@ -589,5 +585,5 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
589585
duplicated_attributes::check(cx, &item.attrs);
590586
}
591587

592-
extract_msrv_attr!(EarlyContext);
588+
extract_msrv_attr!();
593589
}

Diff for: clippy_lints/src/attrs/repr_attributes.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ use rustc_lint::LateContext;
44
use rustc_span::Span;
55

66
use clippy_utils::diagnostics::span_lint_and_then;
7-
use clippy_utils::msrvs;
7+
use clippy_utils::msrvs::{self, Msrv};
88

99
use super::REPR_PACKED_WITHOUT_ABI;
1010

11-
pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute], msrv: &msrvs::Msrv) {
12-
if msrv.meets(msrvs::REPR_RUST) {
13-
check_packed(cx, item_span, attrs);
14-
}
15-
}
16-
17-
fn check_packed(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) {
11+
pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute], msrv: Msrv) {
1812
if let Some(reprs) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
1913
let packed_span = reprs
2014
.iter()
@@ -25,6 +19,7 @@ fn check_packed(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) {
2519
&& !reprs
2620
.iter()
2721
.any(|(x, _)| *x == ReprAttr::ReprC || *x == ReprAttr::ReprRust)
22+
&& msrv.meets(cx, msrvs::REPR_RUST)
2823
{
2924
span_lint_and_then(
3025
cx,

Diff for: clippy_lints/src/booleans.rs

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

8686
impl NonminimalBool {
8787
pub fn new(conf: &'static Conf) -> Self {
88-
Self {
89-
msrv: conf.msrv.clone(),
90-
}
88+
Self { msrv: conf.msrv }
9189
}
9290
}
9391

@@ -103,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
103101
_: Span,
104102
_: LocalDefId,
105103
) {
106-
NonminimalBoolVisitor { cx, msrv: &self.msrv }.visit_body(body);
104+
NonminimalBoolVisitor { cx, msrv: self.msrv }.visit_body(body);
107105
}
108106

109107
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
@@ -120,8 +118,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
120118
_ => {},
121119
}
122120
}
123-
124-
extract_msrv_attr!(LateContext);
125121
}
126122

127123
fn inverted_bin_op_eq_str(op: BinOpKind) -> Option<&'static str> {
@@ -198,7 +194,7 @@ fn check_inverted_bool_in_condition(
198194
);
199195
}
200196

201-
fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) {
197+
fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) {
202198
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
203199
&& !expr.span.from_expansion()
204200
&& !inner.span.from_expansion()
@@ -234,7 +230,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) {
234230

235231
struct NonminimalBoolVisitor<'a, 'tcx> {
236232
cx: &'a LateContext<'tcx>,
237-
msrv: &'a Msrv,
233+
msrv: Msrv,
238234
}
239235

240236
use quine_mc_cluskey::Bool;
@@ -327,7 +323,7 @@ impl<'v> Hir2Qmm<'_, '_, 'v> {
327323
struct SuggestContext<'a, 'tcx, 'v> {
328324
terminals: &'v [&'v Expr<'v>],
329325
cx: &'a LateContext<'tcx>,
330-
msrv: &'a Msrv,
326+
msrv: Msrv,
331327
output: String,
332328
}
333329

@@ -398,7 +394,7 @@ impl SuggestContext<'_, '_, '_> {
398394
}
399395
}
400396

401-
fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Option<String> {
397+
fn simplify_not(cx: &LateContext<'_>, curr_msrv: Msrv, expr: &Expr<'_>) -> Option<String> {
402398
match &expr.kind {
403399
ExprKind::Binary(binop, lhs, rhs) => {
404400
if !implements_ord(cx, lhs) {
@@ -440,7 +436,9 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti
440436
.iter()
441437
.copied()
442438
.flat_map(|(msrv, a, b)| vec![(msrv, a, b), (msrv, b, a)])
443-
.find(|&(msrv, a, _)| msrv.is_none_or(|msrv| curr_msrv.meets(msrv)) && a == path.ident.name.as_str())
439+
.find(|&(msrv, a, _)| {
440+
a == path.ident.name.as_str() && msrv.is_none_or(|msrv| curr_msrv.meets(cx, msrv))
441+
})
444442
.and_then(|(_, _, neg_method)| {
445443
let negated_args = args
446444
.iter()
@@ -469,7 +467,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti
469467
}
470468
}
471469

472-
fn suggest(cx: &LateContext<'_>, msrv: &Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
470+
fn suggest(cx: &LateContext<'_>, msrv: Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
473471
let mut suggest_context = SuggestContext {
474472
terminals,
475473
cx,

Diff for: clippy_lints/src/casts/borrow_as_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(
1616
expr: &'tcx Expr<'_>,
1717
cast_expr: &'tcx Expr<'_>,
1818
cast_to: &'tcx Ty<'_>,
19-
msrv: &Msrv,
19+
msrv: Msrv,
2020
) -> bool {
2121
if matches!(cast_to.kind, TyKind::Ptr(_))
2222
&& let ExprKind::AddrOf(BorrowKind::Ref, mutability, e) = cast_expr.kind
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
3434
return false;
3535
}
3636

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

Diff for: clippy_lints/src/casts/cast_abs_to_unsigned.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ 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)
20-
&& let ty::Int(from) = cast_from.kind()
19+
if let ty::Int(from) = cast_from.kind()
2120
&& let ty::Uint(to) = cast_to.kind()
2221
&& let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind
2322
&& method_path.ident.name.as_str() == "abs"
23+
&& msrv.meets(cx, msrvs::UNSIGNED_ABS)
2424
{
2525
let span = if from.bit_width() == to.bit_width() {
2626
expr.span

Diff for: 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
},

Diff for: clippy_lints/src/casts/cast_slice_different_sizes.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ 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) {
13-
// suggestion is invalid if `ptr::slice_from_raw_parts` does not exist
14-
if !msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) {
15-
return;
16-
}
17-
12+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Msrv) {
1813
// if this cast is the child of another cast expression then don't emit something for it, the full
1914
// chain will be analyzed
2015
if is_child_of_cast(cx, expr) {
@@ -30,7 +25,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
3025
if let (Ok(from_layout), Ok(to_layout)) = (cx.layout_of(start_ty.ty), cx.layout_of(end_ty.ty)) {
3126
let from_size = from_layout.size.bytes();
3227
let to_size = to_layout.size.bytes();
33-
if from_size != to_size && from_size != 0 && to_size != 0 {
28+
if from_size != to_size && from_size != 0 && to_size != 0 && msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) {
3429
span_lint_and_then(
3530
cx,
3631
CAST_SLICE_DIFFERENT_SIZES,

0 commit comments

Comments
 (0)