diff options
Diffstat (limited to 'src/test/compile-fail')
4 files changed, 111 insertions, 0 deletions
diff --git a/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs b/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs new file mode 100644 index 00000000000..4695360a688 --- /dev/null +++ b/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs @@ -0,0 +1,33 @@ +// 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. +// +// 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. + +// Verify that managed pointers scope is treated like ownoed pointers. +// regresion test for #11586 + +#![feature(managed_boxes)] + +fn foo<'a>(x: &'a @int) -> &'a int { + match x { + &ref y => { + &**y // Do not expect an error here + } + } +} + +fn bar() { + let a = 3; + let mut y = &a; + if true { + let x = @3; + y = &*x; //~ ERROR `*x` does not live long enough + } +} + +fn main() {} diff --git a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs new file mode 100644 index 00000000000..1508349344c --- /dev/null +++ b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs @@ -0,0 +1,28 @@ +// 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. + +#![feature(managed_boxes)] + +struct point { + x: int, + y: int, +} + +fn x_coord<'r>(p: &'r point) -> &'r int { + return &p.x; +} + +fn foo(p: @point) -> &int { + let xc = x_coord(p); //~ ERROR `*p` does not live long enough + assert_eq!(*xc, 3); + return xc; +} + +fn main() {} diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs new file mode 100644 index 00000000000..3cd70ce6c8a --- /dev/null +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -0,0 +1,30 @@ +// 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. + +#![feature(managed_boxes)] + +fn borrow<'r, T>(x: &'r T) -> &'r T {x} + +fn foo(cond: || -> bool, make_box: || -> @int) { + let mut y: ∫ + loop { + let x = make_box(); + + // Here we complain because the resulting region + // of this borrow is the fn body as a whole. + y = borrow(x); //~ ERROR `*x` does not live long enough + + assert_eq!(*x, *y); + if cond() { break; } + } + assert!(*y != 0); +} + +fn main() {} diff --git a/src/test/compile-fail/struct-field-assignability.rs b/src/test/compile-fail/struct-field-assignability.rs new file mode 100644 index 00000000000..68a17266106 --- /dev/null +++ b/src/test/compile-fail/struct-field-assignability.rs @@ -0,0 +1,20 @@ +// 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. +// +// 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. + +#![feature(managed_boxes)] + +struct Foo<'a> { + x: &'a int +} + +pub fn main() { + let f = Foo { x: @3 }; //~ ERROR borrowed value does not live long enough + assert_eq!(*f.x, 3); +}  | 
