@@ -67,8 +67,7 @@ use middle::infer::combine::Combine;
67
67
use middle:: infer:: sub:: Sub ;
68
68
use middle:: subst;
69
69
use middle:: ty:: { AutoPtr , AutoDerefRef , AdjustDerefRef , AutoUnsize , AutoUnsafe } ;
70
- use middle:: ty:: { mt} ;
71
- use middle:: ty:: { self , Ty } ;
70
+ use middle:: ty:: { self , mt, Ty } ;
72
71
use util:: common:: indent;
73
72
use util:: ppaux;
74
73
use util:: ppaux:: Repr ;
@@ -118,57 +117,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
118
117
// See above for details.
119
118
match b. sty {
120
119
ty:: ty_ptr( mt_b) => {
121
- match mt_b. ty . sty {
122
- ty:: ty_str => {
123
- return self . unpack_actual_value ( a, |a| {
124
- self . coerce_unsafe_ptr ( a, b, ast:: MutImmutable )
125
- } ) ;
126
- }
127
-
128
- ty:: ty_trait( ..) => {
129
- let result = self . unpack_actual_value ( a, |a| {
130
- self . coerce_unsafe_object ( a, b, mt_b. mutbl )
131
- } ) ;
132
-
133
- match result {
134
- Ok ( t) => return Ok ( t) ,
135
- Err ( ..) => { }
136
- }
137
- }
138
-
139
- _ => {
140
- return self . unpack_actual_value ( a, |a| {
141
- self . coerce_unsafe_ptr ( a, b, mt_b. mutbl )
142
- } ) ;
143
- }
144
- } ;
120
+ return self . unpack_actual_value ( a, |a| {
121
+ self . coerce_unsafe_ptr ( a, b, mt_b. mutbl )
122
+ } ) ;
145
123
}
146
124
147
125
ty:: ty_rptr( _, mt_b) => {
148
- match mt_b. ty . sty {
149
- ty:: ty_str => {
150
- return self . unpack_actual_value ( a, |a| {
151
- self . coerce_borrowed_pointer ( a, b, ast:: MutImmutable )
152
- } ) ;
153
- }
154
-
155
- ty:: ty_trait( ..) => {
156
- let result = self . unpack_actual_value ( a, |a| {
157
- self . coerce_borrowed_object ( a, b, mt_b. mutbl )
158
- } ) ;
159
-
160
- match result {
161
- Ok ( t) => return Ok ( t) ,
162
- Err ( ..) => { }
163
- }
164
- }
165
-
166
- _ => {
167
- return self . unpack_actual_value ( a, |a| {
168
- self . coerce_borrowed_pointer ( a, b, mt_b. mutbl )
169
- } ) ;
170
- }
171
- } ;
126
+ return self . unpack_actual_value ( a, |a| {
127
+ self . coerce_borrowed_pointer ( a, b, mt_b. mutbl )
128
+ } ) ;
172
129
}
173
130
174
131
_ => { }
@@ -210,7 +167,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
210
167
let r_borrow = self . fcx . infcx ( ) . next_region_var ( coercion) ;
211
168
212
169
let inner_ty = match a. sty {
213
- ty:: ty_uniq( _) => return Err ( ty:: terr_mismatch) ,
214
170
ty:: ty_rptr( _, mt_a) => {
215
171
if !can_coerce_mutbls ( mt_a. mutbl , mutbl_b) {
216
172
return Err ( ty:: terr_mutability) ;
@@ -397,74 +353,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
397
353
)
398
354
}
399
355
400
- fn coerce_borrowed_object ( & self ,
401
- a : Ty < ' tcx > ,
402
- b : Ty < ' tcx > ,
403
- b_mutbl : ast:: Mutability ) -> CoerceResult < ' tcx >
404
- {
405
- let tcx = self . tcx ( ) ;
406
-
407
- debug ! ( "coerce_borrowed_object(a={}, b={}, b_mutbl={:?})" ,
408
- a. repr( tcx) ,
409
- b. repr( tcx) , b_mutbl) ;
410
-
411
- let coercion = Coercion ( self . trace . clone ( ) ) ;
412
- let r_a = self . fcx . infcx ( ) . next_region_var ( coercion) ;
413
-
414
- self . coerce_object ( a, b, b_mutbl,
415
- |tr| ty:: mk_rptr ( tcx, tcx. mk_region ( r_a) ,
416
- ty:: mt { mutbl : b_mutbl, ty : tr } ) ,
417
- || AutoPtr ( r_a, b_mutbl, None ) )
418
- }
419
-
420
- fn coerce_unsafe_object ( & self ,
421
- a : Ty < ' tcx > ,
422
- b : Ty < ' tcx > ,
423
- b_mutbl : ast:: Mutability ) -> CoerceResult < ' tcx >
424
- {
425
- let tcx = self . tcx ( ) ;
426
-
427
- debug ! ( "coerce_unsafe_object(a={}, b={}, b_mutbl={:?})" ,
428
- a. repr( tcx) ,
429
- b. repr( tcx) , b_mutbl) ;
430
-
431
- self . coerce_object ( a, b, b_mutbl,
432
- |tr| ty:: mk_ptr ( tcx, ty:: mt { mutbl : b_mutbl, ty : tr } ) ,
433
- || AutoUnsafe ( b_mutbl, None ) )
434
- }
435
-
436
- fn coerce_object < F , G > ( & self ,
437
- a : Ty < ' tcx > ,
438
- b : Ty < ' tcx > ,
439
- b_mutbl : ast:: Mutability ,
440
- mk_ty : F ,
441
- mk_adjust : G ) -> CoerceResult < ' tcx > where
442
- F : FnOnce ( Ty < ' tcx > ) -> Ty < ' tcx > ,
443
- G : FnOnce ( ) -> ty:: AutoRef < ' tcx > ,
444
- {
445
- let tcx = self . tcx ( ) ;
446
-
447
- match a. sty {
448
- ty:: ty_rptr( _, ty:: mt { ty, mutbl} ) => match ty. sty {
449
- ty:: ty_trait( box ty:: TyTrait { ref principal, ref bounds } ) => {
450
- debug ! ( "mutbl={:?} b_mutbl={:?}" , mutbl, b_mutbl) ;
451
- let tr = ty:: mk_trait ( tcx, principal. clone ( ) , bounds. clone ( ) ) ;
452
- try!( self . subtype ( mk_ty ( tr) , b) ) ;
453
- Ok ( Some ( AdjustDerefRef ( AutoDerefRef {
454
- autoderefs : 1 ,
455
- autoref : Some ( mk_adjust ( ) )
456
- } ) ) )
457
- }
458
- _ => {
459
- self . subtype ( a, b)
460
- }
461
- } ,
462
- _ => {
463
- self . subtype ( a, b)
464
- }
465
- }
466
- }
467
-
468
356
fn coerce_from_fn_item ( & self ,
469
357
a : Ty < ' tcx > ,
470
358
fn_def_id_a : ast:: DefId ,
0 commit comments