Use try block instead of closure
This commit is contained in:
parent
06aaea1d6b
commit
b06f0d16a9
@ -530,17 +530,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
let nanoseconds_scalar = this.read_scalar(nanoseconds_place.into())?;
|
let nanoseconds_scalar = this.read_scalar(nanoseconds_place.into())?;
|
||||||
let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?;
|
let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?;
|
||||||
|
|
||||||
Ok((move || {
|
Ok(try {
|
||||||
// tv_sec must be non-negative.
|
// tv_sec must be non-negative.
|
||||||
let seconds: u64 = seconds.try_into().ok()?;
|
let seconds: u64 = seconds.try_into().ok()?;
|
||||||
// tv_nsec must be non-negative.
|
// tv_nsec must be non-negative.
|
||||||
let nanoseconds: u32 = nanoseconds.try_into().ok()?;
|
let nanoseconds: u32 = nanoseconds.try_into().ok()?;
|
||||||
if nanoseconds >= 1_000_000_000 {
|
if nanoseconds >= 1_000_000_000 {
|
||||||
// tv_nsec must not be greater than 999,999,999.
|
// tv_nsec must not be greater than 999,999,999.
|
||||||
return None;
|
None?
|
||||||
}
|
}
|
||||||
Some(Duration::new(seconds, nanoseconds))
|
Duration::new(seconds, nanoseconds)
|
||||||
})())
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#![feature(map_first_last)]
|
#![feature(map_first_last)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(or_patterns)]
|
#![feature(or_patterns)]
|
||||||
|
#![feature(try_blocks)]
|
||||||
|
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![allow(clippy::cast_lossless)]
|
#![allow(clippy::cast_lossless)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user