]> git.lizzy.rs Git - rust.git/commitdiff
rustc: fix fallout from removing ast::Sigil and use ty::TraitStore in ty::ClosureTy.
authorEduard Burtescu <edy.burt@gmail.com>
Fri, 11 Apr 2014 15:03:10 +0000 (18:03 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Fri, 11 Apr 2014 15:03:10 +0000 (18:03 +0300)
28 files changed:
src/librustc/front/feature_gate.rs
src/librustc/metadata/tydecode.rs
src/librustc/metadata/tyencode.rs
src/librustc/middle/astencode.rs
src/librustc/middle/borrowck/mod.rs
src/librustc/middle/kind.rs
src/librustc/middle/lint.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/moves.rs
src/librustc/middle/resolve.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/closure.rs
src/librustc/middle/trans/consts.rs
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/glue.rs
src/librustc/middle/trans/reflect.rs
src/librustc/middle/ty.rs
src/librustc/middle/ty_fold.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionck.rs
src/librustc/middle/typeck/check/writeback.rs
src/librustc/middle/typeck/infer/coercion.rs
src/librustc/middle/typeck/infer/combine.rs
src/librustc/middle/typeck/variance.rs
src/librustc/util/ppaux.rs

index 5c0b9c8956519b0a24eb16cb25531e645935ee31..dd604af40ec52dd6d57902643282b2de93a834db 100644 (file)
@@ -260,8 +260,7 @@ fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
 
     fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
         match t.node {
-            ast::TyClosure(closure) if closure.onceness == ast::Once &&
-                    closure.sigil != ast::OwnedSigil => {
+            ast::TyClosure(closure, _) if closure.onceness == ast::Once => {
                 self.gate_feature("once_fns", t.span,
                                   "once functions are \
                                    experimental and likely to be removed");
index f29b181125ed0b747a7c4893f2fa8b88e2f7fec1..5df5b718f3e76b163d44d714a605b9cc4f5500ee 100644 (file)
@@ -137,15 +137,6 @@ pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx:
     parse_substs(&mut st, conv)
 }
 
-fn parse_sigil(st: &mut PState) -> ast::Sigil {
-    match next(st) {
-        '@' => ast::ManagedSigil,
-        '~' => ast::OwnedSigil,
-        '&' => ast::BorrowedSigil,
-        c => st.tcx.sess.bug(format!("parse_sigil(): bad input '{}'", c))
-    }
-}
-
 fn parse_vstore<M>(st: &mut PState, conv: conv_did,
                    parse_mut: |&mut PState| -> M) -> ty::Vstore<M> {
     assert_eq!(next(st), '/');
@@ -476,17 +467,15 @@ fn parse_onceness(c: char) -> ast::Onceness {
 }
 
 fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy {
-    let sigil = parse_sigil(st);
     let fn_style = parse_fn_style(next(st));
     let onceness = parse_onceness(next(st));
-    let region = parse_region(st, |x,y| conv(x,y));
+    let store = parse_trait_store(st, |x,y| conv(x,y));
     let bounds = parse_bounds(st, |x,y| conv(x,y));
     let sig = parse_sig(st, |x,y| conv(x,y));
     ty::ClosureTy {
         fn_style: fn_style,
-        sigil: sigil,
         onceness: onceness,
-        region: region,
+        store: store,
         bounds: bounds.builtin_bounds,
         sig: sig
     }
index d8c5197df279d44ef031cec1b3fca777978d36eb..53fe1c19d8ff948c60bc359ad29a5aff20f029a3 100644 (file)
@@ -327,14 +327,6 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
     }
 }
 
-fn enc_sigil(w: &mut MemWriter, sigil: Sigil) {
-    match sigil {
-        ManagedSigil => mywrite!(w, "@"),
-        OwnedSigil => mywrite!(w, "~"),
-        BorrowedSigil => mywrite!(w, "&"),
-    }
-}
-
 fn enc_fn_style(w: &mut MemWriter, p: FnStyle) {
     match p {
         NormalFn => mywrite!(w, "n"),
@@ -363,10 +355,9 @@ pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
 }
 
 fn enc_closure_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::ClosureTy) {
-    enc_sigil(w, ft.sigil);
     enc_fn_style(w, ft.fn_style);
     enc_onceness(w, ft.onceness);
-    enc_region(w, cx, ft.region);
+    enc_trait_store(w, cx, ft.store);
     let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
                                   trait_bounds: Vec::new()};
     enc_bounds(w, cx, &bounds);
index ebddc0525ea272c1c61807f453084b66c66eca62..858e873f7ed3592e83d2c3a68d13f8dc6394dfd9 100644 (file)
@@ -897,10 +897,9 @@ fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &ty::substs) {
     fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment) {
         self.emit_enum("AutoAdjustment", |this| {
             match *adj {
-                ty::AutoAddEnv(region, sigil) => {
-                    this.emit_enum_variant("AutoAddEnv", 0, 2, |this| {
-                        this.emit_enum_variant_arg(0, |this| region.encode(this));
-                        this.emit_enum_variant_arg(1, |this| sigil.encode(this))
+                ty::AutoAddEnv(store) => {
+                    this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
+                        this.emit_enum_variant_arg(0, |this| store.encode(this))
                     })
                 }
 
@@ -1270,12 +1269,10 @@ fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjus
             this.read_enum_variant(variants, |this, i| {
                 Ok(match i {
                     0 => {
-                        let region: ty::Region =
+                        let store: ty::TraitStore =
                             this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
-                        let sigil: ast::Sigil =
-                            this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
 
-                        ty:: AutoAddEnv(region.tr(xcx), sigil)
+                        ty:: AutoAddEnv(store.tr(xcx))
                     }
                     1 => {
                         let auto_deref_ref: ty::AutoDerefRef =
index 83c45dc830f115cfb58166bd2a5398c38509cb31..21e68e2724fc327d4f54c1fffd79982d4b09374a 100644 (file)
@@ -620,7 +620,7 @@ pub fn report_use_of_moved_value(&self,
         fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str)
                           -> &'static str {
             match ty::get(ty).sty {
-                ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
+                ty::ty_closure(~ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) =>
                     "a non-copyable stack closure (capture it in a new closure, \
                      e.g. `|x| f(x)`, to override)",
                 _ if ty::type_moves_by_default(tcx, ty) =>
index 09f396e932ff2a1d1cd67212bb1bd36f6658d195..a152e06eb06aafd2cf193dedebb9286b8e9c4ff0 100644 (file)
@@ -197,27 +197,13 @@ fn check_for_bare(cx: &Context, fv: @freevar_entry) {
     let fty = ty::node_id_to_type(cx.tcx, id);
     match ty::get(fty).sty {
         ty::ty_closure(~ty::ClosureTy {
-            sigil: OwnedSigil,
-            bounds: bounds,
-            ..
-        }) => {
-            b(|cx, fv| check_for_uniq(cx, fv, bounds))
-        }
-        ty::ty_closure(~ty::ClosureTy {
-            sigil: ManagedSigil,
-            ..
-        }) => {
-            // can't happen
-            fail!("internal error: saw closure with managed sigil (@fn)");
-        }
+            store: ty::UniqTraitStore, bounds, ..
+        }) => b(|cx, fv| check_for_uniq(cx, fv, bounds)),
+
         ty::ty_closure(~ty::ClosureTy {
-            sigil: BorrowedSigil,
-            bounds: bounds,
-            region: region,
-            ..
-        }) => {
-            b(|cx, fv| check_for_block(cx, fv, bounds, region))
-        }
+            store: ty::RegionTraitStore(region, _), bounds, ..
+        }) => b(|cx, fv| check_for_block(cx, fv, bounds, region)),
+
         ty::ty_bare_fn(_) => {
             b(check_for_bare)
         }
index 16af63c4e16407e4b3edd31af44ec0c991105275..e376f85ff6db030934292ae3fa46568749e2218e 100644 (file)
@@ -919,10 +919,8 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
                 }
                 ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
                 ty::ty_vec(_, ty::VstoreUniq) |
-                ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
-                    n_uniq += 1;
-                }
-                ty::ty_closure(ref c) if c.sigil == ast::OwnedSigil => {
+                ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
+                ty::ty_closure(~ty::ClosureTy { store: ty::UniqTraitStore, .. }) => {
                     n_uniq += 1;
                 }
 
index a5da9e7f9d0e57fca91df8c78df5bd9c9eedbe54..dcab1d9a0da1a4296466f7bdc0861237d4d6e4fc 100644 (file)
@@ -172,7 +172,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
         ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
         ty::ty_vec(_, ty::VstoreUniq) |
         ty::ty_str(ty::VstoreUniq) |
-        ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
+        ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
             Some(deref_ptr(OwnedPtr))
         }
 
@@ -187,8 +187,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
         }
 
         ty::ty_str(ty::VstoreSlice(r, ())) |
-        ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
-                                      region: r, ..}) => {
+        ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(r, _), ..}) => {
             Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
         }
 
@@ -540,15 +539,14 @@ pub fn cat_def(&mut self,
                       // Decide whether to use implicit reference or by copy/move
                       // capture for the upvar. This, combined with the onceness,
                       // determines whether the closure can move out of it.
-                      let var_is_refd = match (closure_ty.sigil, closure_ty.onceness) {
+                      let var_is_refd = match (closure_ty.store, closure_ty.onceness) {
                           // Many-shot stack closures can never move out.
-                          (ast::BorrowedSigil, ast::Many) => true,
+                          (ty::RegionTraitStore(..), ast::Many) => true,
                           // 1-shot stack closures can move out.
-                          (ast::BorrowedSigil, ast::Once) => false,
+                          (ty::RegionTraitStore(..), ast::Once) => false,
                           // Heap closures always capture by copy/move, and can
                           // move out if they are once.
-                          (ast::OwnedSigil, _) |
-                          (ast::ManagedSigil, _) => false,
+                          (ty::UniqTraitStore, _) => false,
 
                       };
                       if var_is_refd {
index dbc28f9fdd5626c1003f59b7eadd01c9ada8abca..2029df38b10015e17c2d9bd96624f0e93aed4385 100644 (file)
@@ -650,30 +650,30 @@ pub fn compute_captures(&mut self, fn_expr_id: NodeId) -> Rc<Vec<CaptureVar> > {
         let _indenter = indenter();
 
         let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id);
-        let sigil = ty::ty_closure_sigil(fn_ty);
         let freevars = freevars::get_freevars(self.tcx, fn_expr_id);
-        let v = if sigil == BorrowedSigil {
-            // || captures everything by ref
-            freevars.iter()
-                    .map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
-                    .collect()
-        } else {
-            // @fn() and ~fn() capture by copy or by move depending on type
-            freevars.iter()
-                    .map(|fvar| {
-                let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
-                let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
-                debug!("fvar_def_id={:?} fvar_ty={}",
-                       fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
-                let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
-                    CapMove
-                } else {
-                    CapCopy
-                };
-                CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
-
+        Rc::new(match ty::ty_closure_store(fn_ty) {
+            ty::RegionTraitStore(..) => {
+                // || captures everything by ref
+                freevars.iter()
+                        .map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
+                        .collect()
+            }
+            ty::UniqTraitStore => {
+                // proc captures by copy or by move depending on type
+                freevars.iter()
+                        .map(|fvar| {
+                    let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
+                    let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
+                    debug!("fvar_def_id={:?} fvar_ty={}",
+                        fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
+                    let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
+                        CapMove
+                    } else {
+                        CapCopy
+                    };
+                    CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
                 }).collect()
-        };
-        Rc::new(v)
+            }
+        })
     }
 }
index 92acb81bbcb22d47e7a0b99cf1023eff025e5aa5..e5b13adb4d0dc9d827f1753b47677f605f74db0a 100644 (file)
@@ -4274,7 +4274,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                 });
             }
 
-            TyClosure(c) => {
+            TyClosure(c, _) | TyProc(c) => {
                 c.bounds.as_ref().map(|bounds| {
                     for bound in bounds.iter() {
                         self.resolve_type_parameter_bound(ty.id, bound);
index 8f4c8c84b68643220b0769a1642f6150e2a10417..130c93ac51e91e8c4152cf63c583525720878021 100644 (file)
@@ -112,7 +112,9 @@ fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
 
     fn visit_ty(&mut self, ty: &ast::Ty, scope: Scope<'a>) {
         match ty.node {
-            ast::TyClosure(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
+            ast::TyClosure(c, _) | ast::TyProc(c) => {
+                push_fn_scope(self, ty, scope, &c.lifetimes);
+            }
             ast::TyBareFn(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
             _ => visit::walk_ty(self, ty, scope),
         }
index 3007b643e0a5f1b93d193bf3c799f20b022cb462..60d6e6850f7ead745dbc1917bc1c0f61bb7164a5 100644 (file)
@@ -260,7 +260,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
             // noalias because the actual object pointer is nested.
             ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
             ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) |
-            ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
+            ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
                 unsafe {
                     llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
                 }
index 8fbaa23875407b8d3e8076daf85aec4c96ede034..9cdc98bab5c96ab7e6fe21fedb48c197a900c5eb 100644 (file)
@@ -158,24 +158,21 @@ fn tuplify_box_ty(tcx: &ty::ctxt, t: ty::t) -> ty::t {
 }
 
 fn allocate_cbox<'a>(bcx: &'a Block<'a>,
-                     sigil: ast::Sigil,
+                     store: ty::TraitStore,
                      cdata_ty: ty::t)
                      -> Result<'a> {
     let _icx = push_ctxt("closure::allocate_cbox");
     let tcx = bcx.tcx();
 
     // Allocate and initialize the box:
-    match sigil {
-        ast::ManagedSigil => {
-            tcx.sess.bug("trying to trans allocation of @fn")
-        }
-        ast::OwnedSigil => {
+    match store {
+        ty::UniqTraitStore => {
             let ty = type_of(bcx.ccx(), cdata_ty);
             let size = llsize_of(bcx.ccx(), ty);
             // we treat proc as @ here, which isn't ideal
             malloc_raw_dyn_managed(bcx, cdata_ty, ClosureExchangeMallocFnLangItem, size)
         }
-        ast::BorrowedSigil => {
+        ty::RegionTraitStore(..) => {
             let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
             let llbox = alloc_ty(bcx, cbox_ty, "__closure");
             rslt(bcx, llbox)
@@ -196,7 +193,7 @@ pub struct ClosureResult<'a> {
 pub fn store_environment<'a>(
                          bcx: &'a Block<'a>,
                          bound_values: Vec<EnvValue> ,
-                         sigil: ast::Sigil)
+                         store: ty::TraitStore)
                          -> ClosureResult<'a> {
     let _icx = push_ctxt("closure::store_environment");
     let ccx = bcx.ccx();
@@ -220,7 +217,7 @@ pub fn store_environment<'a>(
     }
 
     // allocate closure in the heap
-    let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, sigil, cdata_ty);
+    let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, store, cdata_ty);
 
     let llbox = PointerCast(bcx, llbox, llboxptr_ty);
     debug!("tuplify_box_ty = {}", ty_to_str(tcx, cbox_ty));
@@ -254,7 +251,7 @@ pub fn store_environment<'a>(
 // collects the upvars and packages them up for store_environment.
 fn build_closure<'a>(bcx0: &'a Block<'a>,
                      cap_vars: &[moves::CaptureVar],
-                     sigil: ast::Sigil)
+                     store: ty::TraitStore)
                      -> ClosureResult<'a> {
     let _icx = push_ctxt("closure::build_closure");
 
@@ -268,7 +265,11 @@ fn build_closure<'a>(bcx0: &'a Block<'a>,
         let datum = expr::trans_local_var(bcx, cap_var.def);
         match cap_var.mode {
             moves::CapRef => {
-                assert_eq!(sigil, ast::BorrowedSigil);
+                let is_region_closure = match store {
+                    ty::RegionTraitStore(..) => true,
+                    ty::UniqTraitStore => false
+                };
+                assert!(is_region_closure);
                 env_vals.push(EnvValue {action: EnvRef,
                                         datum: datum});
             }
@@ -283,7 +284,7 @@ fn build_closure<'a>(bcx0: &'a Block<'a>,
         }
     }
 
-    return store_environment(bcx, env_vals, sigil);
+    store_environment(bcx, env_vals, store)
 }
 
 // Given an enclosing block context, a new function context, a closure type,
@@ -291,7 +292,7 @@ fn build_closure<'a>(bcx0: &'a Block<'a>,
 // with the upvars and type descriptors.
 fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
                         cap_vars: &[moves::CaptureVar],
-                        sigil: ast::Sigil) -> &'a Block<'a> {
+                        store: ty::TraitStore) -> &'a Block<'a> {
     let _icx = push_ctxt("closure::load_environment");
 
     // Don't bother to create the block if there's nothing to load
@@ -316,9 +317,9 @@ fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
     let mut i = 0u;
     for cap_var in cap_vars.iter() {
         let mut upvarptr = GEPi(bcx, llcdata, [0u, i]);
-        match sigil {
-            ast::BorrowedSigil => { upvarptr = Load(bcx, upvarptr); }
-            ast::ManagedSigil | ast::OwnedSigil => {}
+        match store {
+            ty::RegionTraitStore(..) => { upvarptr = Load(bcx, upvarptr); }
+            ty::UniqTraitStore => {}
         }
         let def_id = ast_util::def_id_of_def(cap_var.def);
 
@@ -331,7 +332,7 @@ fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
                 cdata_ty,
                 env_pointer_alloca,
                 i,
-                sigil,
+                store,
                 cap_var.span);
         }
 
@@ -349,7 +350,7 @@ fn fill_fn_pair(bcx: &Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef)
 
 pub fn trans_expr_fn<'a>(
                      bcx: &'a Block<'a>,
-                     sigil: ast::Sigil,
+                     store: ty::TraitStore,
                      decl: &ast::FnDecl,
                      body: &ast::Block,
                      id: ast::NodeId,
@@ -359,7 +360,7 @@ pub fn trans_expr_fn<'a>(
      *
      * Translates the body of a closure expression.
      *
-     * - `sigil`
+     * - `store`
      * - `decl`
      * - `body`
      * - `id`: The id of the closure expression.
@@ -399,11 +400,11 @@ pub fn trans_expr_fn<'a>(
 
     let cap_vars = ccx.maps.capture_map.borrow().get_copy(&id);
     let ClosureResult {llbox, cdata_ty, bcx} =
-        build_closure(bcx, cap_vars.as_slice(), sigil);
+        build_closure(bcx, cap_vars.as_slice(), store);
     trans_closure(ccx, decl, body, llfn,
                   bcx.fcx.param_substs, id,
                   [], ty::ty_fn_ret(fty),
-                  |bcx| load_environment(bcx, cdata_ty, cap_vars.as_slice(), sigil));
+                  |bcx| load_environment(bcx, cdata_ty, cap_vars.as_slice(), store));
     fill_fn_pair(bcx, dest_addr, llfn, llbox);
 
     bcx
index 66de46aa31d3e1ceb7e265383418ec208458ff08..e0a54234fca7e0fedba76f903cb396e3a1ea556b 100644 (file)
@@ -191,7 +191,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
         None => { }
         Some(adj) => {
             match *adj {
-                ty::AutoAddEnv(ty::ReStatic, ast::BorrowedSigil) => {
+                ty::AutoAddEnv(ty::RegionTraitStore(ty::ReStatic, _)) => {
                     let def = ty::resolve_expr(cx.tcx(), e);
                     let wrapper = closure::get_wrapper_for_bare_fn(cx,
                                                                    ety_adjusted,
@@ -200,13 +200,11 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
                                                                    is_local);
                     llconst = C_struct(cx, [wrapper, C_null(Type::i8p(cx))], false)
                 }
-                ty::AutoAddEnv(ref r, ref s) => {
+                ty::AutoAddEnv(store) => {
                     cx.sess()
                       .span_bug(e.span,
-                                format!("unexpected static function: region \
-                                         {:?} sigil {:?}",
-                                        *r,
-                                        *s))
+                                format!("unexpected static function: {:?}",
+                                        store))
                 }
                 ty::AutoObject(..) => {
                     cx.sess()
index 965276619e9e8764fcd99615a4af96e25e7a71dc..ae58e153258ef467d9726aab94a31858b37c623e 100644 (file)
@@ -394,7 +394,7 @@ pub fn create_captured_var_metadata(bcx: &Block,
                                     env_data_type: ty::t,
                                     env_pointer: ValueRef,
                                     env_index: uint,
-                                    closure_sigil: ast::Sigil,
+                                    closure_store: ty::TraitStore,
                                     span: Span) {
     if fn_should_be_ignored(bcx.fcx) {
         return;
@@ -443,11 +443,11 @@ pub fn create_captured_var_metadata(bcx: &Block,
          llvm::LLVMDIBuilderCreateOpDeref(Type::i64(cx).to_ref())]
     };
 
-    let address_op_count = match closure_sigil {
-        ast::BorrowedSigil => {
+    let address_op_count = match closure_store {
+        ty::RegionTraitStore(..) => {
             address_operations.len()
         }
-        ast::ManagedSigil | ast::OwnedSigil => {
+        ty::UniqTraitStore => {
             address_operations.len() - 1
         }
     };
index 4515b5d086eab90184465428d6774be660f669e2..03540aaee5681d1f6d1fd626f4ce46bbdbb05fca 100644 (file)
@@ -731,10 +731,10 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
         ast::ExprFnBlock(decl, body) |
         ast::ExprProc(decl, body) => {
             let expr_ty = expr_ty(bcx, expr);
-            let sigil = ty::ty_closure_sigil(expr_ty);
+            let store = ty::ty_closure_store(expr_ty);
             debug!("translating block function {} with type {}",
                    expr_to_str(expr), expr_ty.repr(tcx));
-            closure::trans_expr_fn(bcx, sigil, decl, body, expr.id, dest)
+            closure::trans_expr_fn(bcx, store, decl, body, expr.id, dest)
         }
         ast::ExprCall(f, ref args) => {
             callee::trans_call(bcx, expr, f, callee::ArgExprs(args.as_slice()), dest)
index f4b6ed235e87a368b78f17729f9bd37c2357002d..98e135c27c4862fdd0935873dd7f2db7fe6696fe 100644 (file)
@@ -323,7 +323,7 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
                 bcx
             })
         }
-        ty::ty_closure(ref f) if f.sigil == ast::OwnedSigil => {
+        ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
             let box_cell_v = GEPi(bcx, v0, [0u, abi::fn_field_box]);
             let env = Load(bcx, box_cell_v);
             let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
index c4b9c7f97adf7ff3993b86ad0811047bde0dd1b6..3fe494ad41b0eca83ddc9d5bab76670bb1982d81 100644 (file)
@@ -218,7 +218,10 @@ pub fn visit_ty(&mut self, t: ty::t) {
           // FIXME (#4809): visitor should break out bare fns from other fns
           ty::ty_closure(ref fty) => {
             let pureval = ast_fn_style_constant(fty.fn_style);
-            let sigilval = ast_sigil_constant(fty.sigil);
+            let sigilval = match fty.store {
+                ty::UniqTraitStore => 2u,
+                ty::RegionTraitStore(..) => 4u,
+            };
             let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u};
             let extra = vec!(self.c_uint(pureval),
                           self.c_uint(sigilval),
@@ -397,14 +400,6 @@ pub fn emit_calls_to_trait_visit_ty<'a>(
     return final;
 }
 
-pub fn ast_sigil_constant(sigil: ast::Sigil) -> uint {
-    match sigil {
-        ast::OwnedSigil => 2u,
-        ast::ManagedSigil => 3u,
-        ast::BorrowedSigil => 4u,
-    }
-}
-
 pub fn ast_fn_style_constant(fn_style: ast::FnStyle) -> uint {
     match fn_style {
         ast::UnsafeFn => 1u,
index 0cb0d716ddcffd3679a1253492356b3ba9ca198b..a59be10af53359e917c92d4069e68eb5250b45f9 100644 (file)
@@ -214,7 +214,7 @@ pub enum Variance {
 }
 
 pub enum AutoAdjustment {
-    AutoAddEnv(ty::Region, ast::Sigil),
+    AutoAddEnv(ty::TraitStore),
     AutoDerefRef(AutoDerefRef),
     AutoObject(ty::TraitStore,
                ty::BuiltinBounds,
@@ -430,9 +430,8 @@ pub struct BareFnTy {
 #[deriving(Clone, Eq, TotalEq, Hash)]
 pub struct ClosureTy {
     pub fn_style: ast::FnStyle,
-    pub sigil: ast::Sigil,
     pub onceness: ast::Onceness,
-    pub region: Region,
+    pub store: TraitStore,
     pub bounds: BuiltinBounds,
     pub sig: FnSig,
 }
@@ -801,7 +800,7 @@ pub enum type_err {
     terr_onceness_mismatch(expected_found<Onceness>),
     terr_abi_mismatch(expected_found<abi::Abi>),
     terr_mutability,
-    terr_sigil_mismatch(expected_found<ast::Sigil>),
+    terr_sigil_mismatch(expected_found<TraitStore>),
     terr_box_mutability,
     terr_ptr_mutability,
     terr_ref_mutability,
@@ -1204,11 +1203,13 @@ fn sflags(substs: &substs) -> uint {
       &ty_param(_) => flags |= has_params as uint,
       &ty_infer(_) => flags |= needs_infer as uint,
       &ty_self(_) => flags |= has_self as uint,
-      &ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
-      &ty_trait(~ty::TyTrait { ref substs, .. }) => {
+      &ty_enum(_, ref substs) | &ty_struct(_, ref substs) => {
+          flags |= sflags(substs);
+      }
+      &ty_trait(~ty::TyTrait { ref substs, store, .. }) => {
           flags |= sflags(substs);
-          match st {
-              ty_trait(~ty::TyTrait { store: RegionTraitStore(r, _), .. }) => {
+          match store {
+              RegionTraitStore(r, _) => {
                     flags |= rflags(r);
                 }
               _ => {}
@@ -1232,7 +1233,12 @@ fn sflags(substs: &substs) -> uint {
         flags &= !(has_ty_bot as uint);
       }
       &ty_closure(ref f) => {
-        flags |= rflags(f.region);
+        match f.store {
+            RegionTraitStore(r, _) => {
+                flags |= rflags(r);
+            }
+            _ => {}
+        }
         for a in f.sig.inputs.iter() { flags |= get(*a).flags; }
         flags |= get(f.sig.output).flags;
         // T -> _|_ is *not* _|_ !
@@ -2217,17 +2223,7 @@ fn borrowed_contents(region: ty::Region,
     fn closure_contents(cx: &ctxt, cty: &ClosureTy) -> TypeContents {
         // Closure contents are just like trait contents, but with potentially
         // even more stuff.
-        let st = match cty.sigil {
-            ast::BorrowedSigil =>
-                object_contents(cx, RegionTraitStore(cty.region, MutMutable), cty.bounds),
-            ast::OwnedSigil => object_contents(cx, UniqTraitStore, cty.bounds),
-            ast::ManagedSigil => unreachable!()
-        };
-
-        // FIXME(#3569): This borrowed_contents call should be taken care of in
-        // object_contents, after ~Traits and @Traits can have region bounds too.
-        // This one here is redundant for &fns but important for ~fns and @fns.
-        let rt = borrowed_contents(cty.region, ast::MutImmutable);
+        let st = object_contents(cx, cty.store, cty.bounds);
 
         // This also prohibits "@once fn" from being copied, which allows it to
         // be called. Neither way really makes much sense.
@@ -2236,7 +2232,7 @@ fn closure_contents(cx: &ctxt, cty: &ClosureTy) -> TypeContents {
             ast::Many => TC::None,
         };
 
-        st | rt | ot
+        st | ot
     }
 
     fn object_contents(cx: &ctxt,
@@ -2696,11 +2692,11 @@ pub fn ty_fn_args(fty: t) -> Vec<t> {
     }
 }
 
-pub fn ty_closure_sigil(fty: t) -> Sigil {
+pub fn ty_closure_store(fty: t) -> TraitStore {
     match get(fty).sty {
-        ty_closure(ref f) => f.sigil,
+        ty_closure(ref f) => f.store,
         ref s => {
-            fail!("ty_closure_sigil() called on non-closure type: {:?}", s)
+            fail!("ty_closure_store() called on non-closure type: {:?}", s)
         }
     }
 }
@@ -2838,15 +2834,14 @@ pub fn adjust_ty(cx: &ctxt,
     return match adjustment {
         Some(adjustment) => {
             match *adjustment {
-                AutoAddEnv(r, s) => {
+                AutoAddEnv(store) => {
                     match ty::get(unadjusted_ty).sty {
                         ty::ty_bare_fn(ref b) => {
                             ty::mk_closure(
                                 cx,
                                 ty::ClosureTy {fn_style: b.fn_style,
-                                               sigil: s,
                                                onceness: ast::Many,
-                                               region: r,
+                                               store: store,
                                                bounds: ty::AllBuiltinBounds(),
                                                sig: b.sig.clone()})
                         }
@@ -2960,8 +2955,7 @@ 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 {
-                    sigil: BorrowedSigil,
-                    region: r,
+                    store: RegionTraitStore(r, ast::MutMutable),
                     ..(**fty).clone()
                 })
             }
@@ -4278,20 +4272,6 @@ pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) ->
     }
 }
 
-// Determine what the style to check a nested function under
-pub fn determine_inherited_style(parent: (ast::FnStyle, ast::NodeId),
-                                  child: (ast::FnStyle, ast::NodeId),
-                                  child_sigil: ast::Sigil)
-                                    -> (ast::FnStyle, ast::NodeId) {
-    // If the closure is a stack closure and hasn't had some non-standard
-    // style inferred for it, then check it under its parent's style.
-    // Otherwise, use its own
-    match child_sigil {
-        ast::BorrowedSigil if child.val0() == ast::NormalFn => parent,
-        _ => child
-    }
-}
-
 // Iterate over a type parameter's bounded traits and any supertraits
 // of those traits, ignoring kinds.
 // Here, the supertraits are the transitive closure of the supertrait
@@ -4640,10 +4620,16 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 {
             ty_closure(ref c) => {
                 byte!(15);
                 hash!(c.fn_style);
-                hash!(c.sigil);
                 hash!(c.onceness);
                 hash!(c.bounds);
-                region(&mut state, c.region);
+                match c.store {
+                    UniqTraitStore => byte!(0),
+                    RegionTraitStore(r, m) => {
+                        byte!(1)
+                        region(&mut state, r);
+                        assert_eq!(m, ast::MutMutable);
+                    }
+                }
             }
             ty_trait(~ty::TyTrait { def_id: d, store, bounds, .. }) => {
                 byte!(17);
index a100d01f66a379026adf112721ec1bf44e6acb6a..840f741badb7a9576b5efddac83681c9cd9d573c 100644 (file)
@@ -56,10 +56,9 @@ fn fold_closure_ty(&mut self,
                        fty: &ty::ClosureTy)
                        -> ty::ClosureTy {
         ty::ClosureTy {
-            region: self.fold_region(fty.region),
+            store: self.fold_trait_store(fty.store),
             sig: self.fold_sig(&fty.sig),
             fn_style: fty.fn_style,
-            sigil: fty.sigil,
             onceness: fty.onceness,
             bounds: fty.bounds,
         }
index 3170fb82c88f6789c1107e2df398b3ac537804dc..99f10395437a5ee0bbd9f62e5caf254adcebb5ff 100644 (file)
@@ -112,7 +112,7 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime)
     r
 }
 
-fn opt_ast_region_to_region<AC:AstConv,RS:RegionScope>(
+pub fn opt_ast_region_to_region<AC:AstConv,RS:RegionScope>(
     this: &AC,
     rscope: &RS,
     default_span: Span,
@@ -516,33 +516,42 @@ fn mk_pointer<AC:AstConv,
                 ty::mk_bare_fn(tcx, ty_of_bare_fn(this, ast_ty.id, bf.fn_style,
                                                   bf.abi, bf.decl))
             }
-            ast::TyClosure(ref f) => {
-                if f.sigil == ast::ManagedSigil {
-                    tcx.sess.span_err(ast_ty.span,
-                                      "managed closures are not supported");
-                }
+            ast::TyClosure(ref f, ref region) => {
+
+                // resolve the function bound region in the original region
+                // scope `rscope`, not the scope of the function parameters
+                let bound_region = opt_ast_region_to_region(this, rscope,
+                                                            ast_ty.span, region);
+
+                let store = ty::RegionTraitStore(bound_region, ast::MutMutable);
+
+                // Use corresponding trait store to figure out default bounds
+                // if none were specified.
+                let bounds = conv_builtin_bounds(this.tcx(), &f.bounds, store);
 
-                let bounds = conv_builtin_bounds(this.tcx(), &f.bounds, match f.sigil {
-                        // Use corresponding trait store to figure out default bounds
-                        // if none were specified.
-                        ast::BorrowedSigil => {
-                            // dummy region
-                            ty::RegionTraitStore(ty::ReEmpty, ast::MutMutable)
-                        }
-                        ast::OwnedSigil    => ty::UniqTraitStore,
-                        ast::ManagedSigil  => return ty::mk_err()
-                    });
                 let fn_decl = ty_of_closure(this,
-                                            rscope,
                                             ast_ty.id,
-                                            f.sigil,
                                             f.fn_style,
                                             f.onceness,
                                             bounds,
-                                            &f.region,
+                                            store,
                                             f.decl,
-                                            None,
-                                            ast_ty.span);
+                                            None);
+                ty::mk_closure(tcx, fn_decl)
+            }
+            ast::TyProc(ref f) => {
+                // Use corresponding trait store to figure out default bounds
+                // if none were specified.
+                let bounds = conv_builtin_bounds(this.tcx(), &f.bounds, ty::UniqTraitStore);
+
+                let fn_decl = ty_of_closure(this,
+                                            ast_ty.id,
+                                            f.fn_style,
+                                            f.onceness,
+                                            bounds,
+                                            ty::UniqTraitStore,
+                                            f.decl,
+                                            None);
                 ty::mk_closure(tcx, fn_decl)
             }
             ast::TyPath(ref path, ref bounds, id) => {
@@ -728,43 +737,19 @@ fn ty_of_method_or_bare_fn<AC:AstConv>(this: &AC, id: ast::NodeId,
     };
 }
 
-pub fn ty_of_closure<AC:AstConv,RS:RegionScope>(
+pub fn ty_of_closure<AC:AstConv>(
     this: &AC,
-    rscope: &RS,
     id: ast::NodeId,
-    sigil: ast::Sigil,
     fn_style: ast::FnStyle,
     onceness: ast::Onceness,
     bounds: ty::BuiltinBounds,
-    opt_lifetime: &Option<ast::Lifetime>,
+    store: ty::TraitStore,
     decl: &ast::FnDecl,
-    expected_sig: Option<ty::FnSig>,
-    span: Span)
+    expected_sig: Option<ty::FnSig>)
     -> ty::ClosureTy
 {
     debug!("ty_of_fn_decl");
 
-    // resolve the function bound region in the original region
-    // scope `rscope`, not the scope of the function parameters
-    let bound_region = match opt_lifetime {
-        &Some(ref lifetime) => {
-            ast_region_to_region(this.tcx(), lifetime)
-        }
-        &None => {
-            match sigil {
-                ast::OwnedSigil | ast::ManagedSigil => {
-                    // @fn(), ~fn() default to static as the bound
-                    // on their upvars:
-                    ty::ReStatic
-                }
-                ast::BorrowedSigil => {
-                    // || defaults as normal for an omitted lifetime:
-                    opt_ast_region_to_region(this, rscope, span, opt_lifetime)
-                }
-            }
-        }
-    };
-
     // new region names that appear inside of the fn decl are bound to
     // that function type
     let rb = rscope::BindingRscope::new(id);
@@ -791,9 +776,8 @@ pub fn ty_of_closure<AC:AstConv,RS:RegionScope>(
 
     ty::ClosureTy {
         fn_style: fn_style,
-        sigil: sigil,
         onceness: onceness,
-        region: bound_region,
+        store: store,
         bounds: bounds,
         sig: ty::FnSig {binder_id: id,
                         inputs: input_tys,
index 3c28f2bac279ef2dae714ae634187faa5de59299..d9f4527e9d1e99014d0f1362794b060f6e5ccaf0 100644 (file)
@@ -2116,7 +2116,7 @@ fn unpack_expected<O>(
 
     fn check_expr_fn(fcx: &FnCtxt,
                      expr: &ast::Expr,
-                     ast_sigil_opt: Option<ast::Sigil>,
+                     store: ty::TraitStore,
                      decl: &ast::FnDecl,
                      body: ast::P<ast::Block>,
                      fn_kind: FnKind,
@@ -2126,18 +2126,11 @@ fn check_expr_fn(fcx: &FnCtxt,
         // Find the expected input/output types (if any). Substitute
         // fresh bound regions for any bound regions we find in the
         // expected types so as to avoid capture.
-        //
-        // Also try to pick up inferred style and sigil, defaulting
-        // to impure and block. Note that we only will use those for
-        // block syntax lambdas; that is, lambdas without explicit
-        // sigils.
         let expected_sty = unpack_expected(fcx,
                                            expected,
                                            |x| Some((*x).clone()));
         let error_happened = false;
         let (expected_sig,
-             expected_style,
-             expected_sigil,
              expected_onceness,
              expected_bounds) = {
             match expected_sty {
@@ -2146,47 +2139,32 @@ fn check_expr_fn(fcx: &FnCtxt,
                         replace_late_bound_regions_in_fn_sig(
                             tcx, &cenv.sig,
                             |_| fcx.inh.infcx.fresh_bound_region(expr.id));
-                    (Some(sig), cenv.fn_style, cenv.sigil,
-                     cenv.onceness, cenv.bounds)
+                    (Some(sig), cenv.onceness, cenv.bounds)
                 }
                 _ => {
                     // Not an error! Means we're inferring the closure type
-                    let mut sigil = ast::BorrowedSigil;
-                    let mut onceness = ast::Many;
                     let mut bounds = ty::EmptyBuiltinBounds();
-                    match expr.node {
+                    let onceness = match expr.node {
                         ast::ExprProc(..) => {
-                            sigil = ast::OwnedSigil;
-                            onceness = ast::Once;
                             bounds.add(ty::BoundSend);
+                            ast::Once
                         }
-                        _ => ()
-                    }
-                    (None, ast::NormalFn, sigil,
-                     onceness, bounds)
+                        _ => ast::Many
+                    };
+                    (None, onceness, bounds)
                 }
             }
         };
 
-        // If the proto is specified, use that, otherwise select a
-        // proto based on inference.
-        let (sigil, fn_style) = match ast_sigil_opt {
-            Some(p) => (p, ast::NormalFn),
-            None => (expected_sigil, expected_style)
-        };
-
         // construct the function type
         let fn_ty = astconv::ty_of_closure(fcx,
-                                           fcx.infcx(),
                                            expr.id,
-                                           sigil,
-                                           fn_style,
+                                           ast::NormalFn,
                                            expected_onceness,
                                            expected_bounds,
-                                           &None,
+                                           store,
                                            decl,
-                                           expected_sig,
-                                           expr.span);
+                                           expected_sig);
 
         let fty_sig;
         let fty = if error_happened {
@@ -2198,9 +2176,8 @@ fn check_expr_fn(fcx: &FnCtxt,
             };
             ty::mk_err()
         } else {
-            let fn_ty_copy = fn_ty.clone();
             fty_sig = fn_ty.sig.clone();
-            ty::mk_closure(tcx, fn_ty_copy)
+            ty::mk_closure(tcx, fn_ty.clone())
         };
 
         debug!("check_expr_fn_with_unifier fty={}",
@@ -2208,11 +2185,14 @@ fn check_expr_fn(fcx: &FnCtxt,
 
         fcx.write_ty(expr.id, fty);
 
-        let (inherited_style, id) =
-            ty::determine_inherited_style((fcx.ps.borrow().fn_style,
-                                            fcx.ps.borrow().def),
-                                           (fn_style, expr.id),
-                                           sigil);
+        // If the closure is a stack closure and hasn't had some non-standard
+        // style inferred for it, then check it under its parent's style.
+        // Otherwise, use its own
+        let (inherited_style, id) = match store {
+            ty::RegionTraitStore(..) => (fcx.ps.borrow().fn_style,
+                                         fcx.ps.borrow().def),
+            ty::UniqTraitStore => (ast::NormalFn, expr.id)
+        };
 
         check_fn(fcx.ccx, inherited_style, &fty_sig,
                  decl, id, body, fn_kind, fcx.inh);
@@ -2856,9 +2836,13 @@ fn check_struct_enum_variant(fcx: &FnCtxt,
         _match::check_match(fcx, expr, discrim, arms.as_slice());
       }
       ast::ExprFnBlock(decl, body) => {
+        let region = astconv::opt_ast_region_to_region(fcx,
+                                                       fcx.infcx(),
+                                                       expr.span,
+                                                       &None);
         check_expr_fn(fcx,
                       expr,
-                      Some(ast::BorrowedSigil),
+                      ty::RegionTraitStore(region, ast::MutMutable),
                       decl,
                       body,
                       Vanilla,
@@ -2867,7 +2851,7 @@ fn check_struct_enum_variant(fcx: &FnCtxt,
       ast::ExprProc(decl, body) => {
         check_expr_fn(fcx,
                       expr,
-                      Some(ast::OwnedSigil),
+                      ty::UniqTraitStore,
                       decl,
                       body,
                       Vanilla,
index d1a6c069f23073c9393bb7ed245a65d73e63c716..6a42f6485df111b38bac07d5a36cb7a052be50e2 100644 (file)
@@ -133,7 +133,6 @@ fn get_i(x: &'a Bar) -> &'a int {
 use middle::pat_util;
 use util::ppaux::{ty_to_str, region_to_str, Repr};
 
-use syntax::ast::{ManagedSigil, OwnedSigil, BorrowedSigil};
 use syntax::ast::{DefArg, DefBinding, DefLocal, DefUpvar};
 use syntax::ast;
 use syntax::ast_util;
@@ -175,9 +174,9 @@ fn region_of_def(fcx: &FnCtxt, def: ast::Def) -> ty::Region {
             tcx.region_maps.var_region(node_id)
         }
         DefUpvar(_, subdef, closure_id, body_id) => {
-            match ty::ty_closure_sigil(fcx.node_ty(closure_id)) {
-                BorrowedSigil => region_of_def(fcx, *subdef),
-                ManagedSigil | OwnedSigil => ReScope(body_id)
+            match ty::ty_closure_store(fcx.node_ty(closure_id)) {
+                ty::RegionTraitStore(..) => region_of_def(fcx, *subdef),
+                ty::UniqTraitStore => ReScope(body_id)
             }
         }
         _ => {
@@ -611,7 +610,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
     let function_type = rcx.resolve_node_type(expr.id);
     match ty::get(function_type).sty {
         ty::ty_closure(~ty::ClosureTy {
-                sigil: ast::BorrowedSigil, region: region, ..}) => {
+                store: ty::RegionTraitStore(region, _), ..}) => {
             let freevars = freevars::get_freevars(tcx, expr.id);
             if freevars.is_empty() {
                 // No free variables means that the environment
@@ -635,7 +634,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
     rcx.set_repeating_scope(repeating_scope);
 
     match ty::get(function_type).sty {
-        ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
+        ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(..), ..}) => {
             let freevars = freevars::get_freevars(tcx, expr.id);
             propagate_upupvar_borrow_kind(rcx, expr, freevars);
         }
@@ -749,8 +748,12 @@ fn constrain_callee(rcx: &mut Rcx,
     match ty::get(callee_ty).sty {
         ty::ty_bare_fn(..) => { }
         ty::ty_closure(ref closure_ty) => {
+            let region = match closure_ty.store {
+                ty::RegionTraitStore(r, _) => r,
+                ty::UniqTraitStore => ty::ReStatic
+            };
             rcx.fcx.mk_subr(true, infer::InvokeClosure(callee_expr.span),
-                            call_region, closure_ty.region);
+                            call_region, region);
         }
         _ => {
             // this should not happen, but it does if the program is
index 7159febc7f1074b402df399d0c30dd6d9de0f147..6ad3d380b286b7266ba8575066cee6067ec90b8c 100644 (file)
@@ -141,7 +141,11 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
 
         Some(adjustment) => {
             match *adjustment {
-                ty::AutoAddEnv(r, s) => {
+                ty::AutoAddEnv(store) => {
+                    let r = match store {
+                        ty::RegionTraitStore(r, _) => r,
+                        ty::UniqTraitStore => ty::ReStatic
+                    };
                     match resolve_region(fcx.infcx(),
                                          r,
                                          resolve_all | force_all) {
@@ -166,7 +170,12 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
                                         "cannot coerce non-statically resolved bare fn")
                             }
 
-                            let resolved_adj = @ty::AutoAddEnv(r1, s);
+                            let resolved_adj = @ty::AutoAddEnv(match store {
+                                ty::RegionTraitStore(..) => {
+                                    ty::RegionTraitStore(r1, ast::MutMutable)
+                                }
+                                ty::UniqTraitStore => ty::UniqTraitStore
+                            });
                             debug!("Adjustments for node {}: {:?}",
                                    id, resolved_adj);
                             tcx.adjustments.borrow_mut().insert(id, resolved_adj);
index d76bfed661e211a33f6ab7c6a340f30d31dbd83b..ee3c58aeedd0d20be895a866559b5193e996d030 100644 (file)
@@ -120,7 +120,7 @@ pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
                 });
             }
 
-            ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
+            ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(..), ..}) => {
                 return self.unpack_actual_value(a, |sty_a| {
                     self.coerce_borrowed_fn(a, sty_a, b)
                 });
@@ -343,8 +343,7 @@ pub fn coerce_borrowed_fn(&self,
                b.inf_str(self.get_ref().infcx));
 
         let fn_ty = match *sty_a {
-            ty::ty_closure(ref f) if f.sigil == ast::ManagedSigil ||
-                                     f.sigil == ast::OwnedSigil => {
+            ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
                 (*f).clone()
             }
             ty::ty_bare_fn(ref f) => {
@@ -359,8 +358,7 @@ pub fn coerce_borrowed_fn(&self,
         let a_borrowed = ty::mk_closure(
             self.get_ref().infcx.tcx,
             ty::ClosureTy {
-                sigil: ast::BorrowedSigil,
-                region: r_borrow,
+                store: ty::RegionTraitStore(r_borrow, ast::MutMutable),
                 .. *fn_ty
             });
 
@@ -393,7 +391,7 @@ fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t)
                 _ => return self.subtype(a, b)
             };
 
-            let adj = @ty::AutoAddEnv(fn_ty_b.region, fn_ty_b.sigil);
+            let adj = @ty::AutoAddEnv(fn_ty_b.store);
             let a_closure = ty::mk_closure(self.get_ref().infcx.tcx,
                                            ty::ClosureTy {
                                                 sig: fn_ty_a.sig.clone(),
index a2a7f9ec8bdffb288dbe0f80ed67d9d038084379..8c449a8f118f481e921e5e7c1f923c49c42a2052 100644 (file)
@@ -205,18 +205,32 @@ fn bare_fn_tys(&self, a: &ty::BareFnTy,
     fn closure_tys(&self, a: &ty::ClosureTy,
                    b: &ty::ClosureTy) -> cres<ty::ClosureTy> {
 
-        let p = if_ok!(self.sigils(a.sigil, b.sigil));
-        let r = if_ok!(self.contraregions(a.region, b.region));
+        let store = match (a.store, b.store) {
+            (ty::RegionTraitStore(a_r, a_m),
+             ty::RegionTraitStore(b_r, b_m)) if a_m == b_m => {
+                let r = if_ok!(self.contraregions(a_r, b_r));
+                ty::RegionTraitStore(r, a_m)
+            }
+
+            _ if a.store == b.store => {
+                a.store
+            }
+
+            _ => {
+                return Err(ty::terr_sigil_mismatch(expected_found(self, a.store, b.store)))
+            }
+        };
         let fn_style = if_ok!(self.fn_styles(a.fn_style, b.fn_style));
         let onceness = if_ok!(self.oncenesses(a.onceness, b.onceness));
         let bounds = if_ok!(self.bounds(a.bounds, b.bounds));
         let sig = if_ok!(self.fn_sigs(&a.sig, &b.sig));
-        Ok(ty::ClosureTy {fn_style: fn_style,
-                sigil: p,
-                onceness: onceness,
-                region: r,
-                bounds: bounds,
-                sig: sig})
+        Ok(ty::ClosureTy {
+            fn_style: fn_style,
+            onceness: onceness,
+            store: store,
+            bounds: bounds,
+            sig: sig
+        })
     }
 
     fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig>;
@@ -238,14 +252,6 @@ fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
         self.contratys(a, b).and_then(|t| Ok(t))
     }
 
-    fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> {
-        if p1 == p2 {
-            Ok(p1)
-        } else {
-            Err(ty::terr_sigil_mismatch(expected_found(self, p1, p2)))
-        }
-    }
-
     fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<FnStyle>;
 
     fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<abi::Abi> {
index a0817360e394d0d5db3776dc00562f7a25e76d77..c6c79608f6c316fc4f270e7e254550a94dcea9e9 100644 (file)
@@ -704,11 +704,13 @@ fn add_constraints_from_ty(&mut self,
                 self.add_constraint(index, variance);
             }
 
-            ty::ty_bare_fn(ty::BareFnTy { sig: ref sig, .. }) => {
+            ty::ty_bare_fn(ty::BareFnTy { ref sig, .. }) |
+            ty::ty_closure(~ty::ClosureTy { ref sig, store: ty::UniqTraitStore, .. }) => {
                 self.add_constraints_from_sig(sig, variance);
             }
 
-            ty::ty_closure(~ty::ClosureTy { sig: ref sig, region, .. }) => {
+            ty::ty_closure(~ty::ClosureTy { ref sig,
+                    store: ty::RegionTraitStore(region, _), .. }) => {
                 let contra = self.contravariant(variance);
                 self.add_constraints_from_region(region, contra);
                 self.add_constraints_from_sig(sig, variance);
index 3bb344548e12b2b8daeff4c242474bfa101c2149..63ea1a5ec86441be5f35e6c4a6126e49dce20aab 100644 (file)
@@ -266,21 +266,11 @@ fn bare_fn_to_str(cx: &ctxt,
     }
 
     fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> ~str {
-        let is_proc =
-            (cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
-        let is_borrowed_closure = cty.sigil == ast::BorrowedSigil;
+        let mut s = StrBuf::new();
 
-        let mut s = if is_proc || is_borrowed_closure {
-            StrBuf::new()
-        } else {
-            StrBuf::from_owned_str(cty.sigil.to_str())
-        };
-
-        match (cty.sigil, cty.region) {
-            (ast::ManagedSigil, ty::ReStatic) |
-            (ast::OwnedSigil, ty::ReStatic) => {}
-
-            (_, region) => {
+        match cty.store {
+            ty::UniqTraitStore => {}
+            ty::RegionTraitStore(region, _) => {
                 s.push_str(region_to_str(cx, "", true, region));
             }
         }
@@ -293,40 +283,24 @@ fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> ~str {
             }
         };
 
-        if is_proc {
-            s.push_str("proc");
-        } else {
-            match cty.onceness {
-                ast::Many => {}
-                ast::Once => {
-                    s.push_str(cty.onceness.to_str());
-                    s.push_char(' ');
+        match cty.store {
+            ty::UniqTraitStore => {
+                assert_eq!(cty.onceness, ast::Once);
+                s.push_str("proc");
+                push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
+            }
+            ty::RegionTraitStore(..) => {
+                match cty.onceness {
+                    ast::Many => {}
+                    ast::Once => s.push_str("once ")
                 }
-            };
-
-            if !is_borrowed_closure {
-                s.push_str("fn");
+                push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
             }
         }
 
-        if !is_borrowed_closure {
-            // Print bounds before `fn` if this is not a borrowed closure.
-            if !cty.bounds.is_empty() {
-                s.push_str(":");
-                s.push_str(cty.bounds.repr(cx));
-            }
-
-            push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
-        } else {
-            // Print bounds after the signature if this is a borrowed closure.
-            push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
-
-            if is_borrowed_closure {
-                if !cty.bounds.is_empty() {
-                    s.push_str(":");
-                    s.push_str(cty.bounds.repr(cx));
-                }
-            }
+        if !cty.bounds.is_empty() {
+            s.push_str(":");
+            s.push_str(cty.bounds.repr(cx));
         }
 
         s.into_owned()