Closed
Description
Problem
Running the command cargo fix
fails to fix the following minimal example:
fn foo() -> bool {
return(true);
}
fn main() {
println!("{}", foo());
}
and gives the following output
PS C:\Users\name\Documents\minimal example for cargo --fix bug\minimal-example> cargo fix
Checking minimal-example v0.1.0 (C:\Users\name\Documents\minimal example for cargo --fix bug\minimal-example)
warning: failed to automatically apply fixes suggested by rustc to crate `minimal_example`
after fixes were automatically applied the compiler reported errors within these files:
* src\main.rs
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:
error[E0425]: cannot find value `returntrue` in this scope
--> src\main.rs:2:5
|
2 | returntrue;
| ^^^^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> src\main.rs:1:13
|
| --- ^^^^ expected `bool`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
Original diagnostics will follow.
warning: unnecessary parentheses around `return` value
--> src\main.rs:2:11
|
2 | return(true);
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
2 - return(true);
2 + returntrue;
|
warning: `minimal-example` (bin "minimal-example") generated 1 warning (run `cargo fix --bin "minimal-example"` to apply 1 suggestion)
warning: `minimal-example` (bin "minimal-example" test) generated 1 warning (1 duplicate)
Finished dev [unoptimized + debuginfo] target(s) in 0.80s
PS C:\Users\name\Documents\minimal example for cargo --fix bug\minimal-example> cargo clippy --fix
Checking minimal-example v0.1.0 (C:\Users\name\Documents\minimal example for cargo --fix bug\minimal-example)
Fixed src\main.rs (2 fixes)
Finished dev [unoptimized + debuginfo] target(s) in 2.19s
Steps
- run
cargo init
- paste the code above into
main.rs
- run
cargo fix --allow-no-vcs
Possible Solution(s)
The fix command isn't adding a space where it should (in between return
and true
). If you add the space in, the bug does not occur.
fn foo() -> bool {
return(true); // produces bug
// return( true ); // produces bug
// return ( true ); // no bug
// return (true); // no bug
}
Notes
Running cargo clippy --fix
doesn't produce the same bug.
Version
Cargo version on my PC:
cargo 1.69.0 (6e9a83356 2023-04-12)
release: 1.69.0
commit-hash: 6e9a83356b70586d4b77613a6b33f9ea067b9cdf
commit-date: 2023-04-12
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Home) [64-bit]
PS C:\Users\name\Documents\minimal example for cargo --fix bug\minimal-example>
Cargo version on a Replit Rust Repl. (I was able to reproduce the bug there.)
cargo 1.64.0
release: 1.64.0
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.86.0 (sys:0.4.55+curl-7.83.1 system ssl:OpenSSL/3.0.7)
os: Ubuntu 20.4.0 [64-bit]