-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Reassign default private #6375
Reassign default private #6375
Conversation
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
Isn't Also, for let mut a: A = Default::default();
a.i = Default::default(); why not suggest let mut a: A = A { i: Default::default(), ..Default::default() }; |
In that case yes. So we could theoretically check for
It should do that. |
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.
So I think checking for derive(Default)
in this lint would be a good enhancement.
But I think that is a distinct issue that should not be silently corrected by this lint
I disagree. If we can make sure that we're suggesting semantically equivalent code, that improves readability, why not do so?
It should do that.
Does it? The two removed tests suggest otherwise. If it indeed does do that, not checking for derive(Default)
in this lint, but implement a lint that checks for
let mut a: A = A { i: Default::default(), ..Default::default() };
might actually make sense.
Anyway, this can be solved by adding back those tests and make sure that it does suggest
let mut a: A = A { i: Default::default(), ..Default::default() };
self.reassigned_linted.insert(span); | ||
} | ||
// span lint once per statement that binds default | ||
span_lint_and_note( |
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.
Is there a reason, why span_lint_and_sugg
isn't used here? @ebroto I think you reviewed the initial implementation.
Sorry for taking so long with the review. I was busy with work stuff and the clippy roadmap. |
The default value for a field type does not necessarily match the default value for that field in the struct Default.
There is already an assertion that consecutive lines assign to a struct field.
008004c
to
c6450c7
Compare
@bors r+ Thanks! |
📌 Commit c6450c7 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
@flip1995 It seems like the previous broken version is part of Rust 1.49.0. Is there a way to bump the clippy version for a release? This now causes build failures that are impossible to fix without disabling clippy (at least locally) which is quite unfortunate. |
Not really. A stable backport for this is hard to do. We recommend to disable this lint until this fix is deployed. I'll create a beta backport so it will already be in 1.50. |
That's very unfortunate and seems quite limiting. Is there any plan on how to change that in the future? It seems quite unfortunate that rustup components would be tied so strictly to the rustc update schedule. One of the greatest things about clippy is that it's one of the few linters that actually seems usable without having to tweak it 24/7, it's quite unfortunate when that isn't the case and causes trouble like that. Especially for stable releases with obvious bugs. Now mistakes happen of course, that's no problem, but that's exactly why I feel like it makes sense to have processes in place to deal with these issues. I'd hope that this is the most severe kind of issue clippy would ever ship in a stable release, but it could always get worse. Having to change entire CI setups for stable release cycles because of a clippy bug would be most unfortunate and so would be a bump to the entire rust version just for a component update. |
Clippy has more than a few bugs and this one just happened to be fixed right after the cutoff. I think the maintainers are doing all that they reasonably should do. Just my two cents. |
No not the release cycle. This is the best possible way to do Clippy releases. But like mentioned multiple times in #6462, we want to improve the situation for such bugs getting into stable undetected. For a bug like this, you don't have to change your CI setup, but just add |
That's nice, I suppose the main issue with this was just that you were a bit busy, which is natural of course. Temporarily disabling lints that are broken always is an option, but that also requires work. So being able to fix things retroactively would just allow for a bit more flexibility.
I'm aware, thanks. I just added a local annotation while grinding my teeth. I was talking about some other hypothetical issue that might slip through. |
Not really, just that I didn't know that this was a big issue before the 1.49 release. About a year ago I mainly maintained Clippy alone and knew about practically every issue. That isn't possible anymore though.
Understandable. We'll try to improve this situation, because we want Clippy to be as easy to use and reliable as possible. This shouldn't happen, but until now we haven't had the resources or a plan how we want to deal with things like this. |
…=flip1995 Reassign default private changelog: fix field_reassign_with_default false positive * Fix rust-lang#6344 * Fix assumption that `field: Default::default()` is the same as `..Default::default()` * Cleanup some redundant logic
changelog: fix field_reassign_with_default false positive
field: Default::default()
is the same as..Default::default()