-
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
Don't trigger field_reassign_with_default
in macros
#7160
Conversation
Producing a good suggestion for this lint is already hard when no macros are involved. With macros the lint message and the suggestion are just confusing. Since both, producing a good suggestion and figuring out if this pattern can be re-written inside a macro is nearly impossible, just bail out.
r? @phansch (rust-highfive has picked a reviewer for you, use r? to override) |
This could still be applicable in macros, but not applicable unless Then this is the most macro-ified yet lintable version. (..) => {
let $x = Default::default();
$x.$y = Default::default();
} In other words, the example in the bug is not lint-able because the field re-assignment ( |
Yeah, I thought of doing this. But the lint message + suggestion is then all over the place. It tells you that:
The suggestion generation and detection in this lint is already really complicated. Now special casing every part of the suggestion on different macro contexts would make this code absolutely unreadable IMO. I don't think this is worth for this lint. Also if you expand a (..) => {
let $x = Default::default();
$(
$x.$y = Default::default();
)*
} would have everything in the same expansion context, but you can't rewrite it. Playground I'll adapt the test case, since this better shows the problem with linting this inside macros. |
I see. I think it may be possible to do without special casing for macros. I would start by not using |
Yeah, but this is necessary, so that if you assign |
Maybe |
Er |
Meh nevermind. There could be |
Yeah, macros are just too complicated to get lints right that check patterns over multiple statements (especially since we don't know how the unexpanded code looked like in the HIR). As I said, even if you expand with |
ping from triage @phansch. Can you have time to review this? |
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.
LGTM. I gathered from the previous discussion that everyone is okay with just not linting this inside macros.
Hey @camsteffen, I've confirmed with @phansch
that it's okay if we pick up his PRs. @flip1995
usually double-checks my reviews, but this would be a bit counterproductive in this case. Could you maybe rereview it and merge the PR if you also approve of it? 🙃
Sure thing. @bors r=xFrednet,camsteffen |
📌 Commit 0854f0c has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #7155
Producing a good suggestion for this lint is already hard when no macros
are involved. With macros the lint message and the suggestion are just
confusing. Since both, producing a good suggestion and figuring out if
this pattern can be re-written inside a macro is nearly impossible, just
bail out.
changelog: [
field_reassign_with_default
] No longer triggers in macrosNo that our reviewing queue is under control, I want to start hacking on Clippy myself again. Starting with an easy issue to get back in :)