Skip to content
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

clippy --fix "failed to automatically apply fixes suggested by rustc" #13470

Open
tommythorn opened this issue Sep 28, 2024 · 1 comment
Open
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@tommythorn
Copy link

Summary

Thanks for the wonderful Clippy. I hope this bug report is helpful.

I have a C library that was translated by C2Rust and heavily cleaned up by hand. Alas, the terrible code that you (understandably) get from C2Rust seems to break Clippy's --fix option.

Reproducer

To reproduce: git clone https://github.com/tommythorn/repro-clippy-bug;cd repro-clippy-bug;cargo clippy --fix

With Rust 1.81.0 (eeb90cda1 2024-09-04) on macOS (but I think this happens on Linux also) I get

warning: failed to automatically apply fixes suggested by rustc to crate `repro_clippy_bug`

after fixes were automatically applied the compiler reported errors within these files:

  * src/softfloat/f128_to_f16.rs
  * src/softfloat/f16_div.rs
  * src/softfloat/f16_mul.rs
  * src/softfloat/f16_roundToInt.rs
  * src/softfloat/f32_to_f16.rs
  * src/softfloat/f64_to_f16.rs
  * src/softfloat/s_addMagsF16.rs
  * src/softfloat/s_mulAddF16.rs
  * src/softfloat/s_subMagsF16.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-clippy/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:
warning: operator precedence can trip the unwary
  --> src/softfloat/f16_roundToInt.rs:22:15
   |
22 |           uiZ = uiA
   |  _______________^
23 | |             & ((1_i32 as u16 as i32) << 15_i32) + ((0_i32 as u16 as i32) << 10_i32)
24 | |                 as u64;
   | |______________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence
   = note: `#[warn(clippy::precedence)]` on by default
help: consider parenthesizing your expression
   |
22 ~         uiZ = uiA & (((1_i32 as u16 as i32) << 15_i32) + ((0_i32 as u16 as i32) << 10_i32)
23 ~                 as u64);
   |
.... and a *LOT* more of this

Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Additional Labels

No response

@tommythorn tommythorn added the C-bug Category: Clippy is not doing the correct thing label Sep 28, 2024
@tommythorn
Copy link
Author

I recognize the irony of quoting a truncated message that asks for the full output, so I attached it here.
clippy.out.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant