-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add CodeFix::apply_solution
and impl Clone
#14092
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Ah I misread how the test suite worked, thought it only ran |
50fa303
to
148105a
Compare
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.
Thanks for the pull request. I saw you've changed the test snapshot to rustc diagnostics. Would you mind
- Providing issue links and code in Clippy of where Clippy disables rustfix tests.
- Sharing the Clippy diagnositc JSON which rustfix is not happy with.
- Also how Clippy is going to use that new public interface so we won't mess up stuff in the future.
That would make the intent clear and connected. Thank you!
crates/rustfix/src/lib.rs
Outdated
/// Currently individual subdiagnostics with multiple solutions are not | ||
/// detected, they are treated as a single combined solution. See | ||
/// [rust-lang/rust#53934](https://github.com/rust-lang/rust/issues/53934). | ||
pub fn apply_suggestions_separately( |
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.
Do we consider duplicate solutions inside a suggestion? We should only apply once in that situation. See #13728.
That said, it can be considered a rustc bug and we do nothing here if the only consumer is clippy.
I don't think we have an issue open for it but here's a few test examples with disabled rustfix due to having multiple suggestions
https://github.com/rust-lang/cargo/blob/50fa303d5c3e61c95e1a87b5b12ef3de19d415db/crates/rustfix/tests/separate/separate.json is a good Clippy diagnostic example The plan would be to add support to I just noticed though that since the fields of |
Thanks for the information! Now I can clearly see where it came from :)
Sounds that it's better being done on Clippy/ui_test side if it is the only consumer. It also reduces cross repo works if something needs to change in the futre.
Yeah I am good with these additions. |
148105a
to
47eb0e8
Compare
rustfix::apply_suggestions_separately
CodeFix::apply_solution
and impl Clone
47eb0e8
to
5a15397
Compare
A much smaller PR now 😄 |
Thanks! BTW, do you know what rust-cloud-vms is? I saw it force-pushed code you commited. Or, are you a bot? |
🤖 It's because I pushed from one of the dev desktops, they have a funky credential helper setup going on that I guess appears as though it's coming from the bot |
@bors r+ |
☀️ Test successful - checks-actions |
Update cargo 17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65 2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000 - test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111) - test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100) - test: Add auto-redaction for not found error (rust-lang/cargo#14124) - test: migrate build to snapbox (rust-lang/cargo#14068) - test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119) - fix(test): Un-redact Packaged files (rust-lang/cargo#14123) - test: Auto-redact file number (rust-lang/cargo#14121) - test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104) - Simplify checking feature syntax (rust-lang/cargo#14106) - test: migrate testsuites to snapbox (rust-lang/cargo#14091) - Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107) - fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110) - Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092) - test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093) - Simplify checking for dependency cycles (rust-lang/cargo#14089) - test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103) - test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098) <!-- r? ghost -->
Update cargo 17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65 2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000 - test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111) - test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100) - test: Add auto-redaction for not found error (rust-lang/cargo#14124) - test: migrate build to snapbox (rust-lang/cargo#14068) - test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119) - fix(test): Un-redact Packaged files (rust-lang/cargo#14123) - test: Auto-redact file number (rust-lang/cargo#14121) - test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104) - Simplify checking feature syntax (rust-lang/cargo#14106) - test: migrate testsuites to snapbox (rust-lang/cargo#14091) - Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107) - fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110) - Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092) - test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093) - Simplify checking for dependency cycles (rust-lang/cargo#14089) - test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103) - test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098) <!-- r? ghost -->
What does this PR try to resolve?
In Clippy we have a good few lints that produce mutually exclusive suggestions e.g.
For these we have to disable rustfix tests since the suggestions are overlapping, this PR adds a method to
rustfix
thatui_test
could use in order to produce multiple.fixed
files, one for each alternative suggestionAdditional information
It does not work for for multiple suggestions coming from a single subdiagnostic (
Diag::span_suggestions
) e.g.Solving this would be blocked on rust-lang/rust#53934, on the Clippy side we only have one use of
span_suggestions
however so it's still very useful without thisThe test cases use Clippy lints that I generated by setting the
parse_and_replace
test to useclippy-driver
because of familiarity, if there's a rustc case that does multiple suggestions it would be good to go with that