rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Clippy Error during auto fix

Open asze17 opened this issue 3 years ago • 0 comments

Clippy reported error during auto fix

❯ cargo clippy --workspace --all-features --fix --allow-dirty --broken-code  -- -D clippy::all -D clippy::pedantic -D clippy::nursery -D clippy::cargo
    Checking ril v0.1.0 (C:\Users\alvin\OneDrive\Desktop\repos\ril)
warning: failed to automatically apply fixes suggested by rustc to crate `ril`

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

  * src\encode.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[E0699]: the type of this value must be known to call a method on a raw pointer on it
  --> src\encode.rs:55:37
   |
55 |         unsafe { (data as *const _).cast::<T>().read() }
   |                                     ^^^^

error: aborting due to previous error

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

error[E0699]: the type of this value must be known to call a method on a raw pointer on it
  --> src\encode.rs:55:37
   |
55 |         unsafe { (data as *const _).cast::<T>().read() }
   |                                     ^^^^

For more information about this error, try `rustc --explain E0699`.
error: could not compile `ril` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `ril` due to previous error

Original code is

unsafe { (data as *const _ as *const T).read() }

Clippy attempted to change it to

unsafe { (data as *const _).cast::<T>().read() }

which leads to an error

Note: data is &[u8]

rustc --version --verbose

rustc 1.64.0-nightly (7b46aa594 2022-07-05)
binary: rustc
commit-hash: 7b46aa594c4bdc507fbd904b6777ca30c37a9209
commit-date: 2022-07-05
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6

The lint that likely caused it

error: `as` casting between raw pointers without changing its mutability
  --> src\encode.rs:55:18
   |
55 |         unsafe { (data as *const _ as *const T).read() }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(data as *const _).cast::<T>()`
   |
   = note: `-D clippy::ptr-as-ptr` implied by `-D clippy::pedantic`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr

asze17 avatar Jul 26 '22 22:07 asze17