Set 1.50 as msrv of if_then_some_else_none
This commit is contained in:
parent
a672d335a2
commit
f2a85cb42a
4 changed files with 59 additions and 5 deletions
|
|
@ -4,7 +4,10 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::{Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
|
||||
const IF_THEN_SOME_ELSE_NONE_MSRV: RustcVersion = RustcVersion::new(1, 50, 0);
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for if-else that could be written to `bool::then`.
|
||||
|
|
@ -39,10 +42,25 @@ declare_clippy_lint! {
|
|||
"Finds if-else that could be written using `bool::then`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
|
||||
pub struct IfThenSomeElseNone {
|
||||
msrv: Option<RustcVersion>,
|
||||
}
|
||||
|
||||
impl IfThenSomeElseNone {
|
||||
#[must_use]
|
||||
pub fn new(msrv: Option<RustcVersion>) -> Self {
|
||||
Self { msrv }
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(IfThenSomeElseNone => [IF_THEN_SOME_ELSE_NONE]);
|
||||
|
||||
impl LateLintPass<'_> for IfThenSomeElseNone {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) {
|
||||
if !utils::meets_msrv(self.msrv.as_ref(), &IF_THEN_SOME_ELSE_NONE_MSRV) {
|
||||
return;
|
||||
}
|
||||
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -85,4 +103,6 @@ impl LateLintPass<'_> for IfThenSomeElseNone {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extract_msrv_attr!(LateContext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1284,7 +1284,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_late_pass(|| box redundant_slicing::RedundantSlicing);
|
||||
store.register_late_pass(|| box from_str_radix_10::FromStrRadix10);
|
||||
store.register_late_pass(|| box manual_map::ManualMap);
|
||||
store.register_late_pass(|| box if_then_some_else_none::IfThenSomeElseNone);
|
||||
store.register_late_pass(move || box if_then_some_else_none::IfThenSomeElseNone::new(msrv));
|
||||
|
||||
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
|
||||
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue