diff options
| author | George Bateman <george.bateman16@gmail.com> | 2024-10-14 20:47:24 +0100 |
|---|---|---|
| committer | George Bateman <george.bateman16@gmail.com> | 2024-10-14 20:50:40 +0100 |
| commit | 4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38 (patch) | |
| tree | 8d572d6a1a00754a0c12e3f562747cfd5289e78d /library/std/src | |
| parent | 17a19e684cdf3ca088af8b4da6a6209d128913f4 (diff) | |
| download | rust-4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38.tar.gz rust-4e438f7d6b7f6fbf2bb0c1ffe6ffe0b6bfc7fa38.zip | |
Fix two const-hacks
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/pal/windows/args.rs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/library/std/src/sys/pal/windows/args.rs b/library/std/src/sys/pal/windows/args.rs index 848632ec2a7..e9fc19bcb99 100644 --- a/library/std/src/sys/pal/windows/args.rs +++ b/library/std/src/sys/pal/windows/args.rs @@ -18,17 +18,6 @@ use crate::sys_common::AsInner; use crate::sys_common::wstr::WStrUnits; use crate::{fmt, io, iter, vec}; -/// This is the const equivalent to `NonZero::new(n).unwrap()` -/// -/// FIXME(const-hack): This can be removed once `Option::unwrap` is stably const. -/// See the `const_option` feature (#67441). -const fn non_zero_u16(n: u16) -> NonZero<u16> { - match NonZero::new(n) { - Some(n) => n, - None => panic!("called `unwrap` on a `None` value"), - } -} - pub fn args() -> Args { // SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16 // string so it's safe for `WStrUnits` to use. @@ -66,10 +55,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>( lp_cmd_line: Option<WStrUnits<'a>>, exe_name: F, ) -> Vec<OsString> { - const BACKSLASH: NonZero<u16> = non_zero_u16(b'\\' as u16); - const QUOTE: NonZero<u16> = non_zero_u16(b'"' as u16); - const TAB: NonZero<u16> = non_zero_u16(b'\t' as u16); - const SPACE: NonZero<u16> = non_zero_u16(b' ' as u16); + const BACKSLASH: NonZero<u16> = NonZero::new(b'\\' as u16).unwrap(); + const QUOTE: NonZero<u16> = NonZero::new(b'"' as u16).unwrap(); + const TAB: NonZero<u16> = NonZero::new(b'\t' as u16).unwrap(); + const SPACE: NonZero<u16> = NonZero::new(b' ' as u16).unwrap(); let mut ret_val = Vec::new(); // If the cmd line pointer is null or it points to an empty string then |
