- fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
- fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
- let map = &self.cx.tcx.hir();
- if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
- // Skip closure arguments
- if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) {
- return;
- }
- if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
- self.set.insert(consume_pat.hir_id);
- }
- return;
- }
- if let Categorization::Rvalue(..) = cmt.cat {
- if let Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(cmt.hir_id)) {
- if let StmtKind::Local(ref loc) = st.node {
- if let Some(ref ex) = loc.init {
- if let ExprKind::Box(..) = ex.node {
- if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
- // let x = box (...)
- self.set.insert(consume_pat.hir_id);
- }
- // TODO Box::new
- // TODO vec![]
- // TODO "foo".to_owned() and friends
- }
+
+ match map.find(map.get_parent_node(id)) {
+ Some(Node::Param(_)) => true,
+ _ => false,
+ }
+}
+
+impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
+ fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) {
+ if cmt.projections.is_empty() {
+ if let PlaceBase::Local(lid) = cmt.base {
+ if let ConsumeMode::Move = mode {
+ // moved out or in. clearly can't be localized
+ self.set.remove(&lid);
+ }
+ let map = &self.cx.tcx.hir();
+ if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
+ if self.set.contains(&lid) {
+ // let y = x where x is known
+ // remove x, insert y
+ self.set.insert(cmt.hir_id);
+ self.set.remove(&lid);