Skip to content

Commit 4e438f7

Browse files
committed
Fix two const-hacks
1 parent 17a19e6 commit 4e438f7

2 files changed

Lines changed: 7 additions & 20 deletions

File tree

‎library/core/src/time.rs‎

Lines changed: 3 additions & 5 deletions
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)asu64){
218-
Some(secs) => secs,
219-
None => panic!("overflow in Duration::new"),
220-
};
216+
let secs = secs
217+
.checked_add((nanos / NANOS_PER_SEC)asu64)
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)}}

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ use crate::sys_common::AsInner;
1818
usecrate::sys_common::wstr::WStrUnits;
1919
usecrate::{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-
constfnnon_zero_u16(n:u16) -> NonZero<u16>{
26-
matchNonZero::new(n){
27-
Some(n) => n,
28-
None => panic!("called `unwrap` on a `None` value"),
29-
}
30-
}
31-
3221
pubfnargs() -> 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-
constBACKSLASH:NonZero<u16> = non_zero_u16(b'\\'asu16);
70-
constQUOTE:NonZero<u16> = non_zero_u16(b'"'asu16);
71-
constTAB:NonZero<u16> = non_zero_u16(b'\t'asu16);
72-
constSPACE:NonZero<u16> = non_zero_u16(b' 'asu16);
58+
constBACKSLASH:NonZero<u16> = NonZero::new(b'\\'asu16).unwrap();
59+
constQUOTE:NonZero<u16> = NonZero::new(b'"'asu16).unwrap();
60+
constTAB:NonZero<u16> = NonZero::new(b'\t'asu16).unwrap();
61+
constSPACE:NonZero<u16> = NonZero::new(b' 'asu16).unwrap();
7362

7463
letmut 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)