From 57442beb18a056f4ec098812a941393cdc67bbee Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 9 Mar 2022 00:47:24 +0000 Subject: [PATCH] Use `unreachable!` for an unreachable code path --- library/std/src/sys/windows/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> crate::io::Result } 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])); }