Skip to content

Commit cb5d723

Browse files
committed
Fixes temporary lifetime computation for static items
closes: #11854
1 parent 279fe0f commit cb5d723

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: src/librustc/middle/region.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ impl RegionMaps {
172172
}
173173

174174
// else, locate the innermost terminating scope
175-
let mut id = self.encl_scope(expr_id);
175+
// if there's one. Static items, for instance, won't
176+
// have an enclusing scope, hence no scope will be
177+
// returned.
178+
let mut id = match self.opt_encl_scope(expr_id) {
179+
Some(i) => i,
180+
None => { return None; }
181+
};
182+
176183
let terminating_scopes = self.terminating_scopes.borrow();
177184
while !terminating_scopes.get().contains(&id) {
178185
match self.opt_encl_scope(id) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,14 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// This test verifies that temporary lifetime is correctly computed
12+
// for static objects in enclosing scopes.
13+
1114
extern mod extra;
1215
use std::cmp::Eq;
1316

1417
fn f<T:Eq>(o: &mut Option<T>) {
1518
assert!(*o == None);
1619
}
1720

18-
fn main() {
21+
pub fn main() {
22+
mod t {
23+
enum E {V=1, A=0}
24+
static C: E = V;
25+
}
26+
1927
f::<int>(&mut None);
20-
//~^ ERROR cannot borrow
2128
}

0 commit comments

Comments
 (0)