Skip to content

Commit f33d86d

Browse files
committed
Auto merge of rust-lang#7137 - camsteffen:msrv-mod, r=llogiq
Refactor MSRV aliases changelog: Remove MSRV from `needless_question_mark` and change MSRV for `missing_const_for_fn` from 1.37.0 to 1.46.0. First [mentioned on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Better.20MSRV.20testing.20idea/near/236215074). * Moves MSRV constants into `clippy_utils::msrvs`. Now they are named to represent a stabilized feature flag or library item that is required for a lint's suggestion. * `needless_question_mark` no longer has MSRV. Not needed since it does not suggest adding `?`. * `missing_const_for_fn` MSRV was changed from 1.37.0 to 1.46.0. This seems to be a past mistake.
2 parents a362a4d + 3a8e759 commit f33d86d

27 files changed

+108
-293
lines changed

clippy_lints/src/casts/ptr_as_ptr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::borrow::Cow;
22

33
use clippy_utils::diagnostics::span_lint_and_sugg;
4-
use clippy_utils::meets_msrv;
54
use clippy_utils::sugg::Sugg;
5+
use clippy_utils::{meets_msrv, msrvs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::{Expr, ExprKind, Mutability, TyKind};
@@ -12,10 +12,8 @@ use rustc_semver::RustcVersion;
1212

1313
use super::PTR_AS_PTR;
1414

15-
const PTR_AS_PTR_MSRV: RustcVersion = RustcVersion::new(1, 38, 0);
16-
1715
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: &Option<RustcVersion>) {
18-
if !meets_msrv(msrv.as_ref(), &PTR_AS_PTR_MSRV) {
16+
if !meets_msrv(msrv.as_ref(), &msrvs::POINTER_CAST) {
1917
return;
2018
}
2119

clippy_lints/src/checked_conversions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use clippy_utils::source::snippet_with_applicability;
5-
use clippy_utils::{meets_msrv, SpanlessEq};
5+
use clippy_utils::{meets_msrv, msrvs, SpanlessEq};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
88
use rustc_errors::Applicability;
@@ -12,8 +12,6 @@ use rustc_middle::lint::in_external_macro;
1212
use rustc_semver::RustcVersion;
1313
use rustc_session::{declare_tool_lint, impl_lint_pass};
1414

15-
const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0);
16-
1715
declare_clippy_lint! {
1816
/// **What it does:** Checks for explicit bounds checking when casting.
1917
///
@@ -58,7 +56,7 @@ impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
5856

5957
impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
6058
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
61-
if !meets_msrv(self.msrv.as_ref(), &CHECKED_CONVERSIONS_MSRV) {
59+
if !meets_msrv(self.msrv.as_ref(), &msrvs::TRY_FROM) {
6260
return;
6361
}
6462

clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::paths::INTO;
3-
use clippy_utils::{match_def_path, meets_msrv};
3+
use clippy_utils::{match_def_path, meets_msrv, msrvs};
44
use if_chain::if_chain;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_semver::RustcVersion;
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99

10-
const FROM_OVER_INTO_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
11-
1210
declare_clippy_lint! {
1311
/// **What it does:** Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead.
1412
///
@@ -57,7 +55,7 @@ impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
5755

5856
impl LateLintPass<'_> for FromOverInto {
5957
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
60-
if !meets_msrv(self.msrv.as_ref(), &FROM_OVER_INTO_MSRV) {
58+
if !meets_msrv(self.msrv.as_ref(), &msrvs::RE_REBALANCING_COHERENCE) {
6159
return;
6260
}
6361

clippy_lints/src/if_then_some_else_none.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::source::snippet_with_macro_callsite;
3-
use clippy_utils::{is_else_clause, is_lang_ctor, meets_msrv};
3+
use clippy_utils::{is_else_clause, is_lang_ctor, meets_msrv, msrvs};
44
use if_chain::if_chain;
55
use rustc_hir::LangItem::{OptionNone, OptionSome};
66
use rustc_hir::{Expr, ExprKind};
@@ -9,8 +9,6 @@ use rustc_middle::lint::in_external_macro;
99
use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111

12-
const IF_THEN_SOME_ELSE_NONE_MSRV: RustcVersion = RustcVersion::new(1, 50, 0);
13-
1412
declare_clippy_lint! {
1513
/// **What it does:** Checks for if-else that could be written to `bool::then`.
1614
///
@@ -59,7 +57,7 @@ impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
5957

6058
impl LateLintPass<'_> for IfThenSomeElseNone {
6159
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) {
62-
if !meets_msrv(self.msrv.as_ref(), &IF_THEN_SOME_ELSE_NONE_MSRV) {
60+
if !meets_msrv(self.msrv.as_ref(), &msrvs::BOOL_THEN) {
6361
return;
6462
}
6563

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10761076
store.register_late_pass(move || box from_over_into::FromOverInto::new(msrv));
10771077
store.register_late_pass(move || box use_self::UseSelf::new(msrv));
10781078
store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv));
1079-
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark::new(msrv));
1079+
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark);
10801080
store.register_late_pass(move || box casts::Casts::new(msrv));
10811081
store.register_early_pass(move || box unnested_or_patterns::UnnestedOrPatterns::new(msrv));
10821082

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::attrs::is_doc_hidden;
22
use clippy_utils::diagnostics::span_lint_and_then;
3-
use clippy_utils::meets_msrv;
43
use clippy_utils::source::snippet_opt;
4+
use clippy_utils::{meets_msrv, msrvs};
55
use if_chain::if_chain;
66
use rustc_ast::ast::{FieldDef, Item, ItemKind, Variant, VariantData, VisibilityKind};
77
use rustc_errors::Applicability;
@@ -10,8 +10,6 @@ use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111
use rustc_span::{sym, Span};
1212

13-
const MANUAL_NON_EXHAUSTIVE_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
14-
1513
declare_clippy_lint! {
1614
/// **What it does:** Checks for manual implementations of the non-exhaustive pattern.
1715
///
@@ -76,7 +74,7 @@ impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]);
7674

7775
impl EarlyLintPass for ManualNonExhaustive {
7876
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
79-
if !meets_msrv(self.msrv.as_ref(), &MANUAL_NON_EXHAUSTIVE_MSRV) {
77+
if !meets_msrv(self.msrv.as_ref(), &msrvs::NON_EXHAUSTIVE) {
8078
return;
8179
}
8280

clippy_lints/src/manual_strip.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::{constant, Constant};
22
use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then};
33
use clippy_utils::source::snippet;
44
use clippy_utils::usage::mutated_variables;
5-
use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, paths};
5+
use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, msrvs, paths};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
88
use rustc_hir::def::Res;
@@ -17,8 +17,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
1717
use rustc_span::source_map::Spanned;
1818
use rustc_span::Span;
1919

20-
const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
21-
2220
declare_clippy_lint! {
2321
/// **What it does:**
2422
/// Suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing using
@@ -74,7 +72,7 @@ enum StripKind {
7472

7573
impl<'tcx> LateLintPass<'tcx> for ManualStrip {
7674
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
77-
if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) {
75+
if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) {
7876
return;
7977
}
8078

clippy_lints/src/matches.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use clippy_utils::sugg::Sugg;
77
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs};
88
use clippy_utils::visitors::LocalUsedVisitor;
99
use clippy_utils::{
10-
get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, path_to_local,
11-
path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks, strip_pat_refs,
10+
get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, msrvs,
11+
path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks,
12+
strip_pat_refs,
1213
};
1314
use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash};
1415
use if_chain::if_chain;
@@ -578,8 +579,6 @@ impl_lint_pass!(Matches => [
578579
MATCH_SAME_ARMS,
579580
]);
580581

581-
const MATCH_LIKE_MATCHES_MACRO_MSRV: RustcVersion = RustcVersion::new(1, 42, 0);
582-
583582
impl<'tcx> LateLintPass<'tcx> for Matches {
584583
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
585584
if in_external_macro(cx.sess(), expr.span) || in_macro(expr.span) {
@@ -588,7 +587,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
588587

589588
redundant_pattern_match::check(cx, expr);
590589

591-
if meets_msrv(self.msrv.as_ref(), &MATCH_LIKE_MATCHES_MACRO_MSRV) {
590+
if meets_msrv(self.msrv.as_ref(), &msrvs::MATCHES_MACRO) {
592591
if !check_match_like_matches(cx, expr) {
593592
lint_match_arms(cx, expr);
594593
}

clippy_lints/src/mem_replace.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::source::{snippet, snippet_with_applicability};
3-
use clippy_utils::{in_macro, is_diag_trait_item, is_lang_ctor, match_def_path, meets_msrv, paths};
3+
use clippy_utils::{in_macro, is_diag_trait_item, is_lang_ctor, match_def_path, meets_msrv, msrvs, paths};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
66
use rustc_hir::def_id::DefId;
@@ -256,8 +256,6 @@ fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<
256256
}
257257
}
258258

259-
const MEM_REPLACE_WITH_DEFAULT_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
260-
261259
pub struct MemReplace {
262260
msrv: Option<RustcVersion>,
263261
}
@@ -281,7 +279,7 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
281279
then {
282280
check_replace_option_with_none(cx, src, dest, expr.span);
283281
check_replace_with_uninit(cx, src, dest, expr.span);
284-
if meets_msrv(self.msrv.as_ref(), &MEM_REPLACE_WITH_DEFAULT_MSRV) {
282+
if meets_msrv(self.msrv.as_ref(), &msrvs::MEM_TAKE) {
285283
check_replace_with_default(cx, src, dest, expr.span);
286284
}
287285
}

clippy_lints/src/methods/cloned_instead_of_copied.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::ty::{get_iterator_item_ty, is_copy};
3-
use clippy_utils::{is_trait_method, meets_msrv};
3+
use clippy_utils::{is_trait_method, meets_msrv, msrvs};
44
use rustc_errors::Applicability;
55
use rustc_hir::Expr;
66
use rustc_lint::LateContext;
@@ -10,19 +10,16 @@ use rustc_span::{sym, Span};
1010

1111
use super::CLONED_INSTEAD_OF_COPIED;
1212

13-
const ITERATOR_COPIED_MSRV: RustcVersion = RustcVersion::new(1, 36, 0);
14-
const OPTION_COPIED_MSRV: RustcVersion = RustcVersion::new(1, 35, 0);
15-
1613
pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Option<&RustcVersion>) {
1714
let recv_ty = cx.typeck_results().expr_ty_adjusted(recv);
1815
let inner_ty = match recv_ty.kind() {
1916
// `Option<T>` -> `T`
2017
ty::Adt(adt, subst)
21-
if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) && meets_msrv(msrv, &OPTION_COPIED_MSRV) =>
18+
if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) =>
2219
{
2320
subst.type_at(0)
2421
},
25-
_ if is_trait_method(cx, expr, sym::Iterator) && meets_msrv(msrv, &ITERATOR_COPIED_MSRV) => {
22+
_ if is_trait_method(cx, expr, sym::Iterator) && meets_msrv(msrv, &msrvs::ITERATOR_COPIED) => {
2623
match get_iterator_item_ty(cx, recv_ty) {
2724
// <T as Iterator>::Item
2825
Some(ty) => ty,

clippy_lints/src/methods/filter_map_next.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
22
use clippy_utils::source::snippet;
3-
use clippy_utils::{is_trait_method, meets_msrv};
3+
use clippy_utils::{is_trait_method, meets_msrv, msrvs};
44
use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_lint::LateContext;
@@ -9,8 +9,6 @@ use rustc_span::sym;
99

1010
use super::FILTER_MAP_NEXT;
1111

12-
const FILTER_MAP_NEXT_MSRV: RustcVersion = RustcVersion::new(1, 30, 0);
13-
1412
pub(super) fn check<'tcx>(
1513
cx: &LateContext<'tcx>,
1614
expr: &'tcx hir::Expr<'_>,
@@ -19,7 +17,7 @@ pub(super) fn check<'tcx>(
1917
msrv: Option<&RustcVersion>,
2018
) {
2119
if is_trait_method(cx, expr, sym::Iterator) {
22-
if !meets_msrv(msrv, &FILTER_MAP_NEXT_MSRV) {
20+
if !meets_msrv(msrv, &msrvs::ITERATOR_FIND_MAP) {
2321
return;
2422
}
2523

clippy_lints/src/methods/map_unwrap_or.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
2-
use clippy_utils::meets_msrv;
32
use clippy_utils::source::snippet;
43
use clippy_utils::ty::is_type_diagnostic_item;
54
use clippy_utils::usage::mutated_variables;
5+
use clippy_utils::{meets_msrv, msrvs};
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_lint::LateContext;
@@ -11,8 +11,6 @@ use rustc_span::symbol::sym;
1111

1212
use super::MAP_UNWRAP_OR;
1313

14-
const MAP_UNWRAP_OR_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
15-
1614
/// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s
1715
/// Return true if lint triggered
1816
pub(super) fn check<'tcx>(
@@ -23,13 +21,14 @@ pub(super) fn check<'tcx>(
2321
unwrap_arg: &'tcx hir::Expr<'_>,
2422
msrv: Option<&RustcVersion>,
2523
) -> bool {
26-
if !meets_msrv(msrv, &MAP_UNWRAP_OR_MSRV) {
27-
return false;
28-
}
2924
// lint if the caller of `map()` is an `Option`
3025
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type);
3126
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
3227

28+
if is_result && !meets_msrv(msrv, &msrvs::RESULT_MAP_OR_ELSE) {
29+
return false;
30+
}
31+
3332
if is_option || is_result {
3433
// Don't make a suggestion that may fail to compile due to mutably borrowing
3534
// the same variable twice.

clippy_lints/src/methods/option_as_ref_deref.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet;
33
use clippy_utils::ty::is_type_diagnostic_item;
4-
use clippy_utils::{match_def_path, meets_msrv, path_to_local_id, paths, remove_blocks};
4+
use clippy_utils::{match_def_path, meets_msrv, msrvs, path_to_local_id, paths, remove_blocks};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
@@ -12,8 +12,6 @@ use rustc_span::sym;
1212

1313
use super::OPTION_AS_REF_DEREF;
1414

15-
const OPTION_AS_REF_DEREF_MSRV: RustcVersion = RustcVersion::new(1, 40, 0);
16-
1715
/// lint use of `_.as_ref().map(Deref::deref)` for `Option`s
1816
pub(super) fn check<'tcx>(
1917
cx: &LateContext<'tcx>,
@@ -23,7 +21,7 @@ pub(super) fn check<'tcx>(
2321
is_mut: bool,
2422
msrv: Option<&RustcVersion>,
2523
) {
26-
if !meets_msrv(msrv, &OPTION_AS_REF_DEREF_MSRV) {
24+
if !meets_msrv(msrv, &msrvs::OPTION_AS_DEREF) {
2725
return;
2826
}
2927

clippy_lints/src/missing_const_for_fn.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::qualify_min_const_fn::is_min_const_fn;
33
use clippy_utils::ty::has_drop;
4-
use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, trait_ref_of_method};
4+
use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, msrvs, trait_ref_of_method};
55
use rustc_hir as hir;
66
use rustc_hir::intravisit::FnKind;
77
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
@@ -12,8 +12,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
1212
use rustc_span::Span;
1313
use rustc_typeck::hir_ty_to_ty;
1414

15-
const MISSING_CONST_FOR_FN_MSRV: RustcVersion = RustcVersion::new(1, 37, 0);
16-
1715
declare_clippy_lint! {
1816
/// **What it does:**
1917
///
@@ -97,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
9795
span: Span,
9896
hir_id: HirId,
9997
) {
100-
if !meets_msrv(self.msrv.as_ref(), &MISSING_CONST_FOR_FN_MSRV) {
98+
if !meets_msrv(self.msrv.as_ref(), &msrvs::CONST_IF_MATCH) {
10199
return;
102100
}
103101

0 commit comments

Comments
 (0)