Skip to content

exclude enum from derivable impls #7755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/derivable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
if !attrs.iter().any(|attr| attr.doc_str().is_some());
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
if !child_attrs.iter().any(|attr| attr.doc_str().is_some());
if !adt_def.is_enum();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should check for if adt_def.is_struct(); instead, to make sure that we don't get any FPs on unions, as they can also not derive Default. Otherwise, this looks good to me 🙃

then {
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
if let Some(PathSegment { args: Some(a), .. }) = p.segments.last() {
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/derivable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,17 @@ impl Default for RepeatDefault2 {
}
}

// https://github.com/rust-lang/rust-clippy/issues/7753

pub enum IntOrString {
Int(i32),
String(String),
}

impl Default for IntOrString {
fn default() -> Self {
IntOrString::Int(0)
}
}

fn main() {}