Skip to content

Wrong cargo fix output #113650

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

Open
SDesya74 opened this issue Jul 13, 2023 · 1 comment
Open

Wrong cargo fix output #113650

SDesya74 opened this issue Jul 13, 2023 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SDesya74
Copy link

SDesya74 commented Jul 13, 2023

I tried this code:

fn main() {
    let vec = Vec::<(usize,)>::new();
    let mut v: usize = 0;

    for (mut i,) in vec.iter() {
        foo(&mut v, i)
    }
}

fn foo<T>(_: &mut T, _: T) {}

Git repo for reproduction: https://github.com/SDesya74/rustfmt-err

I expected to see this happen: cargo removes mut and adds dereference to i.

Instead, this happened: cargo fix shows error:

Output

    Checking rustfmt-err v0.1.0 (/Users/me/dev/tests/rustfmt-err)
warning: failed to automatically apply fixes suggested by rustc to crate `rustfmt_err`

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[E0308]: mismatched types
  --> src/main.rs:6:21
   |
6  |         foo(&mut v, i)
   |         ---         ^ expected `usize`, found `&usize`
   |         |
   |         arguments to this function are incorrect
   |
note: function defined here
  --> src/main.rs:10:4
   |
10 | fn foo<T>(_: &mut T, _: T) {}
   |    ^^^               ----
help: consider dereferencing the borrow
   |
6  |         foo(&mut v, *i)
   |                     +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.

warning: variable does not need to be mutable
 --> src/main.rs:5:10
  |
5 |     for (mut i,) in vec.iter() {
  |          ----^
  |          |
  |          help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

warning: `rustfmt-err` (bin "rustfmt-err") generated 1 warning (run `cargo clippy --fix --bin "rustfmt-err"` to apply 1 suggestion)
warning: `rustfmt-err` (bin "rustfmt-err" test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: aarch64-apple-darwin
release: 1.70.0
LLVM version: 16.0.2
@SDesya74 SDesya74 added the C-bug Category: This is a bug. label Jul 13, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 13, 2023
@albertlarsan68 albertlarsan68 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jul 13, 2023
@clubby789 clubby789 removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 13, 2023
@lukas-code
Copy link
Member

This is another instance of #113451.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants