From f0c0c2ae91061a2b6041658a6e406c757e4e5483 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 9 Apr 2014 16:10:34 +0300 Subject: [PATCH] rustc: remove proc -> once || coercions. --- .../middle/borrowck/gather_loans/mod.rs | 11 +------- src/librustc/middle/mem_categorization.rs | 15 ++-------- src/librustc/middle/trans/expr.rs | 24 +--------------- src/librustc/middle/ty.rs | 26 ----------------- src/librustc/middle/typeck/check/regionck.rs | 7 +---- src/librustc/middle/typeck/infer/coercion.rs | 28 ++++--------------- 6 files changed, 10 insertions(+), 101 deletions(-) diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index a6409131bed..f0a6c5f16f7 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -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, diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index dcab1d9a0da..f76aae9eef4 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -686,19 +686,8 @@ impl MemCategorizationContext { } } - pub fn cat_deref_fn_or_obj(&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(&mut self, node: &N, base_cmt: cmt) -> cmt { + self.cat_deref_common(node, base_cmt, 0, ty::mk_nil()) } fn cat_deref(&mut self, diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 03540aaee56..e19408520f6 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -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) - -> 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, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a59be10af53..af53c31ad4e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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), } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 6a42f6485df..9e7bb1b10f6 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -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); } diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index ee3c58aeedd..7d1ffa4451f 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -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)