@@ -37,37 +37,35 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
37
37
kind : CastKind ,
38
38
dest : PlaceTy < ' tcx , M :: PointerTag > ,
39
39
) -> EvalResult < ' tcx > {
40
- let src_layout = src. layout ;
41
40
use rustc:: mir:: CastKind :: * ;
42
41
match kind {
43
42
Unsize => {
44
43
self . unsize_into ( src, dest) ?;
45
44
}
46
45
47
46
Misc => {
47
+ let src_layout = src. layout ;
48
48
let src = self . read_value ( src) ?;
49
49
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 ( ) ) ;
53
53
// For the purpose of the "ptr tag hooks", treat this as creating
54
54
// a new, raw reference.
55
55
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
+ } ;
62
60
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 ) ) {
65
63
// pointers to extern types
66
64
( Value :: Scalar ( _) , _) |
67
65
// slices and trait objects to other slices/trait objects
68
66
( Value :: ScalarPair ( ..) , true ) => {
69
67
// No change to value
70
- self . write_value ( * src, dest) ?;
68
+ self . write_value ( src, dest) ?;
71
69
}
72
70
// slices and trait objects to thin pointers (dropping the metadata)
73
71
( Value :: ScalarPair ( data, _) , false ) => {
@@ -79,7 +77,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
79
77
layout:: Variants :: Single { index } => {
80
78
if let Some ( def) = src_layout. ty . ty_adt_def ( ) {
81
79
// Cast from a univariant enum
82
- assert ! ( src . layout . is_zst( ) ) ;
80
+ assert ! ( src_layout . is_zst( ) ) ;
83
81
let discr_val = def
84
82
. discriminant_for_variant ( * self . tcx , index)
85
83
. val ;
0 commit comments