Skip to content
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

cargo fix: Call rustc fewer times. #13243

Merged
merged 2 commits into from
Jan 3, 2024
Merged

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Jan 2, 2024

This is an improvement of cargo fix so that it calls rustc one fewer times per target. The original code an extra step of calling rustc to display final diagnostics to the user. Part of the reason is that in the past, cargo did not always use JSON, and so cargo fix was forced to call rustc with and without JSON. Now that cargo uses JSON all the time, that is not necessary. This avoids the final call to rustc by remembering the original output from rustc.

This needs to keep track of both the first and last output from rustc. This is to handle the situation where cargo fix fails to apply some suggestion (either because the verification fails, or rustfix fails). The cargo fix output 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 rustc replacement 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 rustc and to avoid the final call.

Fixes #13215

This adds a set of tests which validates various edge cases around how
`cargo fix` works in terms of calling `rustc` multiple times. This uses
a replacement of `rustc` so it doesn't depend on the behavior of rustc
itself which is not always stable.
This changes `cargo fix` so that it keeps track of the output so that it
doesn't need to run the final "show the output" step.
@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2024

r? @epage

(rustbot has picked a reviewer for you, use r? to override)

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2024

Unknown labels: A-errors

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. Command-fix labels Jan 2, 2024
@epage
Copy link
Contributor

epage commented Jan 3, 2024

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jan 3, 2024

📌 Commit e7eaa51 has been approved by epage

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 3, 2024
@bors
Copy link
Contributor

bors commented Jan 3, 2024

⌛ Testing commit e7eaa51 with merge dfdd5ff...

@bors
Copy link
Contributor

bors commented Jan 3, 2024

☀️ Test successful - checks-actions
Approved by: epage
Pushing dfdd5ff to master...

@bors bors merged commit dfdd5ff into rust-lang:master Jan 3, 2024
20 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2024
Update cargo

10 commits in add15366eaf3f3eb84717d3b8b71902ca36a7c84..2ce45605d9db521b5fd6c1211ce8de6055fdb24e
2024-01-02 03:24:42 +0000 to 2024-01-04 18:04:13 +0000
- feat(embedded): Add prefix-char frontmatter syntax support (rust-lang/cargo#13247)
- Update dependency handlebars to v5 for mdman. (rust-lang/cargo#13249)
- Deprecate rustc plugin support in cargo (rust-lang/cargo#13248)
- feat(embedded): Add multiple experimental manifest syntaxes (rust-lang/cargo#13241)
- chore: update auto labels (rust-lang/cargo#13244)
- test: support publish package with a `public` field. (rust-lang/cargo#13245)
- `cargo fix`: Call rustc fewer times. (rust-lang/cargo#13243)
- chore: tracing be compat with rustc_log (rust-lang/cargo#13239)
- chore(deps): update compatible (rust-lang/cargo#13227)
- Contrib: Fix team HackMD links (rust-lang/cargo#13237)

r? ghost
@ehuss ehuss added this to the 1.77.0 milestone Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. Command-fix S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo fix checks packages twice, even if nothing was fixed
5 participants