@@ -79,73 +79,69 @@ fn to_ares<T>(+c: cres<T>) -> ares {
79
79
}
80
80
}
81
81
82
- // Note: Assign is not actually a combiner, in that it does not
82
+ // Note: Coerce is not actually a combiner, in that it does not
83
83
// conform to the same interface, though it performs a similar
84
84
// function.
85
- enum Assign = CombineFields ;
85
+ pub enum Coerce = CombineFields ;
86
86
87
- impl Assign {
88
- fn tys ( a : ty:: t , b : ty:: t ) -> ares {
89
- debug ! ( "Assign .tys(%s => %s)" ,
87
+ impl Coerce {
88
+ fn tys ( & self , a: ty:: t, b: ty:: t) -> ares {
89
+ debug!( "Coerce .tys(%s => %s)" ,
90
90
a. inf_str ( self . infcx ) ,
91
91
b. inf_str ( self . infcx ) ) ;
92
- let _r = indenter ( ) ;
93
-
94
- debug ! ( "Assign.tys: copying first type" ) ;
95
- let copy_a = copy ty:: get ( a) . sty ;
96
- debug ! ( "Assign.tys: copying second type" ) ;
97
- let copy_b = copy ty:: get ( b) . sty ;
98
- debug ! ( "Assign.tys: performing match" ) ;
99
-
100
- let r = match ( copy_a, copy_b) {
101
- ( ty:: ty_bot, _) => {
92
+ let _indent = indenter ( ) ;
93
+ let r = match ( & ty:: get ( a) . sty , & ty:: get ( b) . sty ) {
94
+ ( & ty:: ty_bot, _) => {
102
95
Ok ( None )
103
96
}
104
97
105
- ( ty:: ty_infer( TyVar ( a_id) ) , ty:: ty_infer( TyVar ( b_id) ) ) => {
98
+ ( & ty:: ty_infer( TyVar ( a_id) ) , & ty:: ty_infer( TyVar ( b_id) ) ) => {
106
99
let nde_a = self . infcx . get ( a_id) ;
107
100
let nde_b = self . infcx . get ( b_id) ;
108
101
let a_bounds = nde_a. possible_types ;
109
102
let b_bounds = nde_b. possible_types ;
110
103
111
104
let a_bnd = option:: or ( a_bounds. ub , a_bounds. lb ) ;
112
105
let b_bnd = option:: or ( b_bounds. lb , b_bounds. ub ) ;
113
- self . assign_tys_or_sub ( a, b, a_bnd, b_bnd)
106
+ self . coerce_tys_or_sub ( a, b, a_bnd, b_bnd)
114
107
}
115
108
116
- ( ty:: ty_infer( TyVar ( a_id) ) , _) => {
109
+ ( & ty:: ty_infer( TyVar ( a_id) ) , _) => {
117
110
let nde_a = self . infcx . get ( a_id) ;
118
111
let a_bounds = nde_a. possible_types ;
119
112
120
113
let a_bnd = option:: or ( a_bounds. ub , a_bounds. lb ) ;
121
- self . assign_tys_or_sub ( a, b, a_bnd, Some ( b) )
114
+ self . coerce_tys_or_sub ( a, b, a_bnd, Some ( b) )
122
115
}
123
116
124
- ( _, ty:: ty_infer( TyVar ( b_id) ) ) => {
117
+ ( _, & ty:: ty_infer( TyVar ( b_id) ) ) => {
125
118
let nde_b = self . infcx . get ( b_id) ;
126
119
let b_bounds = nde_b. possible_types ;
127
120
128
121
let b_bnd = option:: or ( b_bounds. lb , b_bounds. ub ) ;
129
- self . assign_tys_or_sub ( a, b, Some ( a) , b_bnd)
122
+ self . coerce_tys_or_sub ( a, b, Some ( a) , b_bnd)
130
123
}
131
124
132
125
( _, _) => {
133
- self . assign_tys_or_sub ( a, b, Some ( a) , Some ( b) )
126
+ self . coerce_tys_or_sub ( a, b, Some ( a) , Some ( b) )
134
127
}
135
128
} ;
136
129
137
- debug ! ( "Assign .tys end" ) ;
130
+ debug ! ( "Coerce .tys end" ) ;
138
131
139
132
move r
140
133
}
141
134
}
142
135
143
- priv impl Assign {
144
- fn assign_tys_or_sub (
145
- a : ty:: t , b : ty:: t ,
146
- +a_bnd : Option < ty:: t > , +b_bnd : Option < ty:: t > ) -> ares {
147
-
148
- debug ! ( "Assign.assign_tys_or_sub(%s => %s, %s => %s)" ,
136
+ impl Coerce {
137
+ fn coerce_tys_or_sub (
138
+ & self ,
139
+ +a : ty:: t ,
140
+ +b : ty:: t ,
141
+ +a_bnd : Option < ty:: t > ,
142
+ +b_bnd : Option < ty:: t > ) -> ares
143
+ {
144
+ debug ! ( "Coerce.coerce_tys_or_sub(%s => %s, %s => %s)" ,
149
145
a. inf_str( self . infcx) , b. inf_str( self . infcx) ,
150
146
a_bnd. inf_str( self . infcx) , b_bnd. inf_str( self . infcx) ) ;
151
147
let _r = indenter ( ) ;
@@ -167,59 +163,58 @@ priv impl Assign {
167
163
168
164
match ( a_bnd, b_bnd) {
169
165
( Some ( a_bnd) , Some ( b_bnd) ) => {
170
- match ( /*bad*/ copy ty:: get ( a_bnd) . sty ,
171
- /*bad*/ copy ty:: get ( b_bnd) . sty ) {
166
+ match ( & ty:: get ( a_bnd) . sty , & ty:: get ( b_bnd) . sty ) {
172
167
// check for a case where a non-region pointer (@, ~) is
173
- // being assigned to a region pointer:
174
- ( ty:: ty_box( _) , ty:: ty_rptr( r_b, mt_b) ) => {
168
+ // being coerceed to a region pointer:
169
+ ( & ty:: ty_box( _) , & ty:: ty_rptr( r_b, mt_b) ) => {
175
170
let nr_b = ty:: mk_box ( self . infcx . tcx ,
176
171
ty:: mt { ty : mt_b. ty ,
177
172
mutbl : m_const} ) ;
178
- self . try_assign ( 1 , ty:: AutoPtr ,
173
+ self . try_coerce ( 1 , ty:: AutoPtr ,
179
174
a, nr_b,
180
175
mt_b. mutbl , r_b)
181
176
}
182
- ( ty:: ty_uniq( _) , ty:: ty_rptr( r_b, mt_b) ) => {
177
+ ( & ty:: ty_uniq( _) , & ty:: ty_rptr( r_b, mt_b) ) => {
183
178
let nr_b = ty:: mk_uniq ( self . infcx . tcx ,
184
179
ty:: mt { ty : mt_b. ty ,
185
180
mutbl : m_const} ) ;
186
- self . try_assign ( 1 , ty:: AutoPtr ,
181
+ self . try_coerce ( 1 , ty:: AutoPtr ,
187
182
a, nr_b,
188
183
mt_b. mutbl , r_b)
189
184
}
190
- ( ty:: ty_estr( vs_a) ,
191
- ty:: ty_estr( ty:: vstore_slice( r_b) ) )
185
+ ( & ty:: ty_estr( vs_a) ,
186
+ & ty:: ty_estr( ty:: vstore_slice( r_b) ) )
192
187
if is_borrowable ( vs_a) => {
193
188
let nr_b = ty:: mk_estr ( self . infcx . tcx , vs_a) ;
194
- self . try_assign ( 0 , ty:: AutoBorrowVec ,
189
+ self . try_coerce ( 0 , ty:: AutoBorrowVec ,
195
190
a, nr_b,
196
191
m_imm, r_b)
197
192
}
198
193
199
- ( ty:: ty_evec( _, vs_a) ,
200
- ty:: ty_evec( mt_b, ty:: vstore_slice( r_b) ) )
194
+ ( & ty:: ty_evec( _, vs_a) ,
195
+ & ty:: ty_evec( mt_b, ty:: vstore_slice( r_b) ) )
201
196
if is_borrowable ( vs_a) => {
202
197
let nr_b = ty:: mk_evec ( self . infcx . tcx ,
203
198
ty:: mt { ty : mt_b. ty ,
204
199
mutbl : m_const} ,
205
200
vs_a) ;
206
- self . try_assign ( 0 , ty:: AutoBorrowVec ,
201
+ self . try_coerce ( 0 , ty:: AutoBorrowVec ,
207
202
a, nr_b,
208
203
mt_b. mutbl , r_b)
209
204
}
210
205
211
- ( ty:: ty_fn( ref a_f) , ty:: ty_fn( ref b_f) )
206
+ ( & ty:: ty_fn( ref a_f) , & ty:: ty_fn( ref b_f) )
212
207
if borrowable_protos ( a_f. meta . proto , b_f. meta . proto ) => {
213
208
let nr_b = ty:: mk_fn ( self . infcx . tcx , ty:: FnTyBase {
214
209
meta : ty:: FnMeta { proto : a_f. meta . proto ,
215
210
..b_f. meta } ,
216
211
sig : copy b_f. sig
217
212
} ) ;
218
- self . try_assign ( 0 , ty:: AutoBorrowFn ,
213
+ self . try_coerce ( 0 , ty:: AutoBorrowFn ,
219
214
a, nr_b, m_imm, b_f. meta . region )
220
215
}
221
216
222
- ( ty:: ty_fn( ref a_f) , ty:: ty_fn( ref b_f) )
217
+ ( & ty:: ty_fn( ref a_f) , & ty:: ty_fn( ref b_f) )
223
218
if a_f. meta . proto == ast:: ProtoBare => {
224
219
let b1_f = ty:: FnTyBase {
225
220
meta : ty:: FnMeta { proto : ast:: ProtoBare ,
@@ -229,49 +224,50 @@ priv impl Assign {
229
224
// Eventually we will need to add some sort of
230
225
// adjustment here so that trans can add an
231
226
// extra NULL env pointer:
232
- to_ares ( Sub ( * self ) . fns ( a_f, & b1_f) )
227
+ to_ares ( Sub ( * * self ) . fns ( a_f, & b1_f) )
233
228
}
234
229
235
- // check for &T being assigned to *T:
236
- ( ty:: ty_rptr( _, ref a_t) , ty:: ty_ptr( ref b_t) ) => {
237
- to_ares ( Sub ( * self ) . mts ( * a_t, * b_t) )
230
+ // check for &T being coerced to *T:
231
+ ( & ty:: ty_rptr( _, ref a_t) , & ty:: ty_ptr( ref b_t) ) => {
232
+ to_ares ( Sub ( * * self ) . mts ( * a_t, * b_t) )
238
233
}
239
234
240
- // otherwise, assignment follows normal subtype rules:
235
+ // otherwise, coercement follows normal subtype rules:
241
236
_ => {
242
- to_ares ( Sub ( * self ) . tys ( a, b) )
237
+ to_ares ( Sub ( * * self ) . tys ( a, b) )
243
238
}
244
239
}
245
240
}
246
241
_ => {
247
242
// if insufficient bounds were available, just follow
248
243
// normal subtype rules:
249
- to_ares ( Sub ( * self ) . tys ( a, b) )
244
+ to_ares ( Sub ( * * self ) . tys ( a, b) )
250
245
}
251
246
}
252
247
}
253
248
254
- /// Given an assignment from a type like `@a` to `&r_b/m nr_b`,
249
+ /// Given an coercement from a type like `@a` to `&r_b/m nr_b`,
255
250
/// this function checks that `a <: nr_b`. In that case, the
256
- /// assignment is permitted, so it constructs a fresh region
257
- /// variable `r_a >= r_b` and returns a corresponding assignment
251
+ /// coercement is permitted, so it constructs a fresh region
252
+ /// variable `r_a >= r_b` and returns a corresponding coercement
258
253
/// record. See the discussion at the top of this file for more
259
254
/// details.
260
- fn try_assign ( autoderefs : uint ,
255
+ fn try_coerce ( & self ,
256
+ autoderefs : uint ,
261
257
kind : ty:: AutoRefKind ,
262
258
a : ty:: t ,
263
259
nr_b : ty:: t ,
264
260
m : ast:: mutability ,
265
- r_b : ty:: Region ) -> ares {
266
-
267
- debug ! ( "try_assign (a=%s, nr_b=%s, m=%?, r_b=%s)" ,
261
+ r_b : ty:: Region ) -> ares
262
+ {
263
+ debug ! ( "try_coerce (a=%s, nr_b=%s, m=%?, r_b=%s)" ,
268
264
a. inf_str( self . infcx) ,
269
265
nr_b. inf_str( self . infcx) ,
270
266
m,
271
267
r_b. inf_str( self . infcx) ) ;
272
268
273
269
do indent {
274
- let sub = Sub ( * self ) ;
270
+ let sub = Sub ( * * self ) ;
275
271
do sub. tys ( a, nr_b) . chain |_t| {
276
272
let r_a = self . infcx . next_region_var_nb ( self . span ) ;
277
273
do sub. contraregions ( r_a, r_b) . chain |_r| {
0 commit comments