Skip to content

Commit 61f3b6f

Browse files
committed
add configuration option for minimum supported rust version
add msrv attribute to lints listed in #6097
1 parent 25a9193 commit 61f3b6f

File tree

6 files changed

+50
-13
lines changed

6 files changed

+50
-13
lines changed

clippy_lints/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
915915
]);
916916
// end register lints, do not remove this comment, it’s used in `update_lints`
917917

918-
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
918+
let msrv = conf.msrv;
919+
920+
store.register_late_pass(|| box await_holding_lock::AwaitHoldingLock);
919921
store.register_late_pass(|| box serde_api::SerdeAPI);
920922
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
921923
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
@@ -950,7 +952,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
950952
store.register_late_pass(|| box strings::StringAdd);
951953
store.register_late_pass(|| box implicit_return::ImplicitReturn);
952954
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
953-
store.register_late_pass(|| box methods::Methods);
955+
store.register_late_pass(|| box methods::Methods::new(msrv));
954956
store.register_late_pass(|| box map_clone::MapClone);
955957
store.register_late_pass(|| box map_err_ignore::MapErrIgnore);
956958
store.register_late_pass(|| box shadow::Shadow);
@@ -964,7 +966,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
964966
store.register_late_pass(|| box types::Casts);
965967
let type_complexity_threshold = conf.type_complexity_threshold;
966968
store.register_late_pass(move || box types::TypeComplexity::new(type_complexity_threshold));
967-
store.register_late_pass(|| box matches::Matches::default());
969+
store.register_late_pass(|| box matches::Matches { msrv: msrv, ..Default::default() });
968970
store.register_late_pass(|| box minmax::MinMaxPass);
969971
store.register_late_pass(|| box open_options::OpenOptions);
970972
store.register_late_pass(|| box zero_div_zero::ZeroDiv);
@@ -1123,7 +1125,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11231125
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
11241126
store.register_late_pass(|| box mut_mutex_lock::MutMutexLock);
11251127
store.register_late_pass(|| box match_on_vec_items::MatchOnVecItems);
1126-
store.register_early_pass(|| box manual_non_exhaustive::ManualNonExhaustive);
1128+
store.register_early_pass(|| box manual_non_exhaustive::ManualNonExhaustive::new(msrv));
11271129
store.register_late_pass(|| box manual_async_fn::ManualAsyncFn);
11281130
store.register_early_pass(|| box redundant_field_names::RedundantFieldNames);
11291131
store.register_late_pass(|| box vec_resize_to_zero::VecResizeToZero);
@@ -1144,7 +1146,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11441146
store.register_late_pass(|| box manual_unwrap_or::ManualUnwrapOr);
11451147
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
11461148
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
1147-
store.register_late_pass(|| box manual_strip::ManualStrip);
1149+
store.register_late_pass(|| box manual_strip::ManualStrip::new(msrv));
11481150
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
11491151
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
11501152
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));

clippy_lints/src/manual_non_exhaustive.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantDat
44
use rustc_attr as attr;
55
use rustc_errors::Applicability;
66
use rustc_lint::{EarlyContext, EarlyLintPass};
7-
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
use rustc_session::{impl_lint_pass, declare_tool_lint};
88
use rustc_span::Span;
99

10-
const MSRV: &str = "1.40";
1110

1211
declare_clippy_lint! {
1312
/// **What it does:** Checks for manual implementations of the non-exhaustive pattern.
@@ -57,7 +56,18 @@ declare_clippy_lint! {
5756
"manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]"
5857
}
5958

60-
declare_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]);
59+
pub struct ManualNonExhaustive {
60+
msrv: Option<String>,
61+
}
62+
63+
impl ManualNonExhaustive {
64+
#[must_use]
65+
pub fn new(msrv: Option<String>) -> Self {
66+
Self { msrv }
67+
}
68+
}
69+
70+
impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]);
6171

6272
impl EarlyLintPass for ManualNonExhaustive {
6373
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {

clippy_lints/src/manual_strip.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use rustc_hir::{BorrowKind, Expr, ExprKind};
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::hir::map::Map;
1515
use rustc_middle::ty;
16-
use rustc_session::{declare_lint_pass, declare_tool_lint};
16+
use rustc_session::{impl_lint_pass, declare_tool_lint};
1717
use rustc_span::source_map::Spanned;
1818
use rustc_span::Span;
1919

20-
const MSRV: &str = "1.45";
2120

2221
declare_clippy_lint! {
2322
/// **What it does:**
@@ -53,7 +52,18 @@ declare_clippy_lint! {
5352
"suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing"
5453
}
5554

56-
declare_lint_pass!(ManualStrip => [MANUAL_STRIP]);
55+
pub struct ManualStrip {
56+
msrv: Option<String>,
57+
}
58+
59+
impl ManualStrip {
60+
#[must_use]
61+
pub fn new(msrv: Option<String>) -> Self {
62+
Self { msrv }
63+
}
64+
}
65+
66+
impl_lint_pass!(ManualStrip => [MANUAL_STRIP]);
5767

5868
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5969
enum StripKind {

clippy_lints/src/matches.rs

+1
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ declare_clippy_lint! {
522522
#[derive(Default)]
523523
pub struct Matches {
524524
infallible_destructuring_match_linted: bool,
525+
msrv: Option<String>
525526
}
526527

527528
impl_lint_pass!(Matches => [

clippy_lints/src/methods/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
2020
use rustc_middle::hir::map::Map;
2121
use rustc_middle::lint::in_external_macro;
2222
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
23-
use rustc_session::{declare_lint_pass, declare_tool_lint};
23+
use rustc_session::{impl_lint_pass, declare_tool_lint};
2424
use rustc_span::source_map::Span;
2525
use rustc_span::symbol::{sym, SymbolStr};
2626

@@ -1383,7 +1383,18 @@ declare_clippy_lint! {
13831383
"using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation"
13841384
}
13851385

1386-
declare_lint_pass!(Methods => [
1386+
pub struct Methods {
1387+
msrv: Option<String>,
1388+
}
1389+
1390+
impl Methods {
1391+
#[must_use]
1392+
pub fn new(msrv: Option<String>) -> Self {
1393+
Self { msrv }
1394+
}
1395+
}
1396+
1397+
impl_lint_pass!(Methods => [
13871398
UNWRAP_USED,
13881399
EXPECT_USED,
13891400
SHOULD_IMPLEMENT_TRAIT,

clippy_lints/src/utils/conf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ macro_rules! define_Conf {
106106

107107
pub use self::helpers::Conf;
108108
define_Conf! {
109+
/// Lints: MANUAL_NON_EXHAUSTIVE, MANUAL_STRIP, OPTION_AS_REF_DEREF, MATCH_LIKE_MATCHES_MACRO. The minimum rust version
110+
/// that the project supports
111+
(msrv, "msrv": Option<String>, None),
109112
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
110113
(blacklisted_names, "blacklisted_names": Vec<String>, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
111114
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have

0 commit comments

Comments
 (0)