Skip to content

Commit 51793bd

Browse files
committed
Simplify control flow
1 parent 95bc720 commit 51793bd

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/librustc_mir/interpret/cast.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::ty::{self, Ty, TypeAndMut};
22
use rustc::ty::layout::{self, TyLayout, Size};
33
use rustc::ty::adjustment::{PointerCast};
4-
use syntax::ast::{FloatTy, IntTy, UintTy};
4+
use syntax::ast::FloatTy;
55
use syntax::symbol::sym;
66

77
use rustc_apfloat::ieee::{Single, Double};
@@ -248,18 +248,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
248248
// Casting to a reference or fn pointer is not permitted by rustc,
249249
// no need to support it here.
250250
RawPtr(_) => Ok(ptr.into()),
251-
Int(IntTy::Isize) | Uint(UintTy::Usize) => {
252-
if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) {
253-
self.cast_from_int(bits, src_layout, dest_layout)
254-
} else {
255-
Ok(ptr.into())
256-
}
257-
}
258251
Int(_) | Uint(_) => {
259-
if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) {
260-
self.cast_from_int(bits, src_layout, dest_layout)
261-
} else {
262-
err!(ReadPointerAsBytes)
252+
let size = self.memory.pointer_size();
253+
254+
match self.force_bits(Scalar::Ptr(ptr), size) {
255+
Ok(bits) => self.cast_from_int(bits, src_layout, dest_layout),
256+
Err(_) if dest_layout.size == size => Ok(ptr.into()),
257+
Err(e) => Err(e),
263258
}
264259
}
265260
_ => return err!(Unimplemented(format!("ptr to {:?} cast", dest_layout.ty))),

0 commit comments

Comments
 (0)