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

Incorrect fix: immediately dereferencing a reference to a literal as a place expression. #13423

Open
iago-lito opened this issue Sep 19, 2024 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@iago-lito
Copy link

iago-lito commented Sep 19, 2024

Summary

This corner case triggers an incorrect fix suggestion, leading to a compilation error.

Reproducer

main.rs

fn main() {
    *&mut 4 = 5; // /!\ immediately dereferencing a reference
//  ^^^^^^^ help: try: `4`
}

@Kyuuhachi Assigns to a temporary that is then dropped [1]

$ cargo clippy --fix --allow-dirty --allow-no-vcs
    Checking rust_test v0.1.0 (./tests/rust)
warning: failed to automatically apply fixes suggested by rustc to crate `rust_test`

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-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:
error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:2:7
  |
2 |     4 = 5;
  |     - ^
  |     |
  |     cannot assign to this expression

error: aborting due to 1 previous error

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

Version

$ rustc -Vv                                                                                                                                                                                          
rustc 1.83.0-nightly (f79a912d9 2024-09-18)
binary: rustc
commit-hash: f79a912d9edc3ad4db910c0e93672ed5c65133fa
commit-date: 2024-09-18
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
@iago-lito iago-lito added the C-bug Category: Clippy is not doing the correct thing label Sep 19, 2024
@alex-semenyuk
Copy link
Member

@iago-lito issue description looks incomplete

@iago-lito
Copy link
Author

iago-lito commented Sep 20, 2024

@alex-semenyuk Sorry, is it better now?

@lukaslueg
Copy link
Contributor

Same as #12319 ?!

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

3 participants