Avoid failed assertion when showing fixes from stdin#8029
Merged
charliermarsh merged 1 commit intomainfrom Oct 18, 2023
Merged
Conversation
charliermarsh
commented
Oct 17, 2023
| success: false | ||
| exit_code: 1 | ||
| success: true | ||
| exit_code: 0 |
Member
Author
There was a problem hiding this comment.
I think this is correct, and was wrong before.
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
MichaReiser
reviewed
Oct 18, 2023
Comment on lines
+160
to
+162
| pub(crate) fn is_empty(&self) -> bool { | ||
| self.0.values().all(FixTable::is_empty) | ||
| } |
Member
There was a problem hiding this comment.
This is a somewhat expensive check for large fix tables. Can we instead avoid adding entries when they have no fixes or would that be confusing because it is no longer guaranteed that a key is present after inserting it.
Member
Author
There was a problem hiding this comment.
We can... It puts us back in the world we were in before (we'll need to take more care when creating these). I was hoping to capture hide that detail from callers. But I can change it.
Member
There was a problem hiding this comment.
Can't we handle it inside of from_iter?
Member
Author
There was a problem hiding this comment.
Ah, right, I moved it.
76d6533 to
05edbab
Compare
MichaReiser
approved these changes
Oct 18, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When linting, we store a map from file path to fixes, which we then use to show a fix summary in the printer.
In the printer, we assume that if the map is non-empty, then we have at least one fix. But this isn't enforced by the fix struct, since you can have an entry from (file path) to (empty fix table). In practice, this only bites us when linting from
stdin, since when linting across multiple files, we have anAddAssignonDiagnosticsthat avoids adding empty entries to the map. When linting fromstdin, we create the map directly, and so it is possible to have a non-empty map that doesn't contain any fixes, leading to a panic.This PR introduces a dedicated struct to make these constraints part of the formal interface.
Closes #8027.
Test Plan
cargo test(notice two failures are removed)