-
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
eval_order_dependence shouldn't fire for struct initializers #4637
Comments
Other than special casing struct initializers, the other potential change is to not fire |
It hit me today. Here's a simplified version:
gives
IMHO this is safe and should not be linted. @flip1995 Could you add the correct labels as well as maybe give an instruction on how to fix this? I would work on this, but currently have no plan to start where :) |
@hellow554 I added the labels. For the instruction on how to fix this, it is a bit more complicated. This is probably a really easy fix, the question is, where it has to be done. You probably have to just add |
I tried a few things yesterday, but they either broke existing tests (not sure if legitmate) oder hadn't the desirede effect. I don't think that this should be too hard 😅 But yeah, a look would be great @flip1995 |
Uh, I think this is harder than I thought. For once, the lint is triggered inside a visitor, which is a bad idea most of the time. This is also the reason why just adding a |
The lint has been renamed to |
It's become idiomatic for
syn
-based parsers to parse members of each AST struct directly into the struct initializer, including e.g.bracketed!
which initializes a place outside of the initializer. Thebracketed!
example:clippy gives a
eval_order_dependence
warning here:I believe that struct initializer syntax is in fact strongly specified to evaluate the member expressions in source order. And in this case, the order of the write and read can only be this, as the place assigned is both non-
mut
and not yet initialized before the write.(Note that
ParseStream
is&'_ ParseBuffer<'_>
which does include internal mutability but does so through&Cell
, so the false negative on internal mutability ordering here is expected and likely unpreventable.)The text was updated successfully, but these errors were encountered: