use middle::expr_use_visitor as euv;
use middle::mem_categorization as mc;
use middle::mem_categorization::Categorization;
+use rustc::hir;
use rustc::hir::def_id::DefId;
-use rustc::ty::{self, Ty, TyCtxt, UpvarSubsts};
+use rustc::hir::def_id::LocalDefId;
+use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::infer::UpvarRegion;
+use rustc::ty::{self, Ty, TyCtxt, UpvarSubsts};
use syntax::ast;
use syntax_pos::Span;
-use rustc::hir;
-use rustc::hir::def_id::LocalDefId;
-use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pub fn closure_analyze(&self, body: &'gcx hir::Body) {
}
};
- let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs{
+ let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs {
if self.closure_kind(closure_def_id, closure_substs).is_none() {
Some(closure_substs)
} else {
let final_upvar_tys = self.final_upvar_tys(closure_node_id);
debug!(
"analyze_closure: id={:?} substs={:?} final_upvar_tys={:?}",
- closure_node_id,
- substs,
- final_upvar_tys
+ closure_node_id, substs, final_upvar_tys
);
- for (upvar_ty, final_upvar_ty) in substs.upvar_tys(closure_def_id, self.tcx)
- .zip(final_upvar_tys)
+ for (upvar_ty, final_upvar_ty) in substs
+ .upvar_tys(closure_def_id, self.tcx)
+ .zip(final_upvar_tys)
{
self.demand_suptype(span, upvar_ty, final_upvar_ty);
}
debug!(
"var_id={:?} freevar_ty={:?} capture={:?}",
- var_node_id,
- freevar_ty,
- capture
+ var_node_id, freevar_ty, capture
);
match capture {
},
),
}
- })
- .collect()
+ }).collect()
})
}
}
}
impl<'a, 'gcx, 'tcx> InferBorrowKind<'a, 'gcx, 'tcx> {
- fn adjust_upvar_borrow_kind_for_consume(&mut self, cmt: &mc::cmt_<'tcx>,
- mode: euv::ConsumeMode) {
+ fn adjust_upvar_borrow_kind_for_consume(
+ &mut self,
+ cmt: &mc::cmt_<'tcx>,
+ mode: euv::ConsumeMode,
+ ) {
debug!(
"adjust_upvar_borrow_kind_for_consume(cmt={:?}, mode={:?})",
- cmt,
- mode
+ cmt, mode
);
// we only care about moves
debug!("adjust_upvar_borrow_kind_for_mut(cmt={:?})", cmt);
match cmt.cat.clone() {
- Categorization::Deref(base, mc::Unique) |
- Categorization::Interior(base, _) |
- Categorization::Downcast(base, _) => {
+ Categorization::Deref(base, mc::Unique)
+ | Categorization::Interior(base, _)
+ | Categorization::Downcast(base, _) => {
// Interior or owned data is mutable if base is
// mutable, so iterate to the base.
self.adjust_upvar_borrow_kind_for_mut(&base);
}
}
- Categorization::Deref(_, mc::UnsafePtr(..)) |
- Categorization::StaticItem |
- Categorization::ThreadLocal(..) |
- Categorization::Rvalue(..) |
- Categorization::Local(_) |
- Categorization::Upvar(..) => {
+ Categorization::Deref(_, mc::UnsafePtr(..))
+ | Categorization::StaticItem
+ | Categorization::ThreadLocal(..)
+ | Categorization::Rvalue(..)
+ | Categorization::Local(_)
+ | Categorization::Upvar(..) => {
return;
}
}
debug!("adjust_upvar_borrow_kind_for_unique(cmt={:?})", cmt);
match cmt.cat.clone() {
- Categorization::Deref(base, mc::Unique) |
- Categorization::Interior(base, _) |
- Categorization::Downcast(base, _) => {
+ Categorization::Deref(base, mc::Unique)
+ | Categorization::Interior(base, _)
+ | Categorization::Downcast(base, _) => {
// Interior or owned data is unique if base is
// unique.
self.adjust_upvar_borrow_kind_for_unique(&base);
}
}
- Categorization::Deref(_, mc::UnsafePtr(..)) |
- Categorization::StaticItem |
- Categorization::ThreadLocal(..) |
- Categorization::Rvalue(..) |
- Categorization::Local(_) |
- Categorization::Upvar(..) => {}
+ Categorization::Deref(_, mc::UnsafePtr(..))
+ | Categorization::StaticItem
+ | Categorization::ThreadLocal(..)
+ | Categorization::Rvalue(..)
+ | Categorization::Local(_)
+ | Categorization::Upvar(..) => {}
}
}
- fn try_adjust_upvar_deref(&mut self, cmt: &mc::cmt_<'tcx>, borrow_kind: ty::BorrowKind)
- -> bool
- {
+ fn try_adjust_upvar_deref(
+ &mut self,
+ cmt: &mc::cmt_<'tcx>,
+ borrow_kind: ty::BorrowKind,
+ ) -> bool {
assert!(match borrow_kind {
ty::MutBorrow => true,
ty::UniqueImmBorrow => true,
/// Here the argument `mutbl` is the borrow_kind that is required by
/// some particular use.
fn adjust_upvar_borrow_kind(&mut self, upvar_id: ty::UpvarId, kind: ty::BorrowKind) {
- let upvar_capture = self.adjust_upvar_captures
+ let upvar_capture = self
+ .adjust_upvar_captures
.get(&upvar_id)
.cloned()
.unwrap_or_else(|| self.fcx.tables.borrow().upvar_capture(upvar_id));
debug!(
"adjust_upvar_borrow_kind(upvar_id={:?}, upvar_capture={:?}, kind={:?})",
- upvar_id,
- upvar_capture,
- kind
+ upvar_id, upvar_capture, kind
);
match upvar_capture {
ty::UpvarCapture::ByRef(mut upvar_borrow) => {
match (upvar_borrow.kind, kind) {
// Take RHS:
- (ty::ImmBorrow, ty::UniqueImmBorrow) |
- (ty::ImmBorrow, ty::MutBorrow) |
- (ty::UniqueImmBorrow, ty::MutBorrow) => {
+ (ty::ImmBorrow, ty::UniqueImmBorrow)
+ | (ty::ImmBorrow, ty::MutBorrow)
+ | (ty::UniqueImmBorrow, ty::MutBorrow) => {
upvar_borrow.kind = kind;
self.adjust_upvar_captures
.insert(upvar_id, ty::UpvarCapture::ByRef(upvar_borrow));
}
// Take LHS:
- (ty::ImmBorrow, ty::ImmBorrow) |
- (ty::UniqueImmBorrow, ty::ImmBorrow) |
- (ty::UniqueImmBorrow, ty::UniqueImmBorrow) |
- (ty::MutBorrow, _) => {}
+ (ty::ImmBorrow, ty::ImmBorrow)
+ | (ty::UniqueImmBorrow, ty::ImmBorrow)
+ | (ty::UniqueImmBorrow, ty::UniqueImmBorrow)
+ | (ty::MutBorrow, _) => {}
}
}
}
) {
debug!(
"adjust_closure_kind(closure_id={:?}, new_kind={:?}, upvar_span={:?}, var_name={})",
- closure_id,
- new_kind,
- upvar_span,
- var_name
+ closure_id, new_kind, upvar_span, var_name
);
// Is this the closure whose kind is currently being inferred?
debug!(
"adjust_closure_kind: closure_id={:?}, existing_kind={:?}, new_kind={:?}",
- closure_id,
- existing_kind,
- new_kind
+ closure_id, existing_kind, new_kind
);
match (existing_kind, new_kind) {
- (ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
- (ty::ClosureKind::FnMut, ty::ClosureKind::Fn) |
- (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut) |
- (ty::ClosureKind::FnOnce, _) => {
+ (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
+ | (ty::ClosureKind::FnMut, ty::ClosureKind::Fn)
+ | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
+ | (ty::ClosureKind::FnOnce, _) => {
// no change needed
}
- (ty::ClosureKind::Fn, ty::ClosureKind::FnMut) |
- (ty::ClosureKind::Fn, ty::ClosureKind::FnOnce) |
- (ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
+ (ty::ClosureKind::Fn, ty::ClosureKind::FnMut)
+ | (ty::ClosureKind::Fn, ty::ClosureKind::FnOnce)
+ | (ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
// new kind is stronger than the old kind
self.current_closure_kind = new_kind;
self.current_origin = Some((upvar_span, var_name));
self.adjust_upvar_borrow_kind_for_consume(cmt, mode);
}
- fn matched_pat(&mut self, _matched_pat: &hir::Pat, _cmt: &mc::cmt_<'tcx>,
- _mode: euv::MatchMode) {
+ fn matched_pat(
+ &mut self,
+ _matched_pat: &hir::Pat,
+ _cmt: &mc::cmt_<'tcx>,
+ _mode: euv::MatchMode,
+ ) {
}
- fn consume_pat(&mut self, _consume_pat: &hir::Pat, cmt: &mc::cmt_<'tcx>,
- mode: euv::ConsumeMode) {
+ fn consume_pat(
+ &mut self,
+ _consume_pat: &hir::Pat,
+ cmt: &mc::cmt_<'tcx>,
+ mode: euv::ConsumeMode,
+ ) {
debug!("consume_pat(cmt={:?},mode={:?})", cmt, mode);
self.adjust_upvar_borrow_kind_for_consume(cmt, mode);
}
) {
debug!(
"borrow(borrow_id={}, cmt={:?}, bk={:?})",
- borrow_id,
- cmt,
- bk
+ borrow_id, cmt, bk
);
match bk {