about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/region.rs9
-rw-r--r--src/test/run-pass/regions-lifetime-static-items-enclosing-scopes.rs (renamed from src/test/compile-fail/issue-511.rs)13
2 files changed, 18 insertions, 4 deletions
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs
index 4ebbd097f29..9c11b89bb7e 100644
--- a/src/librustc/middle/region.rs
+++ b/src/librustc/middle/region.rs
@@ -172,7 +172,14 @@ impl RegionMaps {
         }
 
         // else, locate the innermost terminating scope
-        let mut id = self.encl_scope(expr_id);
+        // if there's one. Static items, for instance, won't
+        // have an enclusing scope, hence no scope will be
+        // returned.
+        let mut id = match self.opt_encl_scope(expr_id) {
+            Some(i) => i,
+            None => { return None; }
+        };
+
         let terminating_scopes = self.terminating_scopes.borrow();
         while !terminating_scopes.get().contains(&id) {
             match self.opt_encl_scope(id) {
diff --git a/src/test/compile-fail/issue-511.rs b/src/test/run-pass/regions-lifetime-static-items-enclosing-scopes.rs
index ed2eede76c6..e20717553c4 100644
--- a/src/test/compile-fail/issue-511.rs
+++ b/src/test/run-pass/regions-lifetime-static-items-enclosing-scopes.rs
@@ -1,4 +1,4 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -8,6 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// This test verifies that temporary lifetime is correctly computed
+// for static objects in enclosing scopes.
+
 extern mod extra;
 use std::cmp::Eq;
 
@@ -15,7 +18,11 @@ fn f<T:Eq>(o: &mut Option<T>) {
     assert!(*o == None);
 }
 
-fn main() {
+pub fn main() {
+    mod t {
+        enum E {V=1, A=0}
+        static C: E = V;
+    }
+
     f::<int>(&mut None);
-    //~^ ERROR cannot borrow
 }