2022-10-01 16:59:17 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::as_ptr_cast_mut)]
|
2023-05-24 16:06:56 +00:00
|
|
|
#![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)]
|
2023-07-27 11:40:22 +00:00
|
|
|
//@no-rustfix
|
2022-10-01 16:59:17 +00:00
|
|
|
|
|
|
|
struct MutPtrWrapper(Vec<u8>);
|
|
|
|
impl MutPtrWrapper {
|
|
|
|
fn as_ptr(&mut self) -> *const u8 {
|
|
|
|
self.0.as_mut_ptr() as *const u8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Covariant<T>(*const T);
|
|
|
|
impl<T> Covariant<T> {
|
|
|
|
fn as_ptr(self) -> *const T {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut string = String::new();
|
|
|
|
let _ = string.as_ptr() as *mut u8;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: casting the result of `as_ptr` to *mut u8
|
|
|
|
//~| NOTE: `-D clippy::as-ptr-cast-mut` implied by `-D warnings`
|
2022-10-01 16:59:17 +00:00
|
|
|
let _: *mut i8 = string.as_ptr() as *mut _;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: casting the result of `as_ptr` to *mut i8
|
2022-10-01 16:59:17 +00:00
|
|
|
let _ = string.as_ptr() as *const i8;
|
|
|
|
let _ = string.as_mut_ptr();
|
|
|
|
let _ = string.as_mut_ptr() as *mut u8;
|
|
|
|
let _ = string.as_mut_ptr() as *const u8;
|
|
|
|
|
|
|
|
let nn = std::ptr::NonNull::new(4 as *mut u8).unwrap();
|
|
|
|
let _ = nn.as_ptr() as *mut u8;
|
|
|
|
|
|
|
|
let mut wrap = MutPtrWrapper(Vec::new());
|
|
|
|
let _ = wrap.as_ptr() as *mut u8;
|
|
|
|
|
|
|
|
let mut local = 4;
|
|
|
|
let ref_with_write_perm = Covariant(std::ptr::addr_of_mut!(local) as *const _);
|
|
|
|
let _ = ref_with_write_perm.as_ptr() as *mut u8;
|
|
|
|
}
|