Skip to content

Commit 5dd0375

Browse files
committed
turn casts-to-raw into a proper raw-reborrow; that is just cleaner
1 parent c885d8b commit 5dd0375

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/librustc_mir/interpret/cast.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,35 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
3737
kind: CastKind,
3838
dest: PlaceTy<'tcx, M::PointerTag>,
3939
) -> EvalResult<'tcx> {
40-
let src_layout = src.layout;
4140
use rustc::mir::CastKind::*;
4241
match kind {
4342
Unsize => {
4443
self.unsize_into(src, dest)?;
4544
}
4645

4746
Misc => {
47+
let src_layout = src.layout;
4848
let src = self.read_value(src)?;
4949

50-
if M::ENABLE_PTR_TRACKING_HOOKS &&
51-
src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr()
52-
{
50+
let src = if M::ENABLE_PTR_TRACKING_HOOKS && src_layout.ty.is_region_ptr() {
51+
// The only `Misc` casts on references are those creating raw pointers.
52+
assert!(dest.layout.ty.is_unsafe_ptr());
5353
// For the purpose of the "ptr tag hooks", treat this as creating
5454
// a new, raw reference.
5555
let place = self.ref_to_mplace(src)?;
56-
let _val = self.create_ref(place, None)?;
57-
// FIXME: The blog post said we should now also erase the tag.
58-
// That would amount to using `_val` instead of `src` from here on.
59-
// However, do we really want to do that? `transmute` doesn't
60-
// do it either and we have to support that, somehow.
61-
}
56+
self.create_ref(place, None)?
57+
} else {
58+
*src
59+
};
6260

63-
if self.type_is_fat_ptr(src.layout.ty) {
64-
match (*src, self.type_is_fat_ptr(dest.layout.ty)) {
61+
if self.type_is_fat_ptr(src_layout.ty) {
62+
match (src, self.type_is_fat_ptr(dest.layout.ty)) {
6563
// pointers to extern types
6664
(Value::Scalar(_),_) |
6765
// slices and trait objects to other slices/trait objects
6866
(Value::ScalarPair(..), true) => {
6967
// No change to value
70-
self.write_value(*src, dest)?;
68+
self.write_value(src, dest)?;
7169
}
7270
// slices and trait objects to thin pointers (dropping the metadata)
7371
(Value::ScalarPair(data, _), false) => {
@@ -79,7 +77,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
7977
layout::Variants::Single { index } => {
8078
if let Some(def) = src_layout.ty.ty_adt_def() {
8179
// Cast from a univariant enum
82-
assert!(src.layout.is_zst());
80+
assert!(src_layout.is_zst());
8381
let discr_val = def
8482
.discriminant_for_variant(*self.tcx, index)
8583
.val;

0 commit comments

Comments
 (0)