cargo fix: Call rustc fewer times.
#13243
Merged
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.
This is an improvement of
cargo fixso that it callsrustcone fewer times per target. The original code an extra step of callingrustcto display final diagnostics to the user. Part of the reason is that in the past, cargo did not always use JSON, and socargo fixwas forced to callrustcwith and without JSON. Now that cargo uses JSON all the time, that is not necessary. This avoids the final call torustcby remembering the original output fromrustc.This needs to keep track of both the first and last output from
rustc. This is to handle the situation wherecargo fixfails to apply some suggestion (either because the verification fails, orrustfixfails). Thecargo fixoutput includes both the error, and the original diagnostics before the error.The first commit is a little test framework to exercise the various edge cases around how fix works. The comments should explain how it works, but it essentially has a
rustcreplacement that emits various different diagnostics and counts how often it is called.The subsequent commit includes the change to keep track of the output from
rustcand to avoid the final call.Fixes #13215