Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28d06bd

Browse files
authoredMar 9, 2022
Rollup merge of rust-lang#94756 - ChrisDenton:unreachable, r=yaahc
Use `unreachable!` for an unreachable code path Closes rust-lang#73212
2 parents 4de06d4 + 57442be commit 28d06bd

File tree

1 file changed

+7
-1
lines changed
  • library/std/src/sys/windows

1 file changed

+7
-1
lines changed
 

‎library/std/src/sys/windows/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ where
224224
} as usize;
225225
if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER {
226226
n *= 2;
227-
} else if k >= n {
227+
} else if k > n {
228228
n = k;
229+
} else if k == n {
230+
// It is impossible to reach this point.
231+
// On success, k is the returned string length excluding the null.
232+
// On failure, k is the required buffer length including the null.
233+
// Therefore k never equals n.
234+
unreachable!();
229235
} else {
230236
return Ok(f2(&buf[..k]));
231237
}

0 commit comments

Comments
 (0)
Please sign in to comment.