2022-10-22 10:03:12 +00:00
|
|
|
#![warn(clippy::from_raw_with_void_ptr)]
|
2023-05-24 15:53:31 +00:00
|
|
|
#![allow(clippy::unnecessary_cast)]
|
2022-10-22 10:03:12 +00:00
|
|
|
|
|
|
|
use std::ffi::c_void;
|
2022-10-23 19:14:52 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
2022-10-22 10:03:12 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// must lint
|
|
|
|
let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
|
|
|
|
let _ = unsafe { Box::from_raw(ptr) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: creating a `Box` from a void raw pointer
|
2022-10-22 10:03:12 +00:00
|
|
|
|
|
|
|
// shouldn't be linted
|
|
|
|
let _ = unsafe { Box::from_raw(ptr as *mut usize) };
|
|
|
|
|
|
|
|
// shouldn't be linted
|
|
|
|
let should_not_lint_ptr = Box::into_raw(Box::new(12u8)) as *mut u8;
|
|
|
|
let _ = unsafe { Box::from_raw(should_not_lint_ptr as *mut u8) };
|
2022-10-23 19:14:52 +00:00
|
|
|
|
|
|
|
// must lint
|
|
|
|
let ptr = Rc::into_raw(Rc::new(42usize)) as *mut c_void;
|
|
|
|
let _ = unsafe { Rc::from_raw(ptr) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: creating a `Rc` from a void raw pointer
|
2022-10-23 19:14:52 +00:00
|
|
|
|
|
|
|
// must lint
|
|
|
|
let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void;
|
|
|
|
let _ = unsafe { Arc::from_raw(ptr) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: creating a `Arc` from a void raw pointer
|
2022-10-23 19:14:52 +00:00
|
|
|
|
|
|
|
// must lint
|
|
|
|
let ptr = std::rc::Weak::into_raw(Rc::downgrade(&Rc::new(42usize))) as *mut c_void;
|
|
|
|
let _ = unsafe { std::rc::Weak::from_raw(ptr) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: creating a `Weak` from a void raw pointer
|
2022-10-23 19:14:52 +00:00
|
|
|
|
|
|
|
// must lint
|
|
|
|
let ptr = std::sync::Weak::into_raw(Arc::downgrade(&Arc::new(42usize))) as *mut c_void;
|
|
|
|
let _ = unsafe { std::sync::Weak::from_raw(ptr) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: creating a `Weak` from a void raw pointer
|
2022-10-22 10:03:12 +00:00
|
|
|
}
|