annotated.
CFG_RUSTC_FLAGS += -Z trace
endif
ifndef DEBUG_BORROWS
+ RUSTFLAGS_STAGE0 += -Z no-debug-borrows
RUSTFLAGS_STAGE1 += -Z no-debug-borrows
RUSTFLAGS_STAGE2 += -Z no-debug-borrows
endif
/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
#[inline]
- pub unsafe fn unsafe_access_cond<'x, 'c, U>(&self,
- blk: &fn(x: &'x mut T,
- c: &'c Condvar) -> U)
- -> U {
+ pub unsafe fn unsafe_access_cond<U>(&self,
+ blk: &fn(x: &mut T,
+ c: &Condvar) -> U)
+ -> U {
let state = self.x.get();
do (&(*state).lock).lock_cond |cond| {
check_poison(true, (*state).failed);
/// As unsafe_access_cond but safe and Freeze.
#[inline]
- pub fn access_cond<'x, 'c, U>(&self,
- blk: &fn(x: &'x mut T,
- c: &'c Condvar) -> U)
- -> U {
+ pub fn access_cond<U>(&self,
+ blk: &fn(x: &mut T,
+ c: &Condvar) -> U)
+ -> U {
unsafe { self.unsafe_access_cond(blk) }
}
}
/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline]
- pub fn write_cond<'x, 'c, U>(&self,
- blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
- -> U {
+ pub fn write_cond<U>(&self,
+ blk: &fn(x: &mut T, c: &Condvar) -> U)
+ -> U {
unsafe {
let state = self.x.get();
do (*borrow_rwlock(state)).write_cond |cond| {
}
/// Access the pre-downgrade RWArc in write mode with a condvar.
- pub fn write_cond<'x, 'c, U>(&mut self,
- blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
- -> U {
+ pub fn write_cond<U>(&mut self,
+ blk: &fn(x: &mut T, c: &Condvar) -> U)
+ -> U {
match *self {
RWWriteMode {
data: &ref mut data,
freevars::annotate_freevars(def_map, crate));
let region_map = time(time_passes, "region resolution", (), |_|
- middle::region::resolve_crate(sess, def_map, crate));
-
- let rp_set = time(time_passes, "region parameterization inference", (), |_|
- middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
+ middle::region::resolve_crate(sess, crate));
let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
region_map, lang_items);
return ty::mk_param(st.tcx, parse_uint(st), did);
}
's' => {
- let did = parse_def(st, TypeParameter, conv);
+ let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
return ty::mk_self(st.tcx, did);
}
- '@' => return ty::mk_box(st.tcx, parse_mt(st, conv)),
- '~' => return ty::mk_uniq(st.tcx, parse_mt(st, conv)),
- '*' => return ty::mk_ptr(st.tcx, parse_mt(st, conv)),
+ '@' => return ty::mk_box(st.tcx, parse_mt(st, |x,y| conv(x,y))),
+ '~' => return ty::mk_uniq(st.tcx, parse_mt(st, |x,y| conv(x,y))),
+ '*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'&' => {
- let r = parse_region(st);
- let mt = parse_mt(st, conv);
+ let r = parse_region(st, |x,y| conv(x,y));
+ let mt = parse_mt(st, |x,y| conv(x,y));
return ty::mk_rptr(st.tcx, r, mt);
}
- 'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)),
+ 'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'V' => {
let mt = parse_mt(st, |x,y| conv(x,y));
let v = parse_vstore(st, |x,y| conv(x,y));
return ty::mk_tup(st.tcx, params);
}
'f' => {
- return ty::mk_closure(st.tcx, parse_closure_ty(st, conv));
+ return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
}
'F' => {
- return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, conv));
+ return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
}
'Y' => return ty::mk_type(st.tcx),
'C' => {
pos: pos,
.. *st
};
- let tt = parse_ty(&mut ps, conv);
+ let tt = parse_ty(&mut ps, |x,y| conv(x,y));
st.tcx.rcache.insert(key, tt);
return tt;
}
fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {
let m = parse_mutability(st);
- ty::mt { ty: parse_ty(st, conv), mutbl: m }
+ ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }
}
fn parse_def(st: &mut PState, source: DefIdSource,
use middle::trans::foreign;
use middle::ty;
use util::ppaux;
+use util::ppaux::Repr;
use middle::trans::type_::Type;
// NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
- debug!("type_of {:?}: {:?}", t, ty::get(t));
-
// Check the cache.
match cx.lltypes.find(&t) {
- Some(&t) => return t,
+ Some(&llty) => {
+ return llty;
+ }
None => ()
}
+ debug!("type_of {} {:?}", t.repr(cx.tcx), t);
+
// Replace any typedef'd types with their equivalent non-typedef
// type. This ensures that all LLVM nominal types that contain
// Rust types are defined as the same LLVM types. If we don't do
if t != t_norm {
let llty = type_of(cx, t_norm);
+ debug!("--> normalized {} {:?} to {} {:?} llty={}",
+ t.repr(cx.tcx),
+ t,
+ t_norm.repr(cx.tcx),
+ t_norm,
+ cx.tn.type_to_str(llty));
cx.lltypes.insert(t, llty);
return llty;
}
ty::ty_err(*) => cx.tcx.sess.bug("type_of with ty_err")
};
+ debug!("--> mapped t={} {:?} to llty={}",
+ t.repr(cx.tcx),
+ t,
+ cx.tn.type_to_str(llty));
cx.lltypes.insert(t, llty);
// If this was an enum or struct, fill in the type now.
}
}
-fn main() {
+fn foo<'a>() {
let _ = S::new::<int,f64>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
- let _ = S::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this impl has no lifetime parameter
+ let _ = S::<'a,int>::new::<f64>(1, 1.0); //~ ERROR expected 0 lifetime parameter(s)
let _: S2 = Trait::new::<int,f64>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
- let _: S2 = Trait::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this trait has no lifetime parameter
+ let _: S2 = Trait::<'a,int>::new::<f64>(1, 1.0); //~ ERROR expected 0 lifetime parameter(s)
}
+fn main() {}
use std::local_data;
local_data_key!(key: @&int)
-//~^ ERROR only 'static is allowed
+//~^ ERROR missing lifetime specifier
fn main() {}
fn id<T>(t: T) -> T { t }
-fn f<'r, T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
+fn f<'r, T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR cannot infer an appropriate lifetime
fn main() {
let v = &5;
// except according to those terms.
fn f() { }
-struct S(&fn()); //~ ERROR Illegal anonymous lifetime
-pub static C: S = S(f); //~ ERROR Illegal anonymous lifetime
+struct S(&fn()); //~ ERROR missing lifetime specifier
+pub static C: S = S(f);
fn g() { }
-type T = &fn(); //~ ERROR Illegal anonymous lifetime
-pub static D: T = g; //~ ERROR Illegal anonymous lifetime
+type T = &fn(); //~ ERROR missing lifetime specifier
+pub static D: T = g;
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-#[feature(managed_boxes)];
+trait Repeat<A> { fn get(&self) -> A; }
-trait repeat<A> { fn get(&self) -> A; }
-
-impl<A:Clone> repeat<A> for @A {
- fn get(&self) -> A { **self }
+impl<A:Clone> Repeat<A> for A {
+ fn get(&self) -> A { self.clone() }
}
-fn repeater<A:Clone>(v: @A) -> @repeat<A> {
- // Note: owned kind is not necessary as A appears in the trait type
- @v as @repeat<A> // No
+fn repeater<A:Clone>(v: A) -> ~Repeat:<A> {
+ ~v as ~Repeat:<A> // No
}
fn main() {
// Error results because the type of is inferred to be
- // @repeat<&'blk int> where blk is the lifetime of the block below.
+ // ~Repeat<&'blk int> where blk is the lifetime of the block below.
- let y = { //~ ERROR lifetime of variable does not enclose its declaration
- let x: &'blk int = &3;
- repeater(@x)
+ let y = {
+ let tmp0 = 3;
+ let tmp1 = &tmp0; //~ ERROR borrowed value does not live long enough
+ repeater(tmp1)
};
assert!(3 == *(y.get()));
- //~^ ERROR dereference of reference outside its lifetime
- //~^^ ERROR automatically borrowed pointer is not valid at the time of borrow
- //~^^^ ERROR lifetime of return value does not outlive the function call
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// Check that taking the address of an argument yields a lifetime
+// bounded by the current function call.
+
fn foo(a: int) {
let _p: &'static int = &a; //~ ERROR borrowed value does not live long enough
}
fn bar(a: int) {
- let _q: &'blk int = &a;
+ let _q: &int = &a;
+}
+
+fn zed<'a>(a: int) -> &'a int {
+ &a //~ ERROR borrowed value does not live long enough
}
fn main() {
impl dog {
pub fn chase_cat(&mut self) {
- let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
+ let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime
*p += 1u;
}
pub fn chase_cat_2(&mut self) {
- let p: &'blk mut uint = &mut self.cats_chased;
+ let p: &mut uint = &mut self.cats_chased;
*p += 1u;
}
}
impl dog {
pub fn chase_cat(&mut self) {
let _f = || {
- let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
+ let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime
*p = 3u;
};
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn foo(cond: bool) {
- let x = 5;
- let mut y: &'blk int = &x;
-
- let mut z: &'blk int;
- if cond {
- z = &x; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
- } else {
- let w: &'blk int = &x;
- z = w;
- }
-}
-
-fn main() {
-}
of::<&fn<'b>(&'b T)>());
subtype::<&fn<'b>(&'b T)>(
- of::<&fn<'x>(&'x T)>());
+ of::<&fn(&'x T)>());
- subtype::<&fn<'x>(&'x T)>(
+ subtype::<&fn(&'x T)>(
of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types
subtype::<&fn<'a,'b>(&'a T, &'b T)>(
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
subtype::<&fn<'a,'b>(&'a T, &'b T)>(
- of::<&fn<'x,'y>(&'x T, &'y T)>());
+ of::<&fn(&'x T, &'y T)>());
- subtype::<&fn<'x,'y>(&'x T, &'y T)>(
+ subtype::<&fn(&'x T, &'y T)>(
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
}
fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
// Do not infer an ordering from the return value.
let z: &'b uint = &*x;
- //~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
+ //~^ ERROR cannot infer an appropriate lifetime
fail!();
}
struct Paramd<'self> { x: &'self uint }
-fn call1<'a>(x: &'a uint) {
- let y: uint = 3;
- let z: &'a &'blk uint = &(&y);
- //~^ ERROR pointer has a longer lifetime than the data it references
-}
-
fn call2<'a, 'b>(a: &'a uint, b: &'b uint) {
let z: Option<&'b &'a uint> = None;
//~^ ERROR pointer has a longer lifetime than the data it references
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test various ways to construct a pointer with a longer lifetime
+// than the thing it points at and ensure that they result in
+// errors. See also regions-free-region-ordering-callee.rs
+
+fn call1<'a>(x: &'a uint) {
+ // Test that creating a pointer like
+ // &'a &'z uint requires that 'a <= 'z:
+ let y: uint = 3;
+ let z: &'a & uint = &(&y);
+ //~^ ERROR borrowed value does not live long enough
+ //~^^ ERROR borrowed value does not live long enough
+}
+
+fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-static c_x: &'blk int = &22; //~ ERROR Illegal lifetime 'blk: only 'static is allowed here
-static c_y: &int = &22; //~ ERROR Illegal anonymous lifetime: only 'static is allowed here
+static c_y: &int = &22; //~ ERROR missing lifetime specifier
static c_z: &'static int = &22;
fn main() {
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that anonymous lifetimes are not permitted in enum declarations
+
+enum Foo {
+ Bar(&int) //~ ERROR missing lifetime specifier
+}
+
+fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// Test that lifetimes must be declared for use on enums.
+// See also regions-undeclared.rs
+
enum yes0<'lt> {
- // This will eventually be legal (and in fact the only way):
- X3(&'lt uint) //~ ERROR Illegal lifetime 'lt: only 'self is allowed
+ X3(&'lt uint)
}
enum yes1<'self> {
X4(&'self uint)
}
-enum yes2 {
- X5(&'foo uint) //~ ERROR Illegal lifetime 'foo: only 'self is allowed
+enum no0 {
+ X5(&'foo uint) //~ ERROR use of undeclared lifetime name `'foo`
+}
+
+enum no1 {
+ X6(&'self uint) //~ ERROR use of undeclared lifetime name `'self`
}
fn main() {}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that anonymous lifetimes are not permitted in struct declarations
+
+struct Foo {
+ x: &int //~ ERROR missing lifetime specifier
+}
+
+fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct yes0<'self> {
- x: &uint, //~ ERROR Illegal anonymous lifetime: anonymous lifetimes are not permitted here
-}
-
struct yes1<'self> {
x: &'self uint,
}
-struct yes2<'self> {
- x: &'foo uint, //~ ERROR Illegal lifetime 'foo: only 'self is allowed
+struct yes2<'a> {
+ x: &'a uint,
}
+struct StructDecl {
+ a: &'a int, //~ ERROR use of undeclared lifetime name `'a`
+ b: &'self int, //~ ERROR use of undeclared lifetime name `'self`
+}
+
+
fn main() {}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct item_ty_yes0<'self> {
- x: &'self uint
-}
-
-struct item_ty_yes1<'self> {
- x: &'self uint
-}
-
-struct item_ty_yes2 {
- x: &'a uint //~ ERROR only 'self is allowed
-}
-
-fn main() {}
// contains region pointers
struct foo(~fn(x: &int));
-fn take_foo(x: foo<'static>) {} //~ ERROR no region bound is allowed on `foo`
+fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters
fn main() {
}
// some point regions-ret-borrowed reported an error but this file did
// not, due to special hardcoding around the anonymous region.
-fn with<'a, R>(f: &fn(x: &'a int) -> R) -> R {
+fn with<R>(f: &fn<'a>(x: &'a int) -> R) -> R {
f(&3)
}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+static c_x: &'blk int = &22; //~ ERROR use of undeclared lifetime name `'blk`
+
+enum EnumDecl {
+ Foo(&'a int), //~ ERROR use of undeclared lifetime name `'a`
+ Bar(&'self int), //~ ERROR use of undeclared lifetime name `'self`
+}
+
+fn fnDecl(x: &'a int, //~ ERROR use of undeclared lifetime name `'a`
+ y: &'self int) //~ ERROR use of undeclared lifetime name `'self`
+{}
+
+fn main() {
+}
}
impl foo for int {
fn bar(&self) -> int {
- //~^ ERROR method `bar` has 0 parameters but the trait has 1
+ //~^ ERROR method `bar` has 0 parameter(s) but the trait has 1
*self
}
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test lifetimes are linked properly when we create dependent region pointers.
-// Issue #3148.
-
-struct A {
- value: B
-}
-
-struct B {
- v1: int,
- v2: [int, ..3],
- v3: ~[int],
- v4: C,
- v5: ~C,
- v6: Option<C>
-}
-
-struct C {
- f: int
-}
-
-fn get_v1<'v>(a: &'v A) -> &'v int {
- // Region inferencer must deduce that &v < L2 < L1
- let foo = &a.value; // L1
- &foo.v1 // L2
-}
-
-fn get_v2<'v>(a: &'v A, i: uint) -> &'v int {
- let foo = &a.value;
- &foo.v2[i]
-}
-
-fn get_v3<'v>(a: &'v A, i: uint) -> &'v int {
- let foo = &a.value;
- &foo.v3[i]
-}
-
-fn get_v4<'v>(a: &'v A, _i: uint) -> &'v int {
- let foo = &a.value;
- &foo.v4.f
-}
-
-fn get_v5<'v>(a: &'v A, _i: uint) -> &'v int {
- let foo = &a.value;
- &foo.v5.f
-}
-
-fn get_v6_a<'v>(a: &'v A, _i: uint) -> &'v int {
- match a.value.v6 {
- Some(ref v) => &v.f,
- None => fail!()
- }
-}
-
-fn get_v6_b<'v>(a: &'v A, _i: uint) -> &'v int {
- match *a {
- A { value: B { v6: Some(ref v), _ } } => &v.f,
- _ => fail!()
- }
-}
-
-fn get_v6_c<'v>(a: &'v A, _i: uint) -> &'v int {
- match a {
- &A { value: B { v6: Some(ref v), _ } } => &v.f,
- _ => fail!()
- }
-}
-
-fn get_v5_ref<'v>(a: &'v A, _i: uint) -> &'v int {
- match &a.value {
- &B {v5: ~C {f: ref v}, _} => v
- }
-}
-
-pub fn main() {
- let a = A {value: B {v1: 22,
- v2: [23, 24, 25],
- v3: ~[26, 27, 28],
- v4: C { f: 29 },
- v5: ~C { f: 30 },
- v6: Some(C { f: 31 })}};
-
- let p = get_v1(&a);
- assert_eq!(*p, a.value.v1);
-
- let p = get_v2(&a, 1);
- assert_eq!(*p, a.value.v2[1]);
-
- let p = get_v3(&a, 1);
- assert_eq!(*p, a.value.v3[1]);
-
- let p = get_v4(&a, 1);
- assert_eq!(*p, a.value.v4.f);
-
- let p = get_v5(&a, 1);
- assert_eq!(*p, a.value.v5.f);
-
- let p = get_v6_a(&a, 1);
- assert_eq!(*p, a.value.v6.unwrap().f);
-
- let p = get_v6_b(&a, 1);
- assert_eq!(*p, a.value.v6.unwrap().f);
-
- let p = get_v6_c(&a, 1);
- assert_eq!(*p, a.value.v6.unwrap().f);
-
- let p = get_v5_ref(&a, 1);
- assert_eq!(*p, a.value.v5.f);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test lifetimes are linked properly when we autoslice a vector.
-// Issue #3148.
-
-fn subslice<'r>(v: &'r fn()) -> &'r fn() { v }
-
-fn both<'r>(v: &'r fn()) -> &'r fn() {
- subslice(subslice(v))
-}
-
-pub fn main() {
- both(main);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test lifetimes are linked properly when we autoslice a vector.
-// Issue #3148.
-
-fn subslice1<'r>(v: &'r [uint]) -> &'r [uint] { v }
-
-fn both<'r>(v: &'r [uint]) -> &'r [uint] {
- subslice1(subslice1(v))
-}
-
-pub fn main() {
- let v = ~[1,2,3];
- both(v);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn get<'r, T>(opt: &'r Option<T>) -> &'r T {
- match *opt {
- Some(ref v) => v,
- None => fail!("none")
- }
-}
-
-pub fn main() {
- let mut x = Some(23);
-
- {
- let y = get(&x);
- assert_eq!(*y, 23);
- }
-
- x = Some(24);
-
- {
- let y = get(&x);
- assert_eq!(*y, 24);
- }
-}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test lifetimes are linked properly when we create dependent region pointers.
+// Issue #3148.
+
+struct A {
+ value: B
+}
+
+struct B {
+ v1: int,
+ v2: [int, ..3],
+ v3: ~[int],
+ v4: C,
+ v5: ~C,
+ v6: Option<C>
+}
+
+struct C {
+ f: int
+}
+
+fn get_v1<'v>(a: &'v A) -> &'v int {
+ // Region inferencer must deduce that &v < L2 < L1
+ let foo = &a.value; // L1
+ &foo.v1 // L2
+}
+
+fn get_v2<'v>(a: &'v A, i: uint) -> &'v int {
+ let foo = &a.value;
+ &foo.v2[i]
+}
+
+fn get_v3<'v>(a: &'v A, i: uint) -> &'v int {
+ let foo = &a.value;
+ &foo.v3[i]
+}
+
+fn get_v4<'v>(a: &'v A, _i: uint) -> &'v int {
+ let foo = &a.value;
+ &foo.v4.f
+}
+
+fn get_v5<'v>(a: &'v A, _i: uint) -> &'v int {
+ let foo = &a.value;
+ &foo.v5.f
+}
+
+fn get_v6_a<'v>(a: &'v A, _i: uint) -> &'v int {
+ match a.value.v6 {
+ Some(ref v) => &v.f,
+ None => fail!()
+ }
+}
+
+fn get_v6_b<'v>(a: &'v A, _i: uint) -> &'v int {
+ match *a {
+ A { value: B { v6: Some(ref v), _ } } => &v.f,
+ _ => fail!()
+ }
+}
+
+fn get_v6_c<'v>(a: &'v A, _i: uint) -> &'v int {
+ match a {
+ &A { value: B { v6: Some(ref v), _ } } => &v.f,
+ _ => fail!()
+ }
+}
+
+fn get_v5_ref<'v>(a: &'v A, _i: uint) -> &'v int {
+ match &a.value {
+ &B {v5: ~C {f: ref v}, _} => v
+ }
+}
+
+pub fn main() {
+ let a = A {value: B {v1: 22,
+ v2: [23, 24, 25],
+ v3: ~[26, 27, 28],
+ v4: C { f: 29 },
+ v5: ~C { f: 30 },
+ v6: Some(C { f: 31 })}};
+
+ let p = get_v1(&a);
+ assert_eq!(*p, a.value.v1);
+
+ let p = get_v2(&a, 1);
+ assert_eq!(*p, a.value.v2[1]);
+
+ let p = get_v3(&a, 1);
+ assert_eq!(*p, a.value.v3[1]);
+
+ let p = get_v4(&a, 1);
+ assert_eq!(*p, a.value.v4.f);
+
+ let p = get_v5(&a, 1);
+ assert_eq!(*p, a.value.v5.f);
+
+ let p = get_v6_a(&a, 1);
+ assert_eq!(*p, a.value.v6.unwrap().f);
+
+ let p = get_v6_b(&a, 1);
+ assert_eq!(*p, a.value.v6.unwrap().f);
+
+ let p = get_v6_c(&a, 1);
+ assert_eq!(*p, a.value.v6.unwrap().f);
+
+ let p = get_v5_ref(&a, 1);
+ assert_eq!(*p, a.value.v5.f);
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test lifetimes are linked properly when we autoslice a vector.
+// Issue #3148.
+
+fn subslice<'r>(v: &'r fn()) -> &'r fn() { v }
+
+fn both<'r>(v: &'r fn()) -> &'r fn() {
+ subslice(subslice(v))
+}
+
+pub fn main() {
+ both(main);
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test lifetimes are linked properly when we autoslice a vector.
+// Issue #3148.
+
+fn subslice1<'r>(v: &'r [uint]) -> &'r [uint] { v }
+
+fn both<'r>(v: &'r [uint]) -> &'r [uint] {
+ subslice1(subslice1(v))
+}
+
+pub fn main() {
+ let v = ~[1,2,3];
+ both(v);
+}
#[fixed_stack_segment] #[inline(never)]
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe {
- cast::transmute(libc::malloc(mem::size_of::<Bcx<'blk>>()
+ cast::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
as libc::size_t))
}
}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn get<'r, T>(opt: &'r Option<T>) -> &'r T {
+ match *opt {
+ Some(ref v) => v,
+ None => fail!("none")
+ }
+}
+
+pub fn main() {
+ let mut x = Some(23);
+
+ {
+ let y = get(&x);
+ assert_eq!(*y, 23);
+ }
+
+ x = Some(24);
+
+ {
+ let y = get(&x);
+ assert_eq!(*y, 24);
+ }
+}