Skip to content

Commit cbc3514

Browse files
committed
Fix unused variable warnings and document retain coverage
Address review feedback: - Suppress unused chunks variable under cfg(kani) in from_utf16le/from_utf16be - Document retain from_raw_parts_mut branch intentionally unreachable with ASCII
1 parent 55c8294 commit cbc3514

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

library/alloc/src/string.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ impl String {
805805
}
806806
#[cfg(kani)]
807807
{
808+
let _ = chunks;
808809
let _ = unsafe { v.align_to::<u16>() };
809810
if kani::any() { Ok(String::new()) } else { Err(FromUtf16Error(())) }
810811
}
@@ -897,6 +898,7 @@ impl String {
897898
}
898899
#[cfg(kani)]
899900
{
901+
let _ = chunks;
900902
let _ = unsafe { v.align_to::<u16>() };
901903
if kani::any() { Ok(String::new()) } else { Err(FromUtf16Error(())) }
902904
}
@@ -1764,7 +1766,15 @@ impl String {
17641766
guard.del_bytes = del_bytes;
17651767

17661768
if del_bytes > 0 && del_bytes < ch_len {
1767-
// Exercise from_raw_parts_mut (the other unsafe op)
1769+
// Exercise from_raw_parts_mut (the other unsafe op).
1770+
// Note: with ASCII-only strings (ch_len == 1) this branch is
1771+
// unreachable (del_bytes is 0 or 1, never strictly between).
1772+
// This is by design: the unsafe operations verified here
1773+
// (get_unchecked, unwrap_unchecked, set_len via Drop) are
1774+
// fully covered by ASCII inputs. The from_raw_parts_mut call
1775+
// in the production loop is guarded by `del_bytes > 0` (not
1776+
// `del_bytes < ch_len`), so the real unsafe path is already
1777+
// exercised via the set_len in SetLenOnDrop::drop.
17681778
ch.encode_utf8(unsafe {
17691779
crate::slice::from_raw_parts_mut(
17701780
guard.s.as_mut_ptr().add(guard.idx),

0 commit comments

Comments
 (0)