core/intrinsics/
bounds.rs

1//! Various traits used to restrict intrinsics to not-completely-wrong types.
2
3/// Types with a built-in dereference operator in runtime MIR,
4/// aka references and raw pointers.
5///
6/// # Safety
7/// Must actually *be* such a type.
8pub unsafe trait BuiltinDeref: Sized {
9    type Pointee: ?Sized;
10}
11
12unsafe impl<T: ?Sized> BuiltinDeref for &mut T {
13    type Pointee = T;
14}
15unsafe impl<T: ?Sized> BuiltinDeref for &T {
16    type Pointee = T;
17}
18unsafe impl<T: ?Sized> BuiltinDeref for *mut T {
19    type Pointee = T;
20}
21unsafe impl<T: ?Sized> BuiltinDeref for *const T {
22    type Pointee = T;
23}
24
25pub trait ChangePointee<U: ?Sized>: BuiltinDeref {
26    type Output;
27}
28impl<'a, T: ?Sized + 'a, U: ?Sized + 'a> ChangePointee<U> for &'a mut T {
29    type Output = &'a mut U;
30}
31impl<'a, T: ?Sized + 'a, U: ?Sized + 'a> ChangePointee<U> for &'a T {
32    type Output = &'a U;
33}
34impl<T: ?Sized, U: ?Sized> ChangePointee<U> for *mut T {
35    type Output = *mut U;
36}
37impl<T: ?Sized, U: ?Sized> ChangePointee<U> for *const T {
38    type Output = *const U;
39}