Lines Matching defs:unsafe
35 //! ## Nightly needed for `unsafe-pinned` feature
51 //! - using the unsafe function [`pin_init_from_closure()`] to manually create an initializer.
160 //! [`pin_init_from_closure()`] comes in. This `unsafe` function allows you to create a
211 //! unsafe {
239 //! unsafe { bindings::destroy_foo(self.foo.get().cast::<bindings::foo>()) };
279 all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
339 /// # mod bindings { pub struct info; pub unsafe fn destroy_info(_: *mut info) {} }
358 /// unsafe { bindings::destroy_info(self.raw_info) };
373 /// # mod bindings { pub struct info; pub unsafe fn destroy_info(_: *mut info) {} }
392 /// unsafe { bindings::destroy_info(self.raw_info) };
769 /// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() },
799 /// IMPORTANT: if you have `unsafe` code inside of the initializer you have to ensure that when
856 /// - `unsafe` code must guarantee either full initialization or return an error and allow
907 /// - `unsafe` code must guarantee either full initialization or return an error and allow
1003 /// unsafe { self.map_unchecked_mut(|me| &mut me.elem) }
1012 let data = unsafe { <$ty as $crate::__internal::HasPinData>::__pin_data() };
1015 unsafe { data.$field(ptr, init) }.ok();
1057 pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
1066 unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>;
1101 unsafe impl<T: ?Sized, E, I, F> PinInit<T, E> for ChainPinInit<I, F, T, E>
1106 unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
1108 unsafe { self.0.__pinned_init(slot)? };
1110 let val = unsafe { &mut *slot };
1112 let val = unsafe { Pin::new_unchecked(val) };
1114 (self.1)(val).inspect_err(|_| unsafe { core::ptr::drop_in_place(slot) })
1156 pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
1164 unsafe fn __init(self, slot: *mut T) -> Result<(), E>;
1208 unsafe impl<T: ?Sized, E, I, F> Init<T, E> for ChainInit<I, F, T, E>
1213 unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
1215 unsafe { self.0.__pinned_init(slot)? };
1217 (self.1)(unsafe { &mut *slot }).inspect_err(|_|
1219 unsafe { core::ptr::drop_in_place(slot) })
1224 unsafe impl<T: ?Sized, E, I, F> PinInit<T, E> for ChainInit<I, F, T, E>
1229 unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
1231 unsafe { self.__init(slot) }
1248 pub const unsafe fn pin_init_from_closure<T: ?Sized, E>(
1267 pub const unsafe fn init_from_closure<T: ?Sized, E>(
1280 pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl PinInit<U, E> {
1283 let res = unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.cast::<T>())) };
1296 pub const unsafe fn cast_init<T, U, E>(init: impl Init<T, E>) -> impl Init<U, E> {
1299 let res = unsafe { init_from_closure(|ptr: *mut U| init.__init(ptr.cast::<T>())) };
1311 unsafe { init_from_closure(|_| Ok(())) }
1335 let ptr = unsafe { slot.add(i) };
1338 if let Err(e) = unsafe { init.__init(ptr) } {
1341 unsafe { ptr::drop_in_place(ptr::slice_from_raw_parts_mut(slot, i)) };
1349 unsafe { init_from_closure(init) }
1378 let ptr = unsafe { slot.add(i) };
1381 if let Err(e) = unsafe { init.__pinned_init(ptr) } {
1384 unsafe { ptr::drop_in_place(ptr::slice_from_raw_parts_mut(slot, i)) };
1392 unsafe { pin_init_from_closure(init) }
1396 unsafe impl<T> Init<T> for T {
1397 unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible> {
1399 unsafe { slot.write(self) };
1406 unsafe impl<T> PinInit<T> for T {
1407 unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible> {
1409 unsafe { slot.write(self) };
1417 unsafe impl<T, E> Init<T, E> for Result<T, E> {
1418 unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
1420 unsafe { slot.write(self?) };
1428 unsafe impl<T, E> PinInit<T, E> for Result<T, E> {
1429 unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
1431 unsafe { slot.write(self?) };
1478 pub unsafe trait PinnedDrop: __internal::HasPinData {
1481 /// While this function is marked safe, it is actually unsafe to call it manually. For this
1482 /// reason it takes an additional parameter. This type can only be constructed by `unsafe` code
1498 /// let val: Self = unsafe { core::mem::zeroed() };
1500 pub unsafe trait Zeroable {
1545 /// The implementer needs to ensure that `unsafe impl Zeroable for Option<Self> {}` is sound.
1546 pub unsafe trait ZeroableOption {}
1549 unsafe impl<T: ZeroableOption> Zeroable for Option<T> {}
1553 unsafe impl<T> ZeroableOption for &T {}
1556 unsafe impl<T> ZeroableOption for &mut T {}
1559 unsafe impl<T> ZeroableOption for NonNull<T> {}
1568 unsafe {
1598 unsafe { core::mem::zeroed() }
1604 $(unsafe impl$($($generics)*)? Zeroable for $t {})*
1660 unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
1670 $(impl_fn_zeroable_option!({unsafe extern $abi} $args);)*
1676 unsafe impl<$ret, $($rest),*> ZeroableOption for $($prefix)* fn($($rest),*) -> $ret {}
1716 unsafe { cast_pin_init(value_init) }
1723 unsafe { cast_pin_init(value_init) }
1727 #[cfg(all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED))]
1731 unsafe { cast_pin_init(init) }