File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 335
335
#![ feature( const_ip) ]
336
336
#![ feature( const_ipv4) ]
337
337
#![ feature( const_ipv6) ]
338
- #![ feature( const_option) ]
339
338
#![ feature( const_socketaddr) ]
340
339
#![ feature( thread_local_internals) ]
341
340
//
Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ use crate::vec;
21
21
22
22
use core:: iter;
23
23
24
+ /// This is the const equivalent to `NonZeroU16::new(n).unwrap()`
25
+ ///
26
+ /// FIXME: This can be removed once `Option::unwrap` is stably const.
27
+ /// See the `const_option` feature (#67441).
28
+ const fn non_zero_u16 ( n : u16 ) -> NonZeroU16 {
29
+ match NonZeroU16 :: new ( n) {
30
+ Some ( n) => n,
31
+ None => panic ! ( "called `unwrap` on a `None` value" ) ,
32
+ }
33
+ }
34
+
24
35
pub fn args ( ) -> Args {
25
36
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
26
37
// string so it's safe for `WStrUnits` to use.
@@ -58,10 +69,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
58
69
lp_cmd_line : Option < WStrUnits < ' a > > ,
59
70
exe_name : F ,
60
71
) -> Vec < OsString > {
61
- const BACKSLASH : NonZeroU16 = NonZeroU16 :: new ( b'\\' as u16 ) . unwrap ( ) ;
62
- const QUOTE : NonZeroU16 = NonZeroU16 :: new ( b'"' as u16 ) . unwrap ( ) ;
63
- const TAB : NonZeroU16 = NonZeroU16 :: new ( b'\t' as u16 ) . unwrap ( ) ;
64
- const SPACE : NonZeroU16 = NonZeroU16 :: new ( b' ' as u16 ) . unwrap ( ) ;
72
+ const BACKSLASH : NonZeroU16 = non_zero_u16 ( b'\\' as u16 ) ;
73
+ const QUOTE : NonZeroU16 = non_zero_u16 ( b'"' as u16 ) ;
74
+ const TAB : NonZeroU16 = non_zero_u16 ( b'\t' as u16 ) ;
75
+ const SPACE : NonZeroU16 = non_zero_u16 ( b' ' as u16 ) ;
65
76
66
77
let mut ret_val = Vec :: new ( ) ;
67
78
// If the cmd line pointer is null or it points to an empty string then
You can’t perform that action at this time.
0 commit comments