Skip to content

fix: default to all targets when using --edition and --edition-idioms in cargo fix #15192

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

Merged
merged 3 commits into from
May 2, 2025

Conversation

0xPoe
Copy link
Member

@0xPoe 0xPoe commented Feb 16, 2025

What does this PR try to resolve?

Close #13527

As we discussed, cargo fix should use the default target selection with cargo check.

In this PR, I modified cargo fix to no longer use all targets by default. For cargo fix --edition and cargo fix --edition-idioms, it will retain the old behavior and select all targets.

How should we test and review this PR?

Unit tests

Additional information

@rustbot
Copy link
Collaborator

rustbot commented Feb 16, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-cli Area: Command-line interface, option parsing, etc. Command-fix labels Feb 16, 2025
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from c4933a5 to d1c5bf8 Compare February 20, 2025 14:58
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from 60a57f7 to e9ee015 Compare March 5, 2025 14:43
@0xPoe 0xPoe changed the title test: add fix_tests to validate cargo fix functionality fix: default to all targets when using --edition flags in cargo fix Mar 5, 2025
@0xPoe 0xPoe changed the title fix: default to all targets when using --edition flags in cargo fix fix: default to all targets when using --edition and --edition-idioms flags in cargo fix Mar 5, 2025
@0xPoe 0xPoe changed the title fix: default to all targets when using --edition and --edition-idioms flags in cargo fix fix: default to all targets when using --edition and --edition-idioms in cargo fix Mar 5, 2025
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from e9ee015 to f0cd503 Compare March 5, 2025 14:53
@0xPoe 0xPoe marked this pull request as ready for review March 5, 2025 14:56
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from f0cd503 to 5a058c3 Compare March 6, 2025 13:43
Signed-off-by: Rustin170506 <techregister@pm.me>
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch 2 times, most recently from a9f92ed to 99745f0 Compare March 6, 2025 14:19
@@ -1424,7 +1424,7 @@ fn fix_to_broken_code() {
p.cargo("build").cwd("foo").run();

// Attempt to fix code, but our shim will always fail the second compile
p.cargo("fix --allow-no-vcs --broken-code")
p.cargo("fix --all-targets --allow-no-vcs --broken-code")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, this is suspicious and we should understand why in case there is a bad interaction happening

Copy link
Member Author

@0xPoe 0xPoe Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I’m still looking into it. It seems that if we don’t select all targets, the foo rustc is called only twice. However, if we select all targets, it will be called three times, I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With all targets: p.cargo("fix --all-targets --allow-no-vcs --broken-code")

[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:

thread 'main' panicked at src/main.rs:23:29:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original diagnostics will follow.

[WARNING] variable does not need to be mutable
 --> src/lib.rs:1:20
  |
1 | pub fn foo() { let mut x = 3; let _ = x; }
  |                    ----^
  |                    |
  |                    [HELP] remove this `mut`
  |
  = [NOTE] `#[warn(unused_mut)]` on by default

[WARNING] `bar` (lib) generated 1 warning (run `cargo fix --lib -p bar` to apply 1 suggestion)

thread 'main' panicked at src/main.rs:23:29:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] could not compile `bar` (lib test)

Caused by:
  process didn't exit successfully: `/Volumes/t7/code/cargo/target/debug/cargo [ROOT]/foo/foo/target/debug/foo --crate-name bar --edition=2015 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=022767cbb3148d36 -C extra-filename=-99a4e0453221de9d --out-dir [ROOT]/foo/bar/target/debug/deps -L dependency=[ROOT]/foo/bar/target/debug/deps` ([EXIT_STATUS]: 101)

Without all targets: p.cargo("fix --allow-no-vcs --broken-code")

[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:

thread 'main' panicked at src/main.rs:23:29:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original diagnostics will follow.

[WARNING] variable does not need to be mutable
 --> src/lib.rs:1:20
  |
1 | pub fn foo() { let mut x = 3; let _ = x; }
  |                    ----^
  |                    |
  |                    [HELP] remove this `mut`
  |
  = [NOTE] `#[warn(unused_mut)]` on by default

[WARNING] `bar` (lib) generated 1 warning (run `cargo fix --lib -p bar` to apply 1 suggestion)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you have two targets, it also works: p.cargo("fix --lib --tests --allow-no-vcs --broken-code")

[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:

thread 'main' panicked at src/main.rs:23:29:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original diagnostics will follow.

[WARNING] variable does not need to be mutable
 --> src/lib.rs:1:20
  |
1 | pub fn foo() { let mut x = 3; let _ = x; }
  |                    ----^
  |                    |
  |                    [HELP] remove this `mut`
  |
  = [NOTE] `#[warn(unused_mut)]` on by default

[WARNING] `bar` (lib test) generated 1 warning (run `cargo fix --lib -p bar --tests` to apply 1 suggestion)

thread 'main' panicked at src/main.rs:23:29:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] could not compile `bar` (lib)

Caused by:
  process didn't exit successfully: `/Volumes/t7/code/cargo/target/debug/cargo [ROOT]/foo/foo/target/debug/foo --crate-name bar --edition=2015 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=4b0938be085d245b -C extra-filename=-d245623a02104f1e --out-dir [ROOT]/foo/bar/target/debug/deps -L dependency=[ROOT]/foo/bar/target/debug/deps` ([EXIT_STATUS]: 101)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s related to how many times foo rustc is called in this command. If it’s called only twice for one target, the panic error is caught as a warning. However, if it’s called again, it turns into a compile error and causes a bailout. Then the status becomes 101.
I’ll dig into it further. I’m not sure how we handle the compile error here, but I’ll take a look tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was suggesting that we keep .with_status(0) and remove --all-targets. This means we are still verifying that Cargo sets the correct status code and respects the --broken-code flag, treating it as a warning rather than an error.

Sorry for the confusion here. I thought I was using the .with_status(0) version, but I forgot I had reverted that change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I am suggesting: 44a91af (#15192)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with_status(0) is the default, so it should not be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thank you!

@0xPoe 0xPoe requested review from ehuss and epage April 15, 2025 09:15
… in cargo fix

Signed-off-by: Rustin170506 <techregister@pm.me>
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from 99745f0 to 75a8cdd Compare April 16, 2025 09:22
@0xPoe 0xPoe requested a review from epage April 17, 2025 08:06
@epage epage added the T-cargo Team: Cargo label Apr 17, 2025
@epage
Copy link
Contributor

epage commented Apr 17, 2025

@rcbot fcp merge

We previous discussed this as a team (#13527 (comment)) and agreed that changing the non---edition behavior seemed like the right call. This FCP is to official record that as we are making a behavior change.

Background:

cargo fix was developed with a focus on Editions which including running --all-targets by default so that you migrated your whole project. With RFC #3772 deprecating per-build-target editions, this makes even more sense.

However, it has grown to be a general way of applying fixes suggested by the compiler. In this situation, having cargo check and cargo fix or cargo clippy and cargo clippy --fix diverge in behavior does not make sense.

In considering this, we felt that the non-edition use of cargo fix / cargo --fix is unlikely to be used programmatically in a way negatively impacted by this change, considering it can't fully resolve all lints, it can only work in some situations (due to dirty vcs), and that it can generate broken code.

@0xPoe
Copy link
Member Author

0xPoe commented Apr 17, 2025

@rcbot fcp merge

@rfcbot fcp merge

See #15192 (comment)

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 17, 2025

Team member @Rustin170506 has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Apr 17, 2025
@ehuss ehuss moved this to FCP merge in Cargo status tracker Apr 22, 2025
@rfcbot rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Apr 22, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 22, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

Signed-off-by: Rustin170506 <techregister@pm.me>
@0xPoe 0xPoe force-pushed the rustin-patch-fix-targets branch from 44a91af to a6eb2bd Compare April 28, 2025 15:45
@rfcbot rfcbot added finished-final-comment-period FCP complete to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels May 2, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 2, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@epage
Copy link
Contributor

epage commented May 2, 2025

Thanks again @Rustin170506 !

@epage epage added this pull request to the merge queue May 2, 2025
Merged via the queue into rust-lang:master with commit 8b5c351 May 2, 2025
23 checks passed
@0xPoe
Copy link
Member Author

0xPoe commented May 4, 2025

Thanks for your review! 💚 💙 💜 💛 ❤️

@0xPoe 0xPoe deleted the rustin-patch-fix-targets branch May 4, 2025 09:13
bors added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2025
Update cargo

25 commits in 7918c7eb59614c39f1c4e27e99d557720976bdd7..056f5f4f3c100cb36b5e9aed2d20b9ea70aae295
2025-04-27 09:44:23 +0000 to 2025-05-09 14:54:18 +0000
- Revert "doc: Mention `XDG_DATA_HOME`" (rust-lang/cargo#15512)
- docs: update version notice for deprecation removal (rust-lang/cargo#15511)
- doc: Update instructions on using native-completions (rust-lang/cargo#15480)
- feat(network): use Retry-After header for HTTP 429 responses (rust-lang/cargo#15463)
- CI: Require schema job to pass (rust-lang/cargo#15504)
- chore(config): migrate renovate config (rust-lang/cargo#15501)
- Make cargo script ignore workspaces (rust-lang/cargo#15496)
- fix(rustc): Don't panic on unknown bins (rust-lang/cargo#15497)
- test: Remove unused nightly requirements (rust-lang/cargo#15498)
- Add support for `-Zembed-metadata` (rust-lang/cargo#15378)
- Fix tracking issue template link (rust-lang/cargo#15494)
- Refactor artifact deps in FeatureResolver::deps (rust-lang/cargo#15492)
- Improved error message for versions prefixed with `v` (rust-lang/cargo#15484)
- chore: fix some typos in comment (rust-lang/cargo#15485)
- fix: default to all targets when using `--edition` and ` --edition-idioms` in cargo fix (rust-lang/cargo#15192)
- Update fingerprint footnote (rust-lang/cargo#15478)
- feat(add): suggest similarly named features (rust-lang/cargo#15438)
- In package-workspace, keep dev-dependencies if they have a version (rust-lang/cargo#15470)
- docs: fix a typo in DependencyUI (rust-lang/cargo#15472)
- fix grammar, and remove confusing example (rust-lang/cargo#15457)
- Added tracing spans for rustc invocations (rust-lang/cargo#15464)
- Trivial tweaks to 'target_short_hash' (rust-lang/cargo#15461)
- chore(deps): update msrv (3 versions) to v1.84 (rust-lang/cargo#15456)
- feat(add/install): check if given crate argument would be valid with inserted @ symbol (rust-lang/cargo#15441)
- chang 1 tries to 1 try (rust-lang/cargo#15328)

r? ghost
@rustbot rustbot added this to the 1.89.0 milestone May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. Command-fix disposition-merge FCP with intent to merge finished-final-comment-period FCP complete S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo to-announce
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

cargo clippy and cargo clippy --fix --allow-dirty have different reports
6 participants