Skip to content

Fix false lint warnings in match arms with multiple patterns #14044

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

Merged
merged 1 commit into from
May 9, 2014

Conversation

hirschenberger
Copy link
Contributor

fixing #13866

@alexcrichton
Copy link
Member

This seems like a bit of a roundabout method of iterating over a pattern which is already solved by the Visitor. I would expect the solution to be to ensure that all of the bindings are in the used_mut_nodes map. Do you know why the previous bindings in a pattern are missing from this map?

@hirschenberger
Copy link
Contributor Author

Yes, it was because the visitor was visiting every Pattern of the match arm separately and, looked up if the NodeId of the pattern was in the used_mut_nodes list of the context which was not for the non-matching patterns.
So I had to find the common Ident for the node Ids and look if any of the Ids where used.

@alexcrichton
Copy link
Member

That makes sense to me, but the real bug here seems to be that some identifiers in patterns were missing from the used_mut_nodes map, not that we need to alter the visiting/collection strategy.

@hirschenberger
Copy link
Contributor Author

But to be precise, they are not used, only their common Ident

@lilyball
Copy link
Contributor

lilyball commented May 8, 2014

I am not particularly familiar with Visitor or used_mut_nodes (or any of this, really). But if it's processing all the patterns for each match arm separately, could it not explicitly look for the ident instead of the node id? All patterns for a match arm need to bind the same variables, so if the node id for one is in used_mut_nodes then the matching identifiers in the other patterns can be assumed to be used as well.

@hirschenberger
Copy link
Contributor Author

When all patterns in an arm are processed sepatately, they don't know each other and I have to decide to raise an error in each iteration or not.
I see two solutions:

  • To collect all Ids for each Ident and check if any is in the used_mut_nodes list.
  • To store a used_mut_idents instead of used_mut_nodes in the context.

x = 21
}
_ => {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test where x is not used mutable to verify the number of times the lint is printed?

@alexcrichton
Copy link
Member

Ok, let's take this strategy for now. Just a few comments and I think this is good to go!

bors added a commit that referenced this pull request May 9, 2014
@bors bors closed this May 9, 2014
@bors bors merged commit de92d42 into rust-lang:master May 9, 2014
@hirschenberger hirschenberger deleted the lint_mut_match branch May 9, 2014 15:18
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
fix negative trait bound in outline view (rust-lang#14044)

try to fix and close rust-lang#14044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants