Skip to content

Dont recur on items during gather loans of block #8993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ impl visit::Visitor<@mut GatherLoanCtxt> for GatherLoanVisitor {
fn visit_local(&mut self, l:@Local, e:@mut GatherLoanCtxt) {
gather_loans_in_local(self, l, e);
}

// #7740: Do not visit items here, not even fn items nor methods
// of impl items; the outer loop in borrowck/mod will visit them
// for us in turn. Thus override visit_item's walk with a no-op.
fn visit_item(&mut self, _:@ast::item, _:@mut GatherLoanCtxt) { }
}

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

// Visit closures as part of the containing item.
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-pass/borrowck-static-item-in-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Regression test for issue #7740

fn main() {
static A: &'static char = &'A';
}