Auto merge of #10164 - khuey:default_enum_unit_variant_msrv, r=llogiq
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 --- changelog: none
This commit is contained in:
commit
ef5a545f98
3 changed files with 20 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_late_pass(|_| Box::new(panic_unimplemented::PanicUnimplemented));
|
||||
store.register_late_pass(|_| Box::new(strings::StringLitAsBytes));
|
||||
store.register_late_pass(|_| Box::new(derive::Derive));
|
||||
store.register_late_pass(|_| Box::new(derivable_impls::DerivableImpls));
|
||||
store.register_late_pass(move |_| Box::new(derivable_impls::DerivableImpls::new(msrv())));
|
||||
store.register_late_pass(|_| Box::new(drop_forget_ref::DropForgetRef));
|
||||
store.register_late_pass(|_| Box::new(empty_enum::EmptyEnum));
|
||||
store.register_late_pass(|_| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue