Skip to content

Commit a3bdd46

Browse files
authored
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.
2 parents 956a9f5 + 720c430 commit a3bdd46

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
#![feature(const_ip)]
336336
#![feature(const_ipv4)]
337337
#![feature(const_ipv6)]
338-
#![feature(const_option)]
339338
#![feature(const_socketaddr)]
340339
#![feature(thread_local_internals)]
341340
//

library/std/src/sys/windows/args.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ use crate::vec;
2121

2222
use core::iter;
2323

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+
2435
pub fn args() -> Args {
2536
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
2637
// string so it's safe for `WStrUnits` to use.
@@ -58,10 +69,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
5869
lp_cmd_line: Option<WStrUnits<'a>>,
5970
exe_name: F,
6071
) -> 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);
6576

6677
let mut ret_val = Vec::new();
6778
// If the cmd line pointer is null or it points to an empty string then

0 commit comments

Comments
 (0)