let mut n_uniq = 0i;
ty::fold_ty(cx.tcx, ty, |t| {
match t.sty {
- ty::ty_uniq(_) |
- ty::ty_closure(box ty::ClosureTy {
- store: ty::UniqTraitStore,
- ..
- }) => {
+ ty::ty_uniq(_) => {
n_uniq += 1;
}
ty::ty_str => {
mywrite!(w, "v");
}
- ty::ty_closure(ref f) => {
- mywrite!(w, "f");
- enc_closure_ty(w, cx, &**f);
- }
ty::ty_bare_fn(Some(def_id), f) => {
mywrite!(w, "F");
mywrite!(w, "{}|", (cx.ds)(def_id));
fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty {
ty::ty_bare_fn(_, ref f) => f.unsafety == ast::Unsafety::Unsafe,
- ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe,
_ => false,
}
}
ty::ty_bare_fn(..) => {
self.consume_expr(callee);
}
- ty::ty_closure(ref f) => {
- match f.onceness {
- ast::Many => {
- self.borrow_expr(callee,
- ty::ReScope(call_scope),
- ty::UniqueImmBorrow,
- ClosureInvocation);
- }
- ast::Once => {
- self.consume_expr(callee);
- }
- }
- }
ty::ty_err => { }
_ => {
let overloaded_call_type =
ty::ty_tup(ref tys) => {
Some(TupleSimplifiedType(tys.len()))
}
- ty::ty_closure(ref f) => {
- Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
- }
ty::ty_bare_fn(_, ref f) => {
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
}
};
}
- ty::ty_closure(box ty::ClosureTy {
- store: ty::RegionTraitStore(..),
- ..
- }) => {
- return self.unpack_actual_value(a, |a| {
- self.coerce_borrowed_fn(a, b)
- });
- }
-
_ => {}
}
a.repr(self.tcx()), b.repr(self.tcx()));
match b.sty {
- ty::ty_closure(ref f) => {
- if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal {
- return self.subtype(a, b);
- }
-
- let fn_ty_b = (*f).clone();
- let adj = ty::AdjustAddEnv(fn_def_id_a, fn_ty_b.store);
- let a_closure = ty::mk_closure(self.tcx(),
- ty::ClosureTy {
- sig: fn_ty_a.sig.clone(),
- .. *fn_ty_b
- });
- try!(self.subtype(a_closure, b));
- Ok(Some(adj))
- }
ty::ty_bare_fn(None, _) => {
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, fn_ty_a);
try!(self.subtype(a_fn_pointer, b));
Ok(ty::mk_bare_fn(tcx, a_opt_def_id, tcx.mk_bare_fn(fty)))
}
- (&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
- this.closure_tys(&**a_fty, &**b_fty).and_then(|fty| {
- Ok(ty::mk_closure(tcx, fty))
- })
- }
-
(&ty::ty_projection(ref a_data), &ty::ty_projection(ref b_data)) => {
let projection_ty = try!(this.projection_tys(a_data, b_data));
Ok(ty::mk_projection(tcx, projection_ty.trait_ref, projection_ty.item_name))
ty::ty_ptr(..) |
ty::ty_rptr(..) |
ty::ty_bare_fn(..) |
- ty::ty_closure(..) |
ty::ty_trait(..) |
ty::ty_struct(..) |
ty::ty_unboxed_closure(..) |
// pointer adjustment).
pub fn deref_kind(t: Ty) -> McResult<deref_kind> {
match t.sty {
- ty::ty_uniq(_) |
- ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
+ ty::ty_uniq(_) => {
Ok(deref_ptr(Unique))
}
Ok(deref_ptr(BorrowedPtr(kind, *r)))
}
- ty::ty_closure(box ty::ClosureTy {
- store: ty::RegionTraitStore(r, _),
- ..
- }) => {
- Ok(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
- }
-
ty::ty_ptr(ref mt) => {
Ok(deref_ptr(UnsafePtr(mt.mutbl)))
}
def::DefUpvar(var_id, fn_node_id, _) => {
let ty = try!(self.node_ty(fn_node_id));
match ty.sty {
- ty::ty_closure(ref closure_ty) => {
- // Translate old closure type info into unboxed
- // closure kind/capture mode
- let (mode, kind) = match (closure_ty.store, closure_ty.onceness) {
- // stack closure
- (ty::RegionTraitStore(..), ast::Many) => {
- (ast::CaptureByRef, ty::FnMutUnboxedClosureKind)
- }
- // proc or once closure
- (_, ast::Once) => {
- (ast::CaptureByValue, ty::FnOnceUnboxedClosureKind)
- }
- // There should be no such old closure type
- (ty::UniqTraitStore, ast::Many) => {
- self.tcx().sess.span_bug(span, "Impossible closure type");
- }
- };
- self.cat_upvar(id, span, var_id, fn_node_id, kind, mode, false)
- }
ty::ty_unboxed_closure(closure_id, _, _) => {
let kind = self.typer.unboxed_closure_kind(closure_id);
let mode = self.typer.capture_mode(fn_node_id);
ty::ty_float(..) |
ty::ty_str(..) |
ty::ty_bare_fn(..) |
- ty::ty_closure(..) |
ty::ty_vec(..) |
ty::ty_ptr(..) |
ty::ty_rptr(..) |
}
}
- ty::ty_closure(ref c) => {
- match c.store {
- ty::UniqTraitStore => {
- // proc: Equivalent to `Box<FnOnce>`
- match bound {
- ty::BoundCopy => {
- Err(Unimplemented)
- }
-
- ty::BoundSized => {
- Ok(If(Vec::new()))
- }
-
- ty::BoundSync |
- ty::BoundSend => {
- if c.bounds.builtin_bounds.contains(&bound) {
- Ok(If(Vec::new()))
- } else {
- Err(Unimplemented)
- }
- }
- }
- }
- ty::RegionTraitStore(_, mutbl) => {
- // ||: Equivalent to `&FnMut` or `&mut FnMut` or something like that.
- match bound {
- ty::BoundCopy => {
- match mutbl {
- ast::MutMutable => {
- // &mut T is affine
- Err(Unimplemented)
- }
- ast::MutImmutable => {
- // &T is copyable, no matter what T is
- Ok(If(Vec::new()))
- }
- }
- }
-
- ty::BoundSized => {
- Ok(If(Vec::new()))
- }
-
- ty::BoundSync |
- ty::BoundSend => {
- if c.bounds.builtin_bounds.contains(&bound) {
- Ok(If(Vec::new()))
- } else {
- Err(Unimplemented)
- }
- }
- }
- }
- }
- }
-
ty::ty_trait(ref data) => {
match bound {
ty::BoundSized => {
pub fn print_debug_stats(&self) {
sty_debug_print!(
self,
- ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_closure, ty_trait,
+ ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_trait,
ty_struct, ty_unboxed_closure, ty_tup, ty_param, ty_open, ty_infer, ty_projection);
println!("Substs interner: #{}", self.substs_interner.borrow().len());
// fn item. Otherwise, if None(_), it a fn pointer type.
ty_bare_fn(Option<DefId>, &'tcx BareFnTy<'tcx>),
- ty_closure(Box<ClosureTy<'tcx>>),
ty_trait(Box<TyTrait<'tcx>>),
ty_struct(DefId, &'tcx Substs<'tcx>),
&ty_bare_fn(_, ref f) => {
self.add_fn_sig(&f.sig);
}
-
- &ty_closure(ref f) => {
- if let RegionTraitStore(r, _) = f.store {
- self.add_region(r);
- }
- self.add_fn_sig(&f.sig);
- self.add_bounds(&f.bounds);
- }
}
}
}
pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> {
- mk_t(cx, ty_closure(box fty))
+ panic!("stub");
}
pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>,
pub fn type_is_structural(ty: Ty) -> bool {
match ty.sty {
- ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_closure(_) |
+ ty_struct(..) | ty_tup(_) | ty_enum(..) |
ty_vec(_, Some(_)) | ty_unboxed_closure(..) => true,
_ => type_is_slice(ty) | type_is_trait(ty)
}
TC::None
}
- ty_closure(ref c) => {
- closure_contents(&**c) | TC::ReachesFfiUnsafe
- }
-
ty_uniq(typ) => {
TC::ReachesFfiUnsafe | match typ.sty {
ty_str => TC::OwnsOwned,
ty_float(_) |
ty_str |
ty_bare_fn(..) |
- ty_closure(_) |
ty_param(_) |
ty_projection(_) |
ty_vec(_, None) => {
pub fn fn_is_variadic(fty: Ty) -> bool {
match fty.sty {
ty_bare_fn(_, ref f) => f.sig.0.variadic,
- ty_closure(ref f) => f.sig.0.variadic,
ref s => {
panic!("fn_is_variadic() called on non-fn type: {}", s)
}
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> {
match fty.sty {
ty_bare_fn(_, ref f) => &f.sig,
- ty_closure(ref f) => &f.sig,
ref s => {
panic!("ty_fn_sig() called on non-fn type: {}", s)
}
pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
match fty.sty {
ty_bare_fn(_, ref f) => f.abi,
- ty_closure(ref f) => f.abi,
_ => panic!("ty_fn_abi() called on non-fn type"),
}
}
pub fn ty_closure_store(fty: Ty) -> TraitStore {
match fty.sty {
- ty_closure(ref f) => f.store,
ty_unboxed_closure(..) => {
// Close enough for the purposes of all the callers of this
// function (which is soon to be deprecated anyhow).
pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> {
match fty.sty {
ty_bare_fn(_, ref f) => f.sig.0.output,
- ty_closure(ref f) => f.sig.0.output,
ref s => {
panic!("ty_fn_ret() called on non-fn type: {}", s)
}
pub fn is_fn_ty(fty: Ty) -> bool {
match fty.sty {
ty_bare_fn(..) => true,
- ty_closure(_) => true,
_ => false
}
}
ty_rptr(_, _) => "&-ptr".to_string(),
ty_bare_fn(Some(_), _) => format!("fn item"),
ty_bare_fn(None, _) => "fn pointer".to_string(),
- ty_closure(_) => "fn".to_string(),
ty_trait(ref inner) => {
format!("trait {}", item_path_str(cx, inner.principal_def_id()))
}
fn_sig(state, &b.sig);
return false;
}
- ty_closure(ref c) => {
- byte!(15);
- hash!(c.unsafety);
- hash!(c.onceness);
- hash!(c.bounds);
- match c.store {
- UniqTraitStore => byte!(0),
- RegionTraitStore(r, m) => {
- byte!(1);
- region(state, r);
- assert_eq!(m, ast::MutMutable);
- }
- }
-
- fn_sig(state, &c.sig);
-
- return false;
- }
ty_trait(ref data) => {
byte!(17);
did(state, data.principal_def_id());
ty_struct(_, substs) => {
accum_substs(accumulator, substs);
}
- ty_closure(ref closure_ty) => {
- match closure_ty.store {
- RegionTraitStore(region, _) => accumulator.push(region),
- UniqTraitStore => {}
- }
- }
ty_unboxed_closure(_, region, substs) => {
accumulator.push(*region);
accum_substs(accumulator, substs);
let bfn = f.fold_with(this);
ty::ty_bare_fn(opt_def_id, this.tcx().mk_bare_fn(bfn))
}
- ty::ty_closure(ref f) => {
- ty::ty_closure(f.fold_with(this))
- }
ty::ty_rptr(r, ref tm) => {
let r = r.fold_with(this);
ty::ty_rptr(this.tcx().mk_region(r), tm.fold_with(this))
ty::ty_bare_fn(_, ref ft) => {
self.push_sig_subtypes(&ft.sig);
}
- ty::ty_closure(ref ft) => {
- self.push_sig_subtypes(&ft.sig);
- }
}
}
use middle::ty::{ReSkolemized, ReVar, BrEnv};
use middle::ty::{mt, Ty, ParamTy};
use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum};
-use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
+use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn};
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open};
use middle::ty::{ty_unboxed_closure};
use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
strs => format!("({})", strs.connect(", "))
}
}
- ty_closure(ref f) => {
- closure_to_string(cx, &**f)
- }
ty_bare_fn(opt_def_id, ref f) => {
bare_fn_to_string(cx, opt_def_id, f.unsafety, f.abi, None, &f.sig)
}
default_msgs: (&'static str, &'static str))
-> (&'static str, &'static str) {
match ty.sty {
- ty::ty_closure(box 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(param_env, span, ty) {
("non-copyable",
// Functions are just pointers
ty::ty_bare_fn(..) => Some(path),
- // Closures are a pair of pointers: the code and environment
- ty::ty_closure(..) => {
- path.push(FAT_PTR_ADDR);
- Some(path)
- },
-
// Is this the NonZero lang item wrapping a pointer or integer type?
ty::ty_struct(did, substs) if Some(did) == tcx.lang_items.non_zero() => {
let nonzero_fields = ty::lookup_struct_fields(tcx, did);
ty::ty_bare_fn(_, ref f) => {
(f.sig.0.inputs.clone(), f.sig.0.output, f.abi, None)
}
- ty::ty_closure(ref f) => {
- (f.sig.0.inputs.clone(), f.sig.0.output, f.abi, Some(Type::i8p(ccx)))
- }
ty::ty_unboxed_closure(closure_did, _, substs) => {
let typer = common::NormalizingUnboxedClosureTyper::new(ccx.tcx());
let function_type = typer.unboxed_closure_type(closure_did, substs);
}
}
}
- ty::ty_closure(_) => {
- get_extern_rust_fn(ccx, t, name[], did)
- }
_ => {
get_extern_const(ccx, did, t)
}
use middle::ty::{BrAnon, ReLateBound};
let (fn_sig, abi, has_env) = match fn_ty.sty {
- ty::ty_closure(ref f) => (f.sig.clone(), f.abi, true),
ty::ty_bare_fn(_, ref f) => (f.sig.clone(), f.abi, false),
ty::ty_unboxed_closure(closure_did, _, substs) => {
let typer = common::NormalizingUnboxedClosureTyper::new(ccx.tcx());
data: Fn(llval),
};
}
- ty::ty_closure(..) => {
- let datum = unpack_datum!(
- bcx, datum.to_lvalue_datum(bcx, "callee", expr.id));
- return Callee {
- bcx: bcx,
- data: Closure(datum),
- };
- }
_ => {
bcx.tcx().sess.span_bug(
expr.span,
let (abi, ret_ty) = match callee_ty.sty {
ty::ty_bare_fn(_, ref f) => (f.abi, f.sig.0.output),
- ty::ty_closure(ref f) => (f.abi, f.sig.0.output),
_ => panic!("expected bare rust fn or closure in trans_call_inner")
};
debug!("get_wrapper_for_bare_fn(closure_ty={})", closure_ty.repr(tcx));
let f = match closure_ty.sty {
- ty::ty_closure(ref f) => f,
_ => {
ccx.sess().bug(format!("get_wrapper_for_bare_fn: \
expected a closure ty, got {}",
}
}
},
- ty::ty_closure(box ref closure_ty) => {
- self.get_unique_type_id_of_closure_type(cx,
- closure_ty.clone(),
- &mut unique_type_id);
- },
ty::ty_unboxed_closure(def_id, _, substs) => {
let typer = NormalizingUnboxedClosureTyper::new(cx.tcx());
let closure_ty = typer.unboxed_closure_type(def_id, substs);
ty::ty_bare_fn(_, ref barefnty) => {
subroutine_type_metadata(cx, unique_type_id, &barefnty.sig, usage_site_span)
}
- ty::ty_closure(ref closurety) => {
- subroutine_type_metadata(cx, unique_type_id, &closurety.sig, usage_site_span)
- }
ty::ty_unboxed_closure(def_id, _, substs) => {
let typer = NormalizingUnboxedClosureTyper::new(cx.tcx());
let sig = typer.unboxed_closure_type(def_id, substs).sig;
}
}
},
- ty::ty_closure(box ty::ClosureTy { unsafety,
- onceness,
- store,
- ref sig,
- .. // omitting bounds ...
- }) => {
- if unsafety == ast::Unsafety::Unsafe {
- output.push_str("unsafe ");
- }
-
- if onceness == ast::Once {
- output.push_str("once ");
- }
-
- let param_list_closing_char;
- match store {
- ty::UniqTraitStore => {
- output.push_str("proc(");
- param_list_closing_char = ')';
- }
- ty::RegionTraitStore(_, ast::MutMutable) => {
- output.push_str("&mut|");
- param_list_closing_char = '|';
- }
- ty::RegionTraitStore(_, ast::MutImmutable) => {
- output.push_str("&|");
- param_list_closing_char = '|';
- }
- };
-
- if sig.0.inputs.len() > 0 {
- for ¶meter_type in sig.0.inputs.iter() {
- push_debuginfo_type_name(cx, parameter_type, true, output);
- output.push_str(", ");
- }
- output.pop();
- output.pop();
- }
-
- if sig.0.variadic {
- if sig.0.inputs.len() > 0 {
- output.push_str(", ...");
- } else {
- output.push_str("...");
- }
- }
-
- output.push(param_list_closing_char);
-
- match sig.0.output {
- ty::FnConverging(result_type) if ty::type_is_nil(result_type) => {}
- ty::FnConverging(result_type) => {
- output.push_str(" -> ");
- push_debuginfo_type_name(cx, result_type, true, output);
- }
- ty::FnDiverging => {
- output.push_str(" -> !");
- }
- }
- },
ty::ty_unboxed_closure(..) => {
output.push_str("closure");
}
v0,
t,
|bb, vv, tt| drop_ty(bb, vv, tt, None)),
- ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
- let box_cell_v = GEPi(bcx, v0, &[0u, abi::FAT_PTR_EXTRA]);
- let env = Load(bcx, box_cell_v);
- let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
- let env = PointerCast(bcx, env, env_ptr_ty);
- with_cond(bcx, IsNotNull(bcx, env), |bcx| {
- let dtor_ptr = GEPi(bcx, env, &[0u, abi::BOX_FIELD_DROP_GLUE]);
- let dtor = Load(bcx, dtor_ptr);
- Call(bcx, dtor, &[PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
- bcx
- })
- }
ty::ty_trait(..) => {
// No need to do a null check here (as opposed to the Box<trait case
// above), because this happens for a trait field in an unsized
// Given a function type and a count of ty params, construct an llvm type
pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type {
match fty.sty {
- ty::ty_closure(ref f) => {
- type_of_rust_fn(cx,
- Some(Type::i8p(cx)),
- f.sig.0.inputs.as_slice(),
- f.sig.0.output,
- f.abi)
- }
ty::ty_bare_fn(_, ref f) => {
// FIXME(#19925) once fn item types are
// zero-sized, we'll need to do something here
}
ty::ty_bare_fn(..) => Type::i8p(cx),
- ty::ty_closure(..) => Type::struct_(cx, &[Type::i8p(cx), Type::i8p(cx)], false),
ty::ty_vec(ty, Some(size)) => {
let llty = sizing_type_of(cx, ty);
ty::ty_bare_fn(..) => {
type_of_fn_from_ty(cx, t).ptr_to()
}
- ty::ty_closure(_) => {
- let fn_ty = type_of_fn_from_ty(cx, t).ptr_to();
- Type::struct_(cx, &[fn_ty, Type::i8p(cx)], false)
- }
ty::ty_tup(ref tys) if tys.is_empty() => Type::nil(cx),
ty::ty_tup(..) => {
let repr = adt::represent_type(cx, t);
{
// If the callee is a bare function or a closure, then we're all set.
match structurally_resolved_type(fcx, callee_expr.span, adjusted_ty).sty {
- ty::ty_bare_fn(..) | ty::ty_closure(_) => {
+ ty::ty_bare_fn(..) => {
fcx.write_adjustment(callee_expr.id,
callee_expr.span,
ty::AdjustDerefRef(autoderefref));
let error_fn_sig;
let fn_sig = match callee_ty.sty {
- ty::ty_bare_fn(_, &ty::BareFnTy {ref sig, ..}) |
- ty::ty_closure(box ty::ClosureTy {ref sig, ..}) => {
+ ty::ty_bare_fn(_, &ty::BareFnTy {ref sig, ..}) => {
sig
}
_ => {
// fresh bound regions for any bound regions we find in the
// expected types so as to avoid capture.
let expected_cenv = expected.map_to_option(fcx, |ty| match ty.sty {
- ty::ty_closure(ref cenv) => Some(cenv),
_ => None
});
let (expected_sig, expected_onceness, expected_bounds) = match expected_cenv {
method_callee: &MethodCallee) {
let sig = match method_callee.ty.sty {
ty::ty_bare_fn(_, ref f) => f.sig.clone(),
- ty::ty_closure(ref f) => f.sig.clone(),
_ => return,
};
let function_type = rcx.resolve_node_type(expr.id);
match function_type.sty {
- ty::ty_closure(box ty::ClosureTy{store: ty::RegionTraitStore(..),
- ref bounds,
- ..}) => {
- // For closure, ensure that the variables outlive region
- // bound, since they are captured by reference.
- ty::with_freevars(tcx, expr.id, |freevars| {
- if freevars.is_empty() {
- // No free variables means that the environment
- // will be NULL at runtime and hence the closure
- // has static lifetime.
- } else {
- // Variables being referenced must outlive closure.
- constrain_free_variables_in_by_ref_closure(
- rcx, bounds.region_bound, expr, freevars);
-
- // Closure is stack allocated and hence cannot
- // outlive the appropriate temporary scope.
- let s = rcx.repeating_scope;
- rcx.fcx.mk_subr(infer::InfStackClosure(expr.span),
- bounds.region_bound, ty::ReScope(CodeExtent::from_node_id(s)));
- }
- });
- }
ty::ty_unboxed_closure(_, region, _) => {
if tcx.capture_modes.borrow()[expr.id].clone() == ast::CaptureByRef {
ty::with_freevars(tcx, expr.id, |freevars| {
rcx.set_repeating_scope(repeating_scope);
match function_type.sty {
- ty::ty_closure(box ty::ClosureTy {ref bounds, ..}) => {
- ty::with_freevars(tcx, expr.id, |freevars| {
- ensure_free_variable_types_outlive_closure_bound(rcx, bounds, expr, freevars);
- })
- }
ty::ty_unboxed_closure(_, region, _) => {
ty::with_freevars(tcx, expr.id, |freevars| {
let bounds = ty::region_existential_bound(*region);
let callee_ty = rcx.resolve_node_type(callee_id);
match callee_ty.sty {
ty::ty_bare_fn(..) => { }
- ty::ty_closure(ref closure_ty) => {
- let region = match closure_ty.store {
- ty::RegionTraitStore(r, _) => {
- // While we're here, link the closure's region with a unique
- // immutable borrow (gathered later in borrowck)
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
- let expr_cmt = ignore_err!(mc.cat_expr(callee_expr));
- link_region(rcx, callee_expr.span, call_region,
- ty::UniqueImmBorrow, expr_cmt);
- r
- }
- ty::UniqTraitStore => ty::ReStatic
- };
- rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span),
- call_region, region);
-
- let region = closure_ty.bounds.region_bound;
- rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span),
- call_region, region);
- }
_ => {
// this should not happen, but it does if the program is
// erroneous
// No borrowed content reachable here.
}
- ty::ty_closure(box ref c) => {
- self.accumulate_from_closure_ty(ty, c);
- }
-
ty::ty_unboxed_closure(_, region, _) => {
// An "unboxed closure type" is basically
// modeled here as equivalent to a struct like
_body: &ast::Block)
{
let is_old_skool_closure = match self.fcx.expr_ty(expr).sty {
- ty::ty_closure(..) => true,
_ => false,
};
use middle::ty::RegionEscape;
use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId};
use middle::ty::{ParameterEnvironment, TypeTraitItemId, lookup_item_type};
-use middle::ty::{Ty, ty_bool, ty_char, ty_closure, ty_enum, ty_err};
+use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err};
use middle::ty::{ty_param, TypeScheme, ty_ptr};
use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup};
use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open};
}
ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) |
- ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_closure(..) | ty_tup(..) |
+ ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_tup(..) |
ty_param(..) | ty_err | ty_open(..) | ty_uniq(_) |
ty_ptr(_) | ty_rptr(_, _) | ty_projection(..) => {
None
}
}
- ty::ty_bare_fn(_, &ty::BareFnTy { ref sig, .. }) |
- ty::ty_closure(box ty::ClosureTy {
- ref sig,
- store: ty::UniqTraitStore,
- ..
- }) =>
- {
- self.add_constraints_from_sig(generics, sig, variance);
- }
-
- ty::ty_closure(box ty::ClosureTy { ref sig,
- store: ty::RegionTraitStore(region, _), .. }) => {
- let contra = self.contravariant(variance);
- self.add_constraints_from_region(generics, region, contra);
+ ty::ty_bare_fn(_, &ty::BareFnTy { ref sig, .. }) => {
self.add_constraints_from_sig(generics, sig, variance);
}
decl: (ast_util::local_def(0), &fty.sig).clean(cx),
abi: fty.abi.to_string(),
}),
- ty::ty_closure(ref fty) => {
- let decl = box ClosureDecl {
- lifetimes: Vec::new(), // FIXME: this looks wrong...
- decl: (ast_util::local_def(0), &fty.sig).clean(cx),
- onceness: fty.onceness,
- unsafety: fty.unsafety,
- bounds: fty.bounds.clean(cx),
- };
- match fty.store {
- ty::UniqTraitStore => Proc(decl),
- ty::RegionTraitStore(..) => Closure(decl),
- }
- }
ty::ty_struct(did, substs) |
ty::ty_enum(did, substs) => {
let fqn = csearch::get_item_path(cx.tcx(), did);