-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Avoid failed assertion when showing fixes from stdin #8029
Conversation
success: false | ||
exit_code: 1 | ||
success: true | ||
exit_code: 0 |
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.
I think this is correct, and was wrong before.
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.
Agreed
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
crates/ruff_cli/src/diagnostics.rs
Outdated
pub(crate) fn is_empty(&self) -> bool { | ||
self.0.values().all(FixTable::is_empty) | ||
} |
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 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.
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.
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.
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.
Can't we handle it inside of from_iter
?
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.
Ah, right, I moved it.
76d6533
to
05edbab
Compare
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 anAddAssign
onDiagnostics
that 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)