You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cargo fix makes it hard to discover the --broken-code option. Running cargo fix when there are compile errors gives no hints about this option, and it's not terribly obvious from cargo help fix either. I'm sure there are users missing out on cargo fix as a result -- I certainly was :)
Steps
Given a library crate with src/lib.rs containing:
fn takes_ref(_x: &usize) {}
pub fn call_it() {
let i = 1usize;
takes_ref(i); // oops
}
I get the following output:
$ cargo fix --allow-dirty
Checking mylib v0.1.0 (/tmp/mylib)
error[E0308]: mismatched types
--> src/lib.rs:5:15
|
5 | takes_ref(i); // oops
| --------- ^ expected `&usize`, found `usize`
| |
| arguments to this function are incorrect
|
note: function defined here
--> src/lib.rs:1:4
|
1 | fn takes_ref(_x: &usize) {}
| ^^^^^^^^^ ----------
help: consider borrowing here
|
5 | takes_ref(&i); // oops
| +
For more information about this error, try `rustc --explain E0308`.
error: could not compile `mylib` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `mylib` (lib) due to 1 previous error
This is really confusing: rustc knows how to fix my code, it says so, and yet cargo fix isn't doing anything.
Possible Solution(s)
Ideally, there'd be a hint:
note: `cargo fix` requires `--broken-code` to apply suggestions when there are compiler errors.
(Whilst this is potentially a destructive option, cargo fix already suggests other destructive options like --allow-dirty.)
The output of cargo help fix is:
NAME
cargo-fix — Automatically fix lint warnings reported by rustc
SYNOPSIS
cargo fix [options]
DESCRIPTION
This Cargo subcommand will automatically take rustc’s suggestions from diagnostics like warnings and apply them to your source code. This is intended to help automate tasks that
rustc itself already knows how to tell you to fix!
This wording isn't ideal. "Automatically fix lint warnings" suggests that cargo fix can only do lints. On the other hand, "automatically take rustc’s suggestions diagnostics like warnings" suggests that cargo fix will do more than just warnings.
The description doesn't actually mention --broken-code, nor is this flag shown in the EXAMPLES section of the help.
Notes
I apologise if this seems super nitpicky! For a long time I didn't realise that cargo fix --broken-code could do exactly what I wanted (just apply all rustc suggestions), so I figured I'd report an issue.
Version
$ cargo version --verbose
cargo 1.84.0 (66221abde 2024-11-19)
The text was updated successfully, but these errors were encountered:
Historically, we've not been too confident in the suggestions when errors are present. If we had --interactive support (#11125), then we could offer the user every suggestion, whether there is an error, or if the suggestion is marked as a maybe applicable.
We also have some UX issues around --broken-code, see #10955.
Granted, sometimes the only way to get something to be improved is to make it front and center.
Problem
cargo fix
makes it hard to discover the--broken-code
option. Runningcargo fix
when there are compile errors gives no hints about this option, and it's not terribly obvious fromcargo help fix
either. I'm sure there are users missing out oncargo fix
as a result -- I certainly was :)Steps
Given a library crate with
src/lib.rs
containing:I get the following output:
This is really confusing: rustc knows how to fix my code, it says so, and yet
cargo fix
isn't doing anything.Possible Solution(s)
Ideally, there'd be a hint:
(Whilst this is potentially a destructive option,
cargo fix
already suggests other destructive options like--allow-dirty
.)The output of
cargo help fix
is:This wording isn't ideal. "Automatically fix lint warnings" suggests that
cargo fix
can only do lints. On the other hand, "automatically take rustc’s suggestions diagnostics like warnings" suggests thatcargo fix
will do more than just warnings.The description doesn't actually mention
--broken-code
, nor is this flag shown in the EXAMPLES section of the help.Notes
I apologise if this seems super nitpicky! For a long time I didn't realise that
cargo fix --broken-code
could do exactly what I wanted (just apply all rustc suggestions), so I figured I'd report an issue.Version
The text was updated successfully, but these errors were encountered: