Skip to content

Commit 63f3836

Browse files
committed
Fix two const-hacks
1 parent 843c9e9 commit 63f3836

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

core/src/time.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,9 @@ impl Duration {
213213
// SAFETY: nanos < NANOS_PER_SEC, therefore nanos is within the valid range
214214
Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
215215
} else {
216-
// FIXME(const-hack): use `.expect` once that is possible.
217-
let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
218-
Some(secs) => secs,
219-
None => panic!("overflow in Duration::new"),
220-
};
216+
let secs = secs
217+
.checked_add((nanos / NANOS_PER_SEC) as u64)
218+
.expect("overflow in Duration::new");
221219
let nanos = nanos % NANOS_PER_SEC;
222220
// SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
223221
Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }

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

+4-15
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ use crate::sys_common::AsInner;
1818
use crate::sys_common::wstr::WStrUnits;
1919
use crate::{fmt, io, iter, vec};
2020

21-
/// This is the const equivalent to `NonZero::new(n).unwrap()`
22-
///
23-
/// FIXME(const-hack): This can be removed once `Option::unwrap` is stably const.
24-
/// See the `const_option` feature (#67441).
25-
const fn non_zero_u16(n: u16) -> NonZero<u16> {
26-
match NonZero::new(n) {
27-
Some(n) => n,
28-
None => panic!("called `unwrap` on a `None` value"),
29-
}
30-
}
31-
3221
pub fn args() -> Args {
3322
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
3423
// string so it's safe for `WStrUnits` to use.
@@ -66,10 +55,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
6655
lp_cmd_line: Option<WStrUnits<'a>>,
6756
exe_name: F,
6857
) -> Vec<OsString> {
69-
const BACKSLASH: NonZero<u16> = non_zero_u16(b'\\' as u16);
70-
const QUOTE: NonZero<u16> = non_zero_u16(b'"' as u16);
71-
const TAB: NonZero<u16> = non_zero_u16(b'\t' as u16);
72-
const SPACE: NonZero<u16> = non_zero_u16(b' ' as u16);
58+
const BACKSLASH: NonZero<u16> = NonZero::new(b'\\' as u16).unwrap();
59+
const QUOTE: NonZero<u16> = NonZero::new(b'"' as u16).unwrap();
60+
const TAB: NonZero<u16> = NonZero::new(b'\t' as u16).unwrap();
61+
const SPACE: NonZero<u16> = NonZero::new(b' ' as u16).unwrap();
7362

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

0 commit comments

Comments
 (0)