Closed
Description
Summary
.
Lint Name
borrow_as_ptr
Reproducer
I tried this code:
enum Foo {}
impl Drop for Foo {
fn drop(&mut self) {}
}
fn main() {
unsafe { std::ptr::read(&1u8 as *const u8 as *const Foo) };
}
I saw this happen:
cargo clippy --fix -- -Wclippy::borrow_as_ptr
warning: failed to automatically apply fixes suggested by rustc to crate `a`
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[E0745]: cannot take address of a temporary
--> src/main.rs:7:48
|
7 | unsafe { std::ptr::read(std::ptr::addr_of!(1u8) as *const Foo) };
| ^^^ temporary value
error: aborting due to previous error
For more information about this error, try `rustc --explain E0745`.
Original diagnostics will follow.
warning: borrow as raw pointer
--> src/main.rs:7:29
|
7 | unsafe { std::ptr::read(&1u8 as *const u8 as *const Foo) };
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of!(1u8)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
= note: requested on the command line with `-W clippy::borrow-as-ptr`
warning: `a` (bin "a") generated 1 warning (run `cargo fix --bin "a"` to apply 1 suggestion)
warning: `a` (bin "a" test) generated 1 warning (1 duplicate)
Version
rustc 1.67.0-nightly (b833ad56f 2022-11-18)
binary: rustc
commit-hash: b833ad56f46a0bbe0e8729512812a161e7dae28a
commit-date: 2022-11-18
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
No response