rustc: remove proc -> once || coercions.

This commit is contained in:
Eduard Burtescu 2014-04-09 16:10:34 +03:00
parent 402d946868
commit f0c0c2ae91
6 changed files with 10 additions and 101 deletions

View File

@ -451,17 +451,8 @@ impl<'a> GatherLoanCtxt<'a> {
r,
AutoRef)
}
ty::AutoBorrowFn(r) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
self.guarantee_valid(expr.id,
expr.span,
cmt_deref,
ast::MutImmutable,
r,
AutoRef)
}
ty::AutoBorrowObj(r, m) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
let cmt_deref = mc.cat_deref_obj(expr, cmt);
self.guarantee_valid(expr.id,
expr.span,
cmt_deref,

View File

@ -686,19 +686,8 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
}
}
pub fn cat_deref_fn_or_obj<N:ast_node>(&mut self,
node: &N,
base_cmt: cmt,
deref_cnt: uint)
-> cmt {
// Bit of a hack: the "dereference" of a function pointer like
// `@fn()` is a mere logical concept. We interpret it as
// dereferencing the environment pointer; of course, we don't
// know what type lies at the other end, so we just call it
// `()` (the empty tuple).
let opaque_ty = ty::mk_tup(self.tcx(), Vec::new());
self.cat_deref_common(node, base_cmt, deref_cnt, opaque_ty)
pub fn cat_deref_obj<N:ast_node>(&mut self, node: &N, base_cmt: cmt) -> cmt {
self.cat_deref_common(node, base_cmt, 0, ty::mk_nil())
}
fn cat_deref<N:ast_node>(&mut self,

View File

@ -62,7 +62,7 @@ use middle::trans::type_of;
use middle::trans::write_guard;
use middle::ty::struct_fields;
use middle::ty::{AutoBorrowObj, AutoDerefRef, AutoAddEnv, AutoObject, AutoUnsafe};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef};
use middle::ty;
use middle::typeck::MethodCall;
use util::common::indenter;
@ -200,14 +200,6 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
Some(AutoBorrowVecRef(..)) => {
unpack_datum!(bcx, auto_slice_and_ref(bcx, expr, datum))
}
Some(AutoBorrowFn(..)) => {
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span, expr.id, datum.ty,
Some(adjustment), |method_call| {
bcx.ccx().maps.method_map.borrow()
.find(&method_call).map(|method| method.ty)
});
unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum))
}
Some(AutoBorrowObj(..)) => {
unpack_datum!(bcx, auto_borrow_obj(bcx, expr, datum))
}
@ -225,20 +217,6 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
debug!("after adjustments, datum={}", datum.to_str(bcx.ccx()));
return DatumBlock {bcx: bcx, datum: datum};
fn auto_borrow_fn<'a>(
bcx: &'a Block<'a>,
adjusted_ty: ty::t,
datum: Datum<Expr>)
-> DatumBlock<'a, Expr> {
// Currently, all closure types are represented precisely the
// same, so no runtime adjustment is required, but we still
// must patchup the type.
DatumBlock {bcx: bcx,
datum: Datum {val: datum.val,
ty: adjusted_ty,
kind: datum.kind}}
}
fn auto_slice<'a>(
bcx: &'a Block<'a>,
expr: &ast::Expr,

View File

@ -239,9 +239,6 @@ pub enum AutoRef {
/// Convert from ~[]/&[] to &&[] (or str)
AutoBorrowVecRef(Region, ast::Mutability),
/// Convert from @fn()/~fn()/|| to ||
AutoBorrowFn(Region),
/// Convert from T to *T
AutoUnsafe(ast::Mutability),
@ -2906,10 +2903,6 @@ pub fn adjust_ty(cx: &ctxt,
})
}
AutoBorrowFn(r) => {
borrow_fn(cx, span, r, adjusted_ty)
}
AutoUnsafe(m) => {
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
}
@ -2951,24 +2944,6 @@ pub fn adjust_ty(cx: &ctxt,
}
}
fn borrow_fn(cx: &ctxt, span: Span, r: Region, ty: ty::t) -> ty::t {
match get(ty).sty {
ty_closure(ref fty) => {
ty::mk_closure(cx, ClosureTy {
store: RegionTraitStore(r, ast::MutMutable),
..(**fty).clone()
})
}
ref s => {
cx.sess.span_bug(
span,
format!("borrow-fn associated with bad sty: {:?}",
s));
}
}
}
fn borrow_obj(cx: &ctxt, span: Span, r: Region,
m: ast::Mutability, ty: ty::t) -> ty::t {
match get(ty).sty {
@ -2992,7 +2967,6 @@ impl AutoRef {
ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m),
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m),
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(f(r), m),
ty::AutoBorrowFn(r) => ty::AutoBorrowFn(f(r)),
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(f(r), m),
}

View File

@ -1123,13 +1123,8 @@ fn link_autoref(rcx: &mut Rcx,
link_region(mc.typer, expr.span, r, m, cmt_index);
}
ty::AutoBorrowFn(r) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, expr_cmt, 0);
link_region(mc.typer, expr.span, r, ast::MutImmutable, cmt_deref);
}
ty::AutoBorrowObj(r, m) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, expr_cmt, 0);
let cmt_deref = mc.cat_deref_obj(expr, expr_cmt);
link_region(mc.typer, expr.span, r, m, cmt_deref);
}

View File

@ -65,8 +65,7 @@ we may want to adjust precisely when coercions occur.
*/
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowFn, AutoBorrowObj};
use middle::ty::{AutoDerefRef};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowObj, AutoDerefRef};
use middle::ty::{VstoreSlice, VstoreUniq};
use middle::ty::{mt};
use middle::ty;
@ -342,31 +341,14 @@ impl<'f> Coerce<'f> {
a.inf_str(self.get_ref().infcx), sty_a,
b.inf_str(self.get_ref().infcx));
let fn_ty = match *sty_a {
ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
(*f).clone()
}
match *sty_a {
ty::ty_bare_fn(ref f) => {
return self.coerce_from_bare_fn(a, f, b);
self.coerce_from_bare_fn(a, f, b)
}
_ => {
return self.subtype(a, b);
self.subtype(a, b)
}
};
let r_borrow = self.get_ref().infcx.next_region_var(Coercion(self.get_ref().trace));
let a_borrowed = ty::mk_closure(
self.get_ref().infcx.tcx,
ty::ClosureTy {
store: ty::RegionTraitStore(r_borrow, ast::MutMutable),
.. *fn_ty
});
if_ok!(self.subtype(a_borrowed, b));
Ok(Some(@AutoDerefRef(AutoDerefRef {
autoderefs: 0,
autoref: Some(AutoBorrowFn(r_borrow))
})))
}
}
fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t)