Use try block instead of closure

This commit is contained in:
David Cook 2020-09-07 15:09:34 -05:00
parent 06aaea1d6b
commit b06f0d16a9
2 changed files with 5 additions and 4 deletions

View File

@ -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 = nanoseconds_scalar.to_machine_isize(this)?;
Ok((move || {
Ok(try {
// tv_sec must be non-negative.
let seconds: u64 = seconds.try_into().ok()?;
// tv_nsec must be non-negative.
let nanoseconds: u32 = nanoseconds.try_into().ok()?;
if nanoseconds >= 1_000_000_000 {
// tv_nsec must not be greater than 999,999,999.
return None;
None?
}
Some(Duration::new(seconds, nanoseconds))
})())
Duration::new(seconds, nanoseconds)
})
}
}

View File

@ -3,6 +3,7 @@
#![feature(map_first_last)]
#![feature(never_type)]
#![feature(or_patterns)]
#![feature(try_blocks)]
#![warn(rust_2018_idioms)]
#![allow(clippy::cast_lossless)]