Skip to content

Commit 09d67fd

Browse files
committed
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.
1 parent 6f7cb8c commit 09d67fd

File tree

7 files changed

+278
-10
lines changed

7 files changed

+278
-10
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
103103
self.consume_common(consume_id, consume_span, cmt, mode);
104104
}
105105

106+
fn matched_pat(&mut self,
107+
_matched_pat: &ast::Pat,
108+
_cmt: mc::cmt,
109+
_mode: euv::MatchMode) { }
110+
106111
fn consume_pat(&mut self,
107112
consume_pat: &ast::Pat,
108113
cmt: mc::cmt<'tcx>,

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
8888
}
8989
}
9090

91+
fn matched_pat(&mut self,
92+
matched_pat: &ast::Pat,
93+
cmt: mc::cmt<'tcx>,
94+
mode: euv::MatchMode) {
95+
debug!("matched_pat(matched_pat={}, cmt={}, mode={})",
96+
matched_pat.repr(self.tcx()),
97+
cmt.repr(self.tcx()),
98+
mode);
99+
}
100+
91101
fn consume_pat(&mut self,
92102
consume_pat: &ast::Pat,
93103
cmt: mc::cmt<'tcx>,

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::def::*;
1818
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
1919
use middle::expr_use_visitor::{JustWrite, LoanCause, MutateMode};
2020
use middle::expr_use_visitor::{WriteAndRead};
21+
use middle::expr_use_visitor as euv;
2122
use middle::mem_categorization::cmt;
2223
use middle::pat_util::*;
2324
use middle::ty::*;
@@ -1024,6 +1025,7 @@ struct MutationChecker<'a, 'tcx: 'a> {
10241025
}
10251026

10261027
impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> {
1028+
fn matched_pat(&mut self, _: &Pat, _: cmt, _: euv::MatchMode) {}
10271029
fn consume(&mut self, _: NodeId, _: Span, _: cmt, _: ConsumeMode) {}
10281030
fn consume_pat(&mut self, _: &Pat, _: cmt, _: ConsumeMode) {}
10291031
fn borrow(&mut self,

src/librustc/middle/check_rvalues.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContext<'a, 'tcx> {
5959
}
6060
}
6161

62+
fn matched_pat(&mut self,
63+
_matched_pat: &ast::Pat,
64+
_cmt: mc::cmt,
65+
_mode: euv::MatchMode) {}
66+
6267
fn consume_pat(&mut self,
6368
_consume_pat: &ast::Pat,
6469
_cmt: mc::cmt,

src/librustc/middle/check_static.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ impl<'tcx> euv::Delegate<'tcx> for GlobalChecker {
325325
_assignment_span: Span,
326326
_assignee_cmt: mc::cmt,
327327
_mode: euv::MutateMode) {}
328+
329+
fn matched_pat(&mut self,
330+
_: &ast::Pat,
331+
_: mc::cmt,
332+
_: euv::MatchMode) {}
333+
328334
fn consume_pat(&mut self,
329335
_consume_pat: &ast::Pat,
330336
_cmt: mc::cmt,

0 commit comments

Comments
 (0)