(x: T)
| 51 | } |
| 52 | |
| 53 | const fn zst_ref_out_of_thin_air<T: 'static>(x: T) -> &'static T { |
| 54 | // if T is zero-sized, there's no issue forgetting it - even if it does have a Drop impl, it |
| 55 | // would never get called anyway if we consider this semantically a Box::leak(Box::new(x))-type |
| 56 | // operation. if T isn't zero-sized, we don't have to worry about it because we'll fail to compile. |
| 57 | core::mem::forget(x); |
| 58 | const { |
| 59 | if core::mem::size_of::<T>() != 0 { |
| 60 | panic!("can't use a non-zero-sized type here") |
| 61 | } |
| 62 | // SAFETY: we just confirmed that T is zero-sized, so we can |
| 63 | // pull a value of it out of thin air. |
| 64 | unsafe { core::ptr::NonNull::<T>::dangling().as_ref() } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /// Get the STATIC_FUNC of the passed function. The same |
| 69 | /// requirements of zero-sized-ness apply, see that documentation for details. |
no test coverage detected