Skip to content

Commit

Permalink
Fixes temporary lifetime computation for static items
Browse files Browse the repository at this point in the history
closes: #11854
  • Loading branch information
flaper87 committed Jan 29, 2014
1 parent 279fe0f commit cb5d723
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -8,14 +8,21 @@
// 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;

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
}

5 comments on commit cb5d723

@bors
Copy link
Contributor

@bors bors commented on cb5d723 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at flaper87@cb5d723

@bors
Copy link
Contributor

@bors bors commented on cb5d723 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging FlaPer87/rust/issue-11681-static-lifetime = cb5d723 into auto

@bors
Copy link
Contributor

@bors bors commented on cb5d723 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlaPer87/rust/issue-11681-static-lifetime = cb5d723 merged ok, testing candidate = f84b729

@bors
Copy link
Contributor

@bors bors commented on cb5d723 Jan 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on cb5d723 Jan 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = f84b729

Please sign in to comment.