Skip to content
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

Lint against manual impl Default that could have been derived #134175

Closed
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1b36289
Make some manual `impl Default` derived
estebank Dec 11, 2024
75f1249
Introduce `default_could_be_derived` lint
estebank Dec 11, 2024
476fe03
Use `derive(Default)`
estebank Dec 11, 2024
9b209dc
Detect `impl Default` where fields are literals and `Default::default…
estebank Dec 11, 2024
3ec241b
Explicitly consider fields set to `None` as `Default` derivable
estebank Dec 11, 2024
9ef798c
Detect when user uses default unit variant in default impl
estebank Dec 11, 2024
9ab4f0c
Use `#[derive(Default)]` for `std::option::Option`
estebank Dec 11, 2024
2c7e43f
Also lint enums with type parameters with unit variant default
estebank Dec 11, 2024
c35fd36
Lint against manual `Default` impl if all fields are defaulted
estebank Dec 11, 2024
e5a4a88
Lint structs with default field values and manual `Default`
estebank Dec 11, 2024
34ecbb9
Extend `Default` lint to tuple-structs
estebank Dec 11, 2024
e39edf7
Extend support to unit-structs and add comments
estebank Dec 12, 2024
5558821
Rework logic to make it work x-crate and remove special cases
estebank Dec 12, 2024
da449e2
update test output
estebank Dec 12, 2024
132b49d
Add test for `const` "equivalent"
estebank Dec 12, 2024
f10d560
`#[derive(Default)] struct FixupContext`
estebank Dec 12, 2024
7c8b801
Tweak lint output
estebank Dec 12, 2024
4c421be
Split lints
estebank Dec 12, 2024
64c4938
Fix clippy tests
estebank Dec 12, 2024
810a245
Use `derive(Default)` in rustfmt
estebank Dec 12, 2024
448d80d
Derive `Default` in `tests::hash`
estebank Dec 12, 2024
433947b
Make lint deny-by-default (for crater run)
estebank Dec 12, 2024
32b933e
`allow(default_could_be_derived)` in `Default` examples
estebank Dec 13, 2024
814146c
Mention `#[default]` in E0655 code index
estebank Dec 13, 2024
c666eae
Fix lint example
estebank Dec 14, 2024
6fa30b6
fix rebase
estebank Dec 15, 2024
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
Prev Previous commit
Next Next commit
Make lint deny-by-default (for crater run)
estebank committed Dec 16, 2024
commit 433947ba48c51ad3a17d3bddf3a741ae1f79f230
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/default_could_be_derived.rs
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ declare_lint! {
/// so the derive for `Default` for a struct is trivial, and for an enum
/// variant with no fields, which can be annotated with `#[default]`.
pub DEFAULT_COULD_BE_DERIVED,
Warn,
Deny,
"detect `Default` impl that could be derived"
}

3 changes: 1 addition & 2 deletions src/tools/clippy/tests/ui/new_without_default.stderr
Original file line number Diff line number Diff line change
@@ -177,8 +177,7 @@ LL | | }
LL | | }
| |_^
|
= note: `-D default-could-be-derived` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
= note: `#[deny(default_could_be_derived)]` on by default
help: you don't need to manually `impl Default`, you can derive it
|
LL ~ #[derive(Default)] pub struct Ok;
3 changes: 1 addition & 2 deletions src/tools/clippy/tests/ui/or_fun_call.stderr
Original file line number Diff line number Diff line change
@@ -255,8 +255,7 @@ LL | | }
LL | | }
| |_____^
|
= note: `-D default-could-be-derived` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
= note: `#[deny(default_could_be_derived)]` on by default
help: you don't need to manually `impl Default`, you can derive it
|
LL ~ #[derive(Default)] struct FakeDefault;
3 changes: 1 addition & 2 deletions src/tools/clippy/tests/ui/unwrap_or_else_default.stderr
Original file line number Diff line number Diff line change
@@ -108,8 +108,7 @@ LL | | }
LL | | }
| |_____^
|
= note: `-D default-could-be-derived` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
= note: `#[deny(default_could_be_derived)]` on by default
help: you don't need to manually `impl Default`, you can derive it
|
LL ~ #[derive(Default)] struct HasDefaultAndDuplicate;