Skip to content

Commit b48c4c8

Browse files
committed
rustc_typeck: cleanup coercion logic that has been obsolete/unused for a while now.
1 parent 6a478bd commit b48c4c8

File tree

1 file changed

+7
-119
lines changed

1 file changed

+7
-119
lines changed

src/librustc_typeck/check/coercion.rs

Lines changed: 7 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ use middle::infer::combine::Combine;
6767
use middle::infer::sub::Sub;
6868
use middle::subst;
6969
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};
7271
use util::common::indent;
7372
use util::ppaux;
7473
use util::ppaux::Repr;
@@ -118,57 +117,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
118117
// See above for details.
119118
match b.sty {
120119
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+
});
145123
}
146124

147125
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+
});
172129
}
173130

174131
_ => {}
@@ -210,7 +167,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
210167
let r_borrow = self.fcx.infcx().next_region_var(coercion);
211168

212169
let inner_ty = match a.sty {
213-
ty::ty_uniq(_) => return Err(ty::terr_mismatch),
214170
ty::ty_rptr(_, mt_a) => {
215171
if !can_coerce_mutbls(mt_a.mutbl, mutbl_b) {
216172
return Err(ty::terr_mutability);
@@ -397,74 +353,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
397353
)
398354
}
399355

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-
468356
fn coerce_from_fn_item(&self,
469357
a: Ty<'tcx>,
470358
fn_def_id_a: ast::DefId,

0 commit comments

Comments
 (0)