-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: master
Are you sure you want to change the base?
fix: default to all targets when using --edition
and --edition-idioms
in cargo fix
#15192
Conversation
c4933a5
to
d1c5bf8
Compare
60a57f7
to
e9ee015
Compare
--edition
and --edition-idioms
flags in cargo fix
--edition
and --edition-idioms
flags in cargo fix--edition
and --edition-idioms
in cargo fix
e9ee015
to
f0cd503
Compare
f0cd503
to
5a058c3
Compare
Signed-off-by: Rustin170506 <[email protected]>
a9f92ed
to
99745f0
Compare
tests/testsuite/fix.rs
Outdated
@@ -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") |
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.
As you said, this is suspicious and we should understand why in case there is a bad interaction happening
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.
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.
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.
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
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.
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)
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 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.
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.
How about we keep with_status? I think it’s still useful to verify whether we can catch the error and use the correct status code here when --broken-code
is specified.
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 don't really have much of an opinion either way. I could see that the test is primarily concerned about leaving the fixed result in place when the verification fails, and the 101 exit code is just a side-effect of doing an additional (possibly unexpected) call to rustc. But it also seems fine to verify that it keeps the broken output in that case, too.
If you leave --all-targets
, I would recommend leaving a comment as to why.
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.
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.
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 what I am suggesting: 44a91af
(#15192)
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.
👍
… in cargo fix Signed-off-by: Rustin170506 <[email protected]>
99745f0
to
75a8cdd
Compare
Signed-off-by: Rustin170506 <[email protected]>
@rcbot fcp merge We previous discussed this as a team (#13527 (comment)) and agreed that changing the non- Background:
However, it has grown to be a general way of applying fixes suggested by the compiler. In this situation, having In considering this, we felt that the non-edition use of |
@rfcbot fcp merge See #15192 (comment) |
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. |
What does this PR try to resolve?
Close #13527
As we discussed,
cargo fix
should use the default target selection withcargo check
.In this PR, I modified
cargo fix
to no longer use all targets by default. Forcargo fix --edition
andcargo 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