mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Use try_into instead of asserting manually
This commit is contained in:
@@ -753,11 +753,7 @@ pub fn count(&self) -> usize {
|
||||
match *self {
|
||||
FieldsShape::Primitive => 0,
|
||||
FieldsShape::Union(count) => count.get(),
|
||||
FieldsShape::Array { count, .. } => {
|
||||
let usize_count = count as usize;
|
||||
assert_eq!(usize_count as u64, count);
|
||||
usize_count
|
||||
}
|
||||
FieldsShape::Array { count, .. } => count.try_into().unwrap(),
|
||||
FieldsShape::Arbitrary { ref offsets, .. } => offsets.len(),
|
||||
}
|
||||
}
|
||||
@@ -791,11 +787,7 @@ pub fn memory_index(&self, i: usize) -> usize {
|
||||
unreachable!("FieldsShape::memory_index: `Primitive`s have no fields")
|
||||
}
|
||||
FieldsShape::Union(_) | FieldsShape::Array { .. } => i,
|
||||
FieldsShape::Arbitrary { ref memory_index, .. } => {
|
||||
let r = memory_index[i];
|
||||
assert_eq!(r as usize as u32, r);
|
||||
r as usize
|
||||
}
|
||||
FieldsShape::Arbitrary { ref memory_index, .. } => memory_index[i].try_into().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user