File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,10 +69,10 @@ impl CStr {
6969 /// Returns the length of this string with `NUL`.
7070 #[ inline]
7171 pub const fn len_with_nul ( & self ) -> usize {
72- // SAFETY: This is one of the invariant of `CStr`.
73- // We add a `unreachable_unchecked` here to hint the optimizer that
74- // the value returned from this function is non-zero.
7572 if self . 0 . is_empty ( ) {
73+ // SAFETY: This is one of the invariant of `CStr`.
74+ // We add a `unreachable_unchecked` here to hint the optimizer that
75+ // the value returned from this function is non-zero.
7676 unsafe { core:: hint:: unreachable_unchecked ( ) } ;
7777 }
7878 self . 0 . len ( )
@@ -208,6 +208,7 @@ impl CStr {
208208 /// ```
209209 #[ inline]
210210 pub unsafe fn as_str_unchecked ( & self ) -> & str {
211+ // SAFETY: Depends on the above safety contract
211212 unsafe { core:: str:: from_utf8_unchecked ( self . as_bytes ( ) ) }
212213 }
213214
You can’t perform that action at this time.
0 commit comments