Restrict suggestion of deriving Default for enums to MSRV 1.62.
See https://blog.rust-lang.org/2022/06/30/Rust-1.62.0.html#default-enum-variants
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::source::indent_of;
|
||||
use clippy_utils::{is_default_equivalent, peel_blocks};
|
||||
use rustc_errors::Applicability;
|
||||
@@ -8,7 +9,7 @@ use rustc_hir::{
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{AdtDef, DefIdTree};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::sym;
|
||||
|
||||
declare_clippy_lint! {
|
||||
@@ -53,7 +54,18 @@ declare_clippy_lint! {
|
||||
"manual implementation of the `Default` trait which is equal to a derive"
|
||||
}
|
||||
|
||||
declare_lint_pass!(DerivableImpls => [DERIVABLE_IMPLS]);
|
||||
pub struct DerivableImpls {
|
||||
msrv: Msrv,
|
||||
}
|
||||
|
||||
impl DerivableImpls {
|
||||
#[must_use]
|
||||
pub fn new(msrv: Msrv) -> Self {
|
||||
DerivableImpls { msrv }
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(DerivableImpls => [DERIVABLE_IMPLS]);
|
||||
|
||||
fn is_path_self(e: &Expr<'_>) -> bool {
|
||||
if let ExprKind::Path(QPath::Resolved(_, p)) = e.kind {
|
||||
@@ -181,10 +193,12 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
||||
then {
|
||||
if adt_def.is_struct() {
|
||||
check_struct(cx, item, self_ty, func_expr, adt_def);
|
||||
} else if adt_def.is_enum() {
|
||||
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
|
||||
check_enum(cx, item, func_expr, adt_def);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extract_msrv_attr!(LateContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user