File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -525,11 +525,15 @@ impl OsStr {
525525
526526 #[ inline]
527527 fn from_inner ( inner : & Slice ) -> & OsStr {
528+ // Safety: OsStr is just a wrapper of Slice,
529+ // therefore converting &Slice to &OsStr is safe.
528530 unsafe { & * ( inner as * const Slice as * const OsStr ) }
529531 }
530532
531533 #[ inline]
532534 fn from_inner_mut ( inner : & mut Slice ) -> & mut OsStr {
535+ // Safety: OsStr is just a wrapper of Slice,
536+ // therefore converting &mut Slice to &mut OsStr is safe.
533537 unsafe { & mut * ( inner as * mut Slice as * mut OsStr ) }
534538 }
535539
Original file line number Diff line number Diff line change @@ -77,11 +77,17 @@ impl Buf {
7777 }
7878
7979 pub fn as_slice ( & self ) -> & Slice {
80+ // Safety: Slice is just a wrapper for Wtf8,
81+ // and as_slice returns &Wtf8. Therefore,
82+ // transmute &Wtf8 to &Slice is safe.
8083 unsafe { mem:: transmute ( self . inner . as_slice ( ) ) }
8184 }
8285
8386 #[ inline]
8487 pub fn as_mut_slice ( & mut self ) -> & mut Slice {
88+ // Safety: Slice is just a wrapper for Wtf8,
89+ // and as_slice returns &Wtf8. Therefore,
90+ // transmute &mut Wtf8 to &mut Slice is safe.
8591 unsafe { mem:: transmute ( self . inner . as_mut_slice ( ) ) }
8692 }
8793
Original file line number Diff line number Diff line change @@ -106,11 +106,17 @@ impl Buf {
106106
107107 #[ inline]
108108 pub fn as_slice ( & self ) -> & Slice {
109+ // Safety: Slice just wraps [u8],
110+ // and &*self.inner is &[u8], therefore
111+ // transmuting &[u8] to &Slice is safe.
109112 unsafe { mem:: transmute ( & * self . inner ) }
110113 }
111114
112115 #[ inline]
113116 pub fn as_mut_slice ( & mut self ) -> & mut Slice {
117+ // Safety: Slice just wraps [u8],
118+ // and &mut *self.inner is &mut [u8], therefore
119+ // transmuting &mut [u8] to &mut Slice is safe.
114120 unsafe { mem:: transmute ( & mut * self . inner ) }
115121 }
116122
You can’t perform that action at this time.
0 commit comments