-
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
Move inconsistent_struct_constructor
to pedantic
#7193
Move inconsistent_struct_constructor
to pedantic
#7193
Conversation
The whole point of named fields is that we don't have to worry about order. The names, not the position, communicate the information, so worrying about consistency for consistency's sake is pedantic to a *T*. Fixes rust-lang#7192. wchargin-branch: inconsistent-struct-constructor-pedantic wchargin-source: 4fe078a21c77ceb625e58fa3b90b613fc4fa6a76
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @camsteffen (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Well I think the thing is that because of this inconsistency (which is probably ok in most cases) you MIGHT write code that does not work the way you think it does and that can cause bugs. |
This seems pedantic to me. I'll wait for other opinions. |
I agree with @matthiaskrgr. One of the motivations for introducing this lint was to indirectly address FN of Also, the applicability of this lint is |
Those are not good motives for re-categorizing a lint IMO. If another lint has a false positive, then that should be fixed. My reasoning for thinking it should be pedantic is that the significance of the order of fields in a struct varies widely between structs. Considering structs where the order is meaningless, it is pedantic to tell people to reorder the fields to match the definition. |
What I meant was
Not to fix another lint's FN. |
I also think this is too pedantic for general applicability, I always liked to group my initializers with "simple" fields that use the syntax shorthand first and more "complicated" fields that use expressions or variables with other names last, to make it more obvious which variables are trivially reused. |
This lint only triggers if only the shorthands are present in the constructor (at least that is what is documented). But I'm also leaning towards Maybe this lint should also consider the types of the fields, but I'm not sure if that would actually help in real world code. In its current state, aggressively linting all structs, this lint should be in |
That is a little surprising to me. The lint could include cases without shorthand where there are no side-effects. But in any case I don't think that has any bearing on whether it should be pedantic. |
I haven't looked at the code, but that is what the documentation says. And yeah, I agree this has little influence on the decision if it should be pedantic. |
+1 |
@bors r+ Between comments here and on the issue, many people believe that that out of order fields is not bad style, at least not enough to warn by default. |
📌 Commit 1b2ca30 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
The whole point of named fields is that we don't have to worry about
order. The names, not the position, communicate the information, so
worrying about consistency for consistency's sake is pedantic to a T.
Closes #7192.
changelog: [
inconsistent_struct_constructor
] is moved to pedantic.wchargin-branch: inconsistent-struct-constructor-pedantic