- fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
- if let Categorization::Local(lid) = cmt.cat {
- if let Move(DirectRefMove) | Move(CaptureMove) = mode {
- // moved out or in. clearly can't be localized
- self.set.remove(&lid);
- }
- }
- }
- 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 is_argument(map, consume_pat.hir_id) {
- // Skip closure arguments
- let parent_id = map.get_parent_node(consume_pat.hir_id);
- if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_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(map.get_parent_node(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
- }
+ 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);