]> git.lizzy.rs Git - rust.git/commitdiff
Remove feature `const_option` from std
authorChris Denton <christophersdenton@gmail.com>
Tue, 28 Jun 2022 10:37:48 +0000 (11:37 +0100)
committerChris Denton <christophersdenton@gmail.com>
Tue, 28 Jun 2022 10:37:48 +0000 (11:37 +0100)
library/std/src/lib.rs
library/std/src/sys/windows/args.rs

index 7da9f248c877a6c86773704a3fa8557c055958e5..65b8df429966329615eb3570e38c2d81a18698c6 100644 (file)
 #![feature(const_ip)]
 #![feature(const_ipv4)]
 #![feature(const_ipv6)]
-#![feature(const_option)]
 #![feature(const_socketaddr)]
 #![feature(thread_local_internals)]
 //
index c5918103fec254eb9d7ed6a7e23019ce07711594..361cf0590a17c00c21ff86667d88b8186ab3a88a 100644 (file)
 
 use core::iter;
 
+/// This is the const equivalent to `NonZeroU16::new(n).unwrap()`
+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 +66,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