Fixes temporary lifetime computation for static items

closes: #11854
This commit is contained in:
Flavio Percoco 2014-01-27 23:09:57 +01:00
parent 279fe0fa76
commit cb5d7236f1
2 changed files with 18 additions and 4 deletions

View File

@ -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) {

View File

@ -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
}