@@ -38,7 +38,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
38
38
dest : PlaceTy < ' tcx , M :: PointerTag > ,
39
39
) -> EvalResult < ' tcx > {
40
40
let src_layout = src. layout ;
41
- let dst_layout = dest. layout ;
42
41
use rustc:: mir:: CastKind :: * ;
43
42
match kind {
44
43
Unsize => {
@@ -47,7 +46,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
47
46
48
47
Misc => {
49
48
let src = self . read_value ( src) ?;
50
- if self . type_is_fat_ptr ( src_layout. ty ) {
49
+
50
+ if src. layout . ty . is_region_ptr ( ) && dest. layout . ty . is_unsafe_ptr ( ) {
51
+ // For the purpose of the "ptr tag hooks", treat this as creating
52
+ // a new, raw reference.
53
+ let place = self . ref_to_mplace ( src) ?;
54
+ let _val = self . create_ref ( place, None ) ?;
55
+ // FIXME: The blog post said we should now also erase the tag.
56
+ // That would amount to using `_val` instead of `src` from here on.
57
+ // However, do we really want to do that? `transmute` doesn't
58
+ // do it either and we have to support that, somehow.
59
+ }
60
+
61
+ if self . type_is_fat_ptr ( src. layout . ty ) {
51
62
match ( * src, self . type_is_fat_ptr ( dest. layout . ty ) ) {
52
63
// pointers to extern types
53
64
( Value :: Scalar ( _) , _) |
@@ -65,11 +76,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
65
76
match src_layout. variants {
66
77
layout:: Variants :: Single { index } => {
67
78
if let Some ( def) = src_layout. ty . ty_adt_def ( ) {
79
+ // Cast from a univariant enum
80
+ assert ! ( src. layout. is_zst( ) ) ;
68
81
let discr_val = def
69
82
. discriminant_for_variant ( * self . tcx , index)
70
83
. val ;
71
84
return self . write_scalar (
72
- Scalar :: from_uint ( discr_val, dst_layout . size ) ,
85
+ Scalar :: from_uint ( discr_val, dest . layout . size ) ,
73
86
dest) ;
74
87
}
75
88
}
@@ -85,7 +98,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
85
98
86
99
ReifyFnPointer => {
87
100
// The src operand does not matter, just its type
88
- match src_layout . ty . sty {
101
+ match src . layout . ty . sty {
89
102
ty:: FnDef ( def_id, substs) => {
90
103
if self . tcx . has_attr ( def_id, "rustc_args_required_const" ) {
91
104
bug ! ( "reifying a fn ptr that requires \
@@ -117,7 +130,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
117
130
118
131
ClosureFnPointer => {
119
132
// The src operand does not matter, just its type
120
- match src_layout . ty . sty {
133
+ match src . layout . ty . sty {
121
134
ty:: Closure ( def_id, substs) => {
122
135
let substs = self . tcx . subst_and_normalize_erasing_regions (
123
136
self . substs ( ) ,
0 commit comments