Skip to content

Commit 6169a1a

Browse files
committed
use fallible convertions for Pos trait
1 parent 41ba864 commit 6169a1a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/rustc_span/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,22 +1860,22 @@ macro_rules! impl_pos {
18601860
impl Pos for $ident {
18611861
#[inline(always)]
18621862
fn from_usize(n: usize) -> $ident {
1863-
$ident(n as $inner_ty)
1863+
$ident(<$inner_ty>::try_from(n).unwrap())
18641864
}
18651865

18661866
#[inline(always)]
18671867
fn to_usize(&self) -> usize {
1868-
self.0 as usize
1868+
self.0.try_into().unwrap()
18691869
}
18701870

18711871
#[inline(always)]
18721872
fn from_u32(n: u32) -> $ident {
1873-
$ident(n as $inner_ty)
1873+
$ident(<$inner_ty>::try_from(n).unwrap())
18741874
}
18751875

18761876
#[inline(always)]
18771877
fn to_u32(&self) -> u32 {
1878-
self.0 as u32
1878+
self.0.try_into().unwrap()
18791879
}
18801880
}
18811881

0 commit comments

Comments
 (0)