Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Track what drop obligations are established on match arms.
This is accomplished by:

1. Add `MatchMode` enum to `expr_use_visitor`.

2. Computing the match mode for each pattern via a pre-pass, and then
   passing the mode along when visiting the pattern in
   expr_use_visitor.

3. Adding a `fn matched_pat` callback to expr_use_visitor, which is
   called on interior struct and enum nodes of the pattern (as opposed
   to `fn consume_pat`, which is only invoked for identifiers at the
   leaves of the pattern), and invoking it accordingly.

Of particular interest are the `cat_downcast` instances established
when matching enum variants.
  • Loading branch information
pnkfelix committed Nov 25, 2014
1 parent 6f7cb8c commit 09d67fd
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/librustc/middle/borrowck/check_loans.rs
Expand Up @@ -103,6 +103,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
self.consume_common(consume_id, consume_span, cmt, mode);
}

fn matched_pat(&mut self,
_matched_pat: &ast::Pat,
_cmt: mc::cmt,
_mode: euv::MatchMode) { }

fn consume_pat(&mut self,
consume_pat: &ast::Pat,
cmt: mc::cmt<'tcx>,
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Expand Up @@ -88,6 +88,16 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
}
}

fn matched_pat(&mut self,
matched_pat: &ast::Pat,
cmt: mc::cmt<'tcx>,
mode: euv::MatchMode) {
debug!("matched_pat(matched_pat={}, cmt={}, mode={})",
matched_pat.repr(self.tcx()),
cmt.repr(self.tcx()),
mode);
}

fn consume_pat(&mut self,
consume_pat: &ast::Pat,
cmt: mc::cmt<'tcx>,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/check_match.rs
Expand Up @@ -18,6 +18,7 @@ use middle::def::*;
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
use middle::expr_use_visitor::{JustWrite, LoanCause, MutateMode};
use middle::expr_use_visitor::{WriteAndRead};
use middle::expr_use_visitor as euv;
use middle::mem_categorization::cmt;
use middle::pat_util::*;
use middle::ty::*;
Expand Down Expand Up @@ -1024,6 +1025,7 @@ struct MutationChecker<'a, 'tcx: 'a> {
}

impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> {
fn matched_pat(&mut self, _: &Pat, _: cmt, _: euv::MatchMode) {}
fn consume(&mut self, _: NodeId, _: Span, _: cmt, _: ConsumeMode) {}
fn consume_pat(&mut self, _: &Pat, _: cmt, _: ConsumeMode) {}
fn borrow(&mut self,
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/middle/check_rvalues.rs
Expand Up @@ -59,6 +59,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContext<'a, 'tcx> {
}
}

fn matched_pat(&mut self,
_matched_pat: &ast::Pat,
_cmt: mc::cmt,
_mode: euv::MatchMode) {}

fn consume_pat(&mut self,
_consume_pat: &ast::Pat,
_cmt: mc::cmt,
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/middle/check_static.rs
Expand Up @@ -325,6 +325,12 @@ impl<'tcx> euv::Delegate<'tcx> for GlobalChecker {
_assignment_span: Span,
_assignee_cmt: mc::cmt,
_mode: euv::MutateMode) {}

fn matched_pat(&mut self,
_: &ast::Pat,
_: mc::cmt,
_: euv::MatchMode) {}

fn consume_pat(&mut self,
_consume_pat: &ast::Pat,
_cmt: mc::cmt,
Expand Down

0 comments on commit 09d67fd

Please sign in to comment.