summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-03-09 06:38:53 +0100
committerGitHub <noreply@github.com>2022-03-09 06:38:53 +0100
commit28d06bdec9412bc0c744d656f3965aa74f8da72a (patch)
treec4d773055a52b57f8a2f2876e4c4d45009e9a3c5 /library/std/src
parent4de06d459fd26e21874e79d41ed29576e87951c7 (diff)
parent57442beb18a056f4ec098812a941393cdc67bbee (diff)
downloadrust-28d06bdec9412bc0c744d656f3965aa74f8da72a.tar.gz
rust-28d06bdec9412bc0c744d656f3965aa74f8da72a.zip
Rollup merge of #94756 - ChrisDenton:unreachable, r=yaahc
Use `unreachable!` for an unreachable code path

Closes #73212
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/windows/mod.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs
index dc288176346..6097e628768 100644
--- a/library/std/src/sys/windows/mod.rs
+++ b/library/std/src/sys/windows/mod.rs
@@ -224,8 +224,14 @@ where
             } as usize;
             if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER {
                 n *= 2;
-            } else if k >= n {
+            } else if k > n {
                 n = k;
+            } else if k == n {
+                // It is impossible to reach this point.
+                // On success, k is the returned string length excluding the null.
+                // On failure, k is the required buffer length including the null.
+                // Therefore k never equals n.
+                unreachable!();
             } else {
                 return Ok(f2(&buf[..k]));
             }