-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix: default to all targets when using --edition
and --edition-idioms
in cargo fix
#15192
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]>
5a058c3
to
a9f92ed
Compare
… in cargo fix Signed-off-by: Rustin170506 <[email protected]>
a9f92ed
to
99745f0
Compare
@@ -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.
I think this change is reasonable. The test returns a 101 status because rustc was called three times. The first time, it attempts to fix build.rs with no errors. The second time, it tries to fix src/lib.rs, where there is one error, but we have a mechanism to output the errors as warnings when --broekn-code
was specified.
Lines 720 to 723 in 99745f0
// Exit with whatever exit code we initially started with. `cargo fix` | |
// treats this as a warning, and shouldn't return a failure code | |
// unless the code didn't compile in the first place. | |
exit_with(fixes.first_output.status); |
The third time, it attempts to fix src/lib.rs again, but since no fixes are needed, the panic error is displayed directly, resulting in the 101 status.
Line 695 in 99745f0
if fixes.files.is_empty() { |
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 we should remove --all-target. The status 0 is expected here
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.
@ehuss any idea what this test should be doing?
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