File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,10 +72,10 @@ impl CStr {
7272 /// Returns the length of this string with `NUL`.
7373 #[ inline]
7474 pub const fn len_with_nul ( & self ) -> usize {
75- // SAFETY: This is one of the invariant of `CStr`.
76- // We add a `unreachable_unchecked` here to hint the optimizer that
77- // the value returned from this function is non-zero.
7875 if self . 0 . is_empty ( ) {
76+ // SAFETY: This is one of the invariant of `CStr`.
77+ // We add a `unreachable_unchecked` here to hint the optimizer that
78+ // the value returned from this function is non-zero.
7979 unsafe { core:: hint:: unreachable_unchecked ( ) } ;
8080 }
8181 self . 0 . len ( )
@@ -198,6 +198,7 @@ impl CStr {
198198 /// ```
199199 #[ inline]
200200 pub unsafe fn as_str_unchecked ( & self ) -> & str {
201+ // SAFETY: Depends on the above safety contract
201202 unsafe { core:: str:: from_utf8_unchecked ( self . as_bytes ( ) ) }
202203 }
203204
You can’t perform that action at this time.
0 commit comments