about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-06-28 18:34:33 +0200
committerGitHub <noreply@github.com>2022-06-28 18:34:33 +0200
commita3bdd46431d0baf25c2bef85a05fd6c1238459c7 (patch)
tree3f8eff6b0e3c96ccb1e7f8681216eed351e314af /library/std/src/sys
parent956a9f55c0e1b45605975d565848da089897a853 (diff)
parent720c430822ab093449d495487cc103b39bcf9f4a (diff)
downloadrust-a3bdd46431d0baf25c2bef85a05fd6c1238459c7.tar.gz
rust-a3bdd46431d0baf25c2bef85a05fd6c1238459c7.zip
Rollup merge of #98617 - ChrisDenton:const-unwrap, r=Mark-Simulacrum
Remove feature `const_option` from std

This is part of the effort to reduce the number of unstable features used by std. This one is easy as it's only used in one place.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/windows/args.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/library/std/src/sys/windows/args.rs b/library/std/src/sys/windows/args.rs
index c5918103fec..01f26298290 100644
--- a/library/std/src/sys/windows/args.rs
+++ b/library/std/src/sys/windows/args.rs
@@ -21,6 +21,17 @@ use crate::vec;
 
 use core::iter;
 
+/// This is the const equivalent to `NonZeroU16::new(n).unwrap()`
+///
+/// FIXME: This can be removed once `Option::unwrap` is stably const.
+/// See the `const_option` feature (#67441).
+const fn non_zero_u16(n: u16) -> NonZeroU16 {
+    match NonZeroU16::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.
@@ -58,10 +69,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
     lp_cmd_line: Option<WStrUnits<'a>>,
     exe_name: F,
 ) -> Vec<OsString> {
-    const BACKSLASH: NonZeroU16 = NonZeroU16::new(b'\\' as u16).unwrap();
-    const QUOTE: NonZeroU16 = NonZeroU16::new(b'"' as u16).unwrap();
-    const TAB: NonZeroU16 = NonZeroU16::new(b'\t' as u16).unwrap();
-    const SPACE: NonZeroU16 = NonZeroU16::new(b' ' as u16).unwrap();
+    const BACKSLASH: NonZeroU16 = non_zero_u16(b'\\' as u16);
+    const QUOTE: NonZeroU16 = non_zero_u16(b'"' as u16);
+    const TAB: NonZeroU16 = non_zero_u16(b'\t' as u16);
+    const SPACE: NonZeroU16 = non_zero_u16(b' ' as u16);
 
     let mut ret_val = Vec::new();
     // If the cmd line pointer is null or it points to an empty string then