Skip to content

Commit cb0253b

Browse files
committed
---
yaml --- r: 148351 b: refs/heads/try2 c: 56f4d18 h: refs/heads/master i: 148349: 8949534 148347: db96c23 148343: 0f2ea97 148335: 32605e8 148319: c42340e 148287: d4974aa 148223: 57cdbda v: v3
1 parent 7d11cdf commit cb0253b

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 0c916c58e8c978554415933773f0a105dee754d3
8+
refs/heads/try2: 56f4d1831a65b9739d38c2754f65b641b4e0d6b8
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/borrowck/gather_loans/lifetime.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ impl<'a> GuaranteeLifetimeContext<'a> {
6767

6868
fn check(&self, cmt: mc::cmt, discr_scope: Option<ast::NodeId>) -> R {
6969
//! Main routine. Walks down `cmt` until we find the "guarantor".
70+
debug!("guarantee_lifetime.check(cmt={}, loan_region={})",
71+
cmt.repr(self.bccx.tcx),
72+
self.loan_region.repr(self.bccx.tcx));
7073

7174
match cmt.cat {
7275
mc::cat_rvalue(..) |

branches/try2/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ fn visit_arm(rcx: &mut Rcx, arm: &ast::Arm) {
213213
fn visit_local(rcx: &mut Rcx, l: &ast::Local) {
214214
// see above
215215
constrain_bindings_in_pat(l.pat, rcx);
216+
guarantor::for_local(rcx, l);
216217
visit::walk_local(rcx, l, ());
217218
}
218219

@@ -828,6 +829,30 @@ pub mod guarantor {
828829
}
829830
}
830831

832+
pub fn for_local(rcx: &mut Rcx, local: &ast::Local) {
833+
/*!
834+
* Link the lifetimes of any ref bindings in a let
835+
* pattern to the lifetimes in the initializer.
836+
*
837+
* For example, given something like this:
838+
*
839+
* let &Foo(ref x) = ...;
840+
*
841+
* this would ensure that the lifetime 'a of the
842+
* region pointer being matched must be >= the lifetime
843+
* of the ref binding.
844+
*/
845+
846+
debug!("regionck::for_match()");
847+
let init_expr = match local.init {
848+
None => { return; }
849+
Some(e) => e
850+
};
851+
let init_guarantor = guarantor(rcx, init_expr);
852+
debug!("init_guarantor={}", init_guarantor.repr(rcx.tcx()));
853+
link_ref_bindings_in_pat(rcx, local.pat, init_guarantor);
854+
}
855+
831856
pub fn for_autoref(rcx: &mut Rcx,
832857
expr: &ast::Expr,
833858
autoderefs: uint,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test lifetimes are linked properly when we take reference
12+
// to interior.
13+
14+
struct Foo(int);
15+
16+
fn foo() -> &int {
17+
let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough
18+
x
19+
}
20+
21+
pub fn main() {
22+
}

branches/try2/src/test/debug-info/destructured-local.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ fn main() {
196196
let Unit(ii) = Unit(51);
197197

198198
// univariant enum with ref binding
199-
let Unit(ref jj) = Unit(52);
199+
let &Unit(ref jj) = &Unit(52);
200200

201201
// tuple struct
202-
let TupleStruct(kk, ll) = TupleStruct(53.0, 54);
202+
let &TupleStruct(kk, ll) = &TupleStruct(53.0, 54);
203203

204204
// tuple struct with ref binding
205-
let TupleStruct(mm, ref nn) = TupleStruct(55.0, 56);
205+
let &TupleStruct(mm, ref nn) = &TupleStruct(55.0, 56);
206206

207207
zzz();
208208
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test lifetimes are linked properly when we take reference
12+
// to interior.
13+
14+
struct Foo(int);
15+
pub fn main() {
16+
// Here the lifetime of the `&` should be at least the
17+
// block, since a ref binding is created to the interior.
18+
let &Foo(ref _x) = &Foo(3);
19+
}

0 commit comments

Comments
 (0)