about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-05 04:55:44 -0700
committerbors <bors@rust-lang.org>2013-09-05 04:55:44 -0700
commit510c4d8dcf7fd265efb8cced2a03fd06063b0f6b (patch)
tree2c4eb40cef6d62e491afce379d40e54e435eb8d3
parent6f176a17f630a82acd9f4163efc0384d02717d77 (diff)
parentc7352e6403331b0464d1b1e1ccfc9a0f7b67e50b (diff)
downloadrust-510c4d8dcf7fd265efb8cced2a03fd06063b0f6b.tar.gz
rust-510c4d8dcf7fd265efb8cced2a03fd06063b0f6b.zip
auto merge of #8993 : pnkfelix/rust/fsk-fix-7740-dont-recur-on-items-during-gather-loans-of-block, r=nikomatsakis
Fix #7740

r? anyone, @nikomatsakis especially.

-rw-r--r--src/librustc/middle/borrowck/gather_loans/mod.rs9
-rw-r--r--src/test/run-pass/borrowck-static-item-in-fn.rs15
2 files changed, 21 insertions, 3 deletions
diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs
index be033de4e41..352a229633b 100644
--- a/src/librustc/middle/borrowck/gather_loans/mod.rs
+++ b/src/librustc/middle/borrowck/gather_loans/mod.rs
@@ -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,
@@ -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.
diff --git a/src/test/run-pass/borrowck-static-item-in-fn.rs b/src/test/run-pass/borrowck-static-item-in-fn.rs
new file mode 100644
index 00000000000..a3a7a1b8969
--- /dev/null
+++ b/src/test/run-pass/borrowck-static-item-in-fn.rs
@@ -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';
+}