auto merge of #13724 : nikomatsakis/rust/expr-use-visitor, r=pnkfelix

Pre-step towards issue #12624 and others: Introduce ExprUseVisitor, remove the
moves computation. ExprUseVisitor is a visitor that walks the AST for a
function and calls a delegate to inform it where borrows, copies, and moves
occur.

In this patch, I rewrite the gather_loans visitor to use ExprUseVisitor, but in
future patches, I think we could rewrite regionck, check_loans, and possibly
other passes to use it as well. This would refactor the repeated code between
those places that tries to determine where copies/moves/etc occur.

r? @alexcrichton
This commit is contained in:
bors
2014-05-01 04:36:50 -07:00
29 changed files with 1268 additions and 1634 deletions

View File

@@ -475,7 +475,6 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
visit::walk_pat(self, pattern, env)
}
fn visit_expr(&mut self, expression: &Expr, env: ()) {
self.operation.visit_id(expression.id);
visit::walk_expr(self, expression, env)
@@ -596,6 +595,30 @@ pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
visitor.result.get()
}
pub fn compute_id_range_for_fn_body(fk: &visit::FnKind,
decl: &FnDecl,
body: &Block,
sp: Span,
id: NodeId)
-> IdRange
{
/*!
* Computes the id range for a single fn body,
* ignoring nested items.
*/
let visitor = IdRangeComputingVisitor {
result: Cell::new(IdRange::max())
};
let mut id_visitor = IdVisitor {
operation: &visitor,
pass_through_items: false,
visited_outermost: false,
};
id_visitor.visit_fn(fk, decl, body, sp, id, ());
visitor.result.get()
}
pub fn is_item_impl(item: @ast::Item) -> bool {
match item.node {
ItemImpl(..) => true,