File tree 1 file changed +9
-0
lines changed
compiler/rustc_middle/src/query
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,13 @@ pub fn erase<T: EraseType>(src: T) -> Erase<T> {
30
30
} ;
31
31
32
32
Erased :: < <T as EraseType >:: Result > {
33
+ // `transmute_unchecked` is needed here because it does not have `transmute`'s size check
34
+ // (and thus allows to transmute between `T`` and `MaybeUninit<T::Result>`) (we do the size
35
+ // check ourselves in the `const` block above).
36
+ //
37
+ // `transmute_copy` is also commonly used for this (and it would work here since
38
+ // `EraseType: Copy`), but `transmute_unchecked` better explains the intent.
39
+ //
33
40
// SAFETY: It is safe to transmute to MaybeUninit for types with the same sizes.
34
41
data : unsafe { transmute_unchecked :: < T , MaybeUninit < T :: Result > > ( src) } ,
35
42
}
@@ -39,6 +46,8 @@ pub fn erase<T: EraseType>(src: T) -> Erase<T> {
39
46
#[ inline( always) ]
40
47
pub fn restore < T : EraseType > ( value : Erase < T > ) -> T {
41
48
let value: Erased < <T as EraseType >:: Result > = value;
49
+ // See comment in `erase` for why we use `transmute_unchecked`.
50
+ //
42
51
// SAFETY: Due to the use of impl Trait in `Erase` the only way to safely create an instance
43
52
// of `Erase` is to call `erase`, so we know that `value.data` is a valid instance of `T` of
44
53
// the right size.
You can’t perform that action at this time.
0 commit comments