-
Couldn't load subscription status.
- Fork 1.8k
feat({unnecessary,panicking}_unwrap): lint field accesses #15949
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
base: master
Are you sure you want to change the base?
Conversation
| is_potentially_local_place(*local_id, place) | ||
| // If there were projections other than field projections, err on the side of caution and say that they | ||
| // _might_ be mutating something. | ||
| // | ||
| // The reason we use `<=` and not `==` is that a mutation of `struct` or `struct.field1` should count as | ||
| // mutation of the child fields such as `struct.field1.field2` | ||
| && place.projections.len() <= field_indices.len() | ||
| && iter::zip(&place.projections, field_indices.iter().copied().rev()).all(|(proj, field_idx)| { | ||
| match proj.kind { | ||
| ProjectionKind::Field(f_idx, _) => f_idx == field_idx, | ||
| // If this is a projection we don't expect, it _might_ be mutating something | ||
| _ => false, | ||
| } | ||
| }) |
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.
This effectively extends is_potentially_local_place with support for locals with field projections -- maybe this change should be incorporated into is_potentially_local_place directly?
0550663 to
23ee56d
Compare
|
Lintcheck changes for 23ee56d
This comment will be updated if you push new changes |
|
Oh hey look, the multi-step-field-access pattern does come up |
Resolves #15321
Unresolved questions:
changelog: [
unnecessary_unwrap]: lint field accesseschangelog: [
panicking_unwrap]: lint field accesses