-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add the derivable_impls
lint
#7570
Conversation
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
You can use |
2288ca5
to
a08f41f
Compare
I added
I think it should be ok, do you have special test in mind that I can add it? r? @camsteffen |
c4ac1c0
to
6498b8f
Compare
The lint is technically correct because the result of |
6498b8f
to
9e0f002
Compare
Or maybe just for boolean? For integers take isn't better? |
|
Here's a couple tests - playground |
9e0f002
to
7b49561
Compare
I disabled that lint for primitives. But it is still enable for stack allocated things like @rustbot label +S-waiting-on-review |
☔ The latest upstream changes (presumably #7595) made this pull request unmergeable. Please resolve the merge conflicts. |
3817081
to
5167f10
Compare
r? @camsteffen reassigning, since you already did most of the reviewing work. |
Whoops I somehow assumed this was already assigned to me. |
We should watch out for cases where a manual impl is needed because a derive adds different type bounds (rust-lang/rust#26925). For example, a struct with |
8ac1245
to
f9c4a27
Compare
I now disabled lint for non-lifetime generics, because in addition to that issue, specialized impls can create false positives, and detection of them is not always easy: struct SpecializedImpl<A, B> {
a: A,
b: B,
}
impl<T: Default> Default for SpecializedImpl<T, T> {
fn default() -> Self {
Self {
a: T::default(),
b: T::default(),
}
}
} Not sure if there is real use case for specialized impls of default trait, but |
Wouldn't that example be the same as derive? |
No? I think derive will generate this: impl<A: Default, B: Default> Default for SpecializedImpl<A, B> {
fn default() -> Self {
Self {
a: A::default(),
b: B::default(),
}
}
} |
f9c4a27
to
f973ec6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more things and this is almost ready! Can you be a little more specific for the mem_replace_with_default changelog?
502181f
to
e69061d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, found a couple more things.
☔ The latest upstream changes (presumably #7604) made this pull request unmergeable. Please resolve the merge conflicts. |
479acf7
to
93390d4
Compare
93390d4
to
8221f9e
Compare
Thanks! @bors r+ |
📌 Commit 8221f9e has been approved by |
Add the `derivable_impls` lint Fix #7550 changelog: Add new derivable_impls lint. mem_replace_with_default now covers non constructor cases.
💔 Test failed - checks-action_test |
changelog: is there, what is wrong? |
Oh it has to be on the same line like |
@bors retry |
Like this? Please edit it in the desired way if it is wrong. |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix #7550
changelog: Add new derivable_impls lint. mem_replace_with_default now covers non constructor cases.