mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 05:57:03 +03:00
Make From implementations non-failing.
This commit is contained in:
+4
-2
@@ -1,3 +1,5 @@
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::*;
|
||||
use rustc_target::abi::LayoutOf;
|
||||
|
||||
@@ -63,7 +65,7 @@ fn pthread_join(
|
||||
}
|
||||
|
||||
let thread_id = this.read_scalar(thread)?.to_machine_usize(this)?;
|
||||
this.join_thread(thread_id.into())?;
|
||||
this.join_thread(thread_id.try_into().expect("thread ID should fit in u32"))?;
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
@@ -72,7 +74,7 @@ fn pthread_detach(&mut self, thread: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32>
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let thread_id = this.read_scalar(thread)?.to_machine_usize(this)?;
|
||||
this.detach_thread(thread_id.into())?;
|
||||
this.detach_thread(thread_id.try_into().expect("thread ID should fit in u32"))?;
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
+7
-5
@@ -3,7 +3,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
use std::num::NonZeroU32;
|
||||
use std::num::{NonZeroU32, TryFromIntError};
|
||||
|
||||
use log::trace;
|
||||
|
||||
@@ -45,20 +45,22 @@ impl Idx for ThreadId {
|
||||
fn new(idx: usize) -> Self {
|
||||
ThreadId(u32::try_from(idx).unwrap())
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
usize::try_from(self.0).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for ThreadId {
|
||||
fn from(id: u64) -> Self {
|
||||
Self(u32::try_from(id).unwrap())
|
||||
impl TryFrom<u64> for ThreadId {
|
||||
type Error = TryFromIntError;
|
||||
fn try_from(id: u64) -> Result<Self, Self::Error> {
|
||||
u32::try_from(id).map(|id_u32| Self(id_u32))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for ThreadId {
|
||||
fn from(id: u32) -> Self {
|
||||
Self(u32::try_from(id).unwrap())
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user