Skip to content

Commit 41e7924

Browse files
committed
Fix #7740: gather_loans should not recur into the items of the block.
gather_loans does not need to recurse into any items declared in the current block. Rather than special-case `fk_item_fn` and `fk_method`, just make the GatherLoanVisitor's visit_item method a no-op. This indirectly implies that the example of #7740 is fixed: fn f() { static A: &'static char = &'A'; } Since we do not recurse into items, we no longer encounter `&'A'`.
1 parent 45c3ca7 commit 41e7924

File tree

1 file changed

+6
-3
lines changed
  • src/librustc/middle/borrowck/gather_loans

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ impl visit::Visitor<@mut GatherLoanCtxt> for GatherLoanVisitor {
9595
fn visit_local(&mut self, l:@Local, e:@mut GatherLoanCtxt) {
9696
gather_loans_in_local(self, l, e);
9797
}
98+
99+
// #7740: Do not visit items here, not even fn items nor methods
100+
// of impl items; the outer loop in borrowck/mod will visit them
101+
// for us in turn. Thus override visit_item's walk with a no-op.
102+
fn visit_item(&mut self, _:@ast::item, _:@mut GatherLoanCtxt) { }
98103
}
99104

100105
pub fn gather_loans(bccx: @BorrowckCtxt,
@@ -135,10 +140,8 @@ fn gather_loans_in_fn(v: &mut GatherLoanVisitor,
135140
id: ast::NodeId,
136141
this: @mut GatherLoanCtxt) {
137142
match fk {
138-
// Do not visit items here, the outer loop in borrowck/mod
139-
// will visit them for us in turn.
140143
&visit::fk_item_fn(*) | &visit::fk_method(*) => {
141-
return;
144+
fail!("cannot occur, due to visit_item override");
142145
}
143146

144147
// Visit closures as part of the containing item.

0 commit comments

Comments
 (0)