@@ -5,7 +5,7 @@ import syntax::visit;
5
5
import syntax:: ast_util;
6
6
import driver:: session:: session;
7
7
8
- enum deref_t { unbox, field, index, }
8
+ enum deref_t { unbox( bool ) , field, index, }
9
9
10
10
type deref = @{ mut : bool , kind : deref_t , outer_t : ty:: t } ;
11
11
@@ -20,15 +20,15 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
20
20
while true {
21
21
alt ty:: struct ( tcx, t) {
22
22
ty:: ty_box ( mt) {
23
- ds += [ @{ mut: mt. mut == mut, kind: unbox, outer_t: t} ] ;
23
+ ds += [ @{ mut: mt. mut == mut, kind: unbox ( false ) , outer_t: t} ] ;
24
24
t = mt. ty ;
25
25
}
26
26
ty:: ty_uniq ( mt) {
27
- ds += [ @{ mut: mt. mut == mut, kind: unbox, outer_t: t} ] ;
27
+ ds += [ @{ mut: mt. mut == mut, kind: unbox ( false ) , outer_t: t} ] ;
28
28
t = mt. ty ;
29
29
}
30
30
ty:: ty_res ( _, inner, tps) {
31
- ds += [ @{ mut: false , kind: unbox, outer_t: t} ] ;
31
+ ds += [ @{ mut: false , kind: unbox ( false ) , outer_t: t} ] ;
32
32
t = ty:: substitute_type_params ( tcx, tps, inner) ;
33
33
}
34
34
ty:: ty_enum ( did, tps) {
@@ -37,7 +37,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
37
37
vec:: len ( variants[ 0 ] . args ) != 1 u {
38
38
break ;
39
39
}
40
- ds += [ @{ mut: false , kind: unbox, outer_t: t} ] ;
40
+ ds += [ @{ mut: false , kind: unbox ( false ) , outer_t: t} ] ;
41
41
t = ty:: substitute_type_params ( tcx, tps, variants[ 0 ] . args [ 0 ] ) ;
42
42
}
43
43
_ { break; }
@@ -85,15 +85,16 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
85
85
expr_unary ( op, base) {
86
86
if op == deref {
87
87
let base_t = ty:: expr_ty ( tcx, base) ;
88
- let is_mut = false ;
88
+ let is_mut = false , ptr = false ;
89
89
alt ty:: struct ( tcx, base_t) {
90
90
ty:: ty_box ( mt) { is_mut = mt. mut == mut; }
91
91
ty:: ty_uniq ( mt) { is_mut = mt. mut == mut; }
92
92
ty:: ty_res ( _, _, _) { }
93
93
ty:: ty_enum ( _, _) { }
94
- ty:: ty_ptr ( mt) { is_mut = mt. mut == mut; }
94
+ ty:: ty_ptr ( mt) { is_mut = mt. mut == mut; ptr = true ; }
95
95
}
96
- ds += [ @{ mut: is_mut, kind: unbox, outer_t: base_t} ] ;
96
+ ds += [ @{ mut: is_mut, kind: unbox ( ptr && is_mut) ,
97
+ outer_t: base_t} ] ;
97
98
ex = base;
98
99
} else { break; }
99
100
}
@@ -187,7 +188,7 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) {
187
188
} else if !root. ds [ 0 ] . mut {
188
189
let name =
189
190
alt root. ds [ 0 ] . kind {
190
- mut:: unbox { "immutable box" }
191
+ mut:: unbox ( _ ) { "immutable box" }
191
192
mut:: field { "immutable field" }
192
193
mut:: index { "immutable vec content" }
193
194
} ;
@@ -212,7 +213,8 @@ fn check_move_rhs(cx: @ctx, src: @expr) {
212
213
let root = expr_root( cx. tcx, src, false ) ;
213
214
214
215
// Not a path and no-derefs means this is a temporary.
215
- if vec:: len ( * root. ds ) != 0 u {
216
+ if vec:: len ( * root. ds ) != 0 u &&
217
+ root. ds[ vec:: len ( * root. ds ) - 1 u] . kind != unbox( true ) {
216
218
cx. tcx. sess. span_err( src. span, "moving out of a data structure" ) ;
217
219
}
218
220
}
0 commit comments