diff options
| author | Mikhail Modin <mikhailm1@gmail.com> | 2016-10-26 19:10:39 +0300 |
|---|---|---|
| committer | Mikhail Modin <mikhailm1@gmail.com> | 2016-11-01 19:39:28 +0300 |
| commit | a0e7e357a796f93527d0a0e850fa71c48594b91d (patch) | |
| tree | bf3a00bf61d177d572b5113ae4426e87270ba8bb /src/test/compile-fail | |
| parent | 69ec350f5968defc7024d72ce791b0653c966cee (diff) | |
| download | rust-a0e7e357a796f93527d0a0e850fa71c48594b91d.tar.gz rust-a0e7e357a796f93527d0a0e850fa71c48594b91d.zip | |
Improve "Doesn't live long enough" error
case with different lifetime with spans
Diffstat (limited to 'src/test/compile-fail')
13 files changed, 0 insertions, 394 deletions
diff --git a/src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs b/src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs deleted file mode 100644 index 726d4bcdf1d..00000000000 --- a/src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs +++ /dev/null @@ -1,20 +0,0 @@ -// 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 main() { - let msg; - match Some("Hello".to_string()) { - Some(ref m) => { //~ ERROR borrowed value does not live long enough - msg = m; - }, - None => { panic!() } - } - println!("{}", *msg); -} diff --git a/src/test/compile-fail/destructor-restrictions.rs b/src/test/compile-fail/destructor-restrictions.rs deleted file mode 100644 index 22f615cafd7..00000000000 --- a/src/test/compile-fail/destructor-restrictions.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -// Tests the new destructor semantics. - -use std::cell::RefCell; - -fn main() { - let b = { - let a = Box::new(RefCell::new(4)); - *a.borrow() + 1 //~ ERROR `*a` does not live long enough - }; - println!("{}", b); -} diff --git a/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs b/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs deleted file mode 100644 index 8e968d90a2f..00000000000 --- a/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2013 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. - -use std::cell::RefCell; - -fn main() { - let m = RefCell::new(0); - let p; - { - let b = m.borrow(); - p = &*b; //~ ERROR `b` does not live long enough - } -} diff --git a/src/test/compile-fail/range-2.rs b/src/test/compile-fail/range-2.rs deleted file mode 100644 index 94967693ecf..00000000000 --- a/src/test/compile-fail/range-2.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 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 range syntax - borrow errors. - -pub fn main() { - let r = { - let a = 42; - let b = 42; - &a..&b - //~^ ERROR `a` does not live long enough - //~^^ ERROR `b` does not live long enough - }; -} diff --git a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs b/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs deleted file mode 100644 index 8ec6036762f..00000000000 --- a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -use std::ops::FnMut; - -fn main() { - let mut f; - { - let c = 1; - let c_ref = &c; //~ ERROR `c` does not live long enough - f = move |a: isize, b: isize| { a + b + *c_ref }; - } -} diff --git a/src/test/compile-fail/regions-close-over-type-parameter-2.rs b/src/test/compile-fail/regions-close-over-type-parameter-2.rs deleted file mode 100644 index 053af49e068..00000000000 --- a/src/test/compile-fail/regions-close-over-type-parameter-2.rs +++ /dev/null @@ -1,36 +0,0 @@ -// 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(box_syntax)] - -// Test for what happens when a type parameter `A` is closed over into -// an object. This should yield errors unless `A` (and the object) -// both have suitable bounds. - -trait Foo { fn get(&self); } - -impl<A> Foo for A { - fn get(&self) { } -} - -fn repeater3<'a,A:'a>(v: A) -> Box<Foo+'a> { - box v as Box<Foo+'a> -} - -fn main() { - // Error results because the type of is inferred to be - // ~Repeat<&'blk isize> where blk is the lifetime of the block below. - - let _ = { - let tmp0 = 3; - let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough - repeater3(tmp1) - }; -} diff --git a/src/test/compile-fail/regions-escape-loop-via-variable.rs b/src/test/compile-fail/regions-escape-loop-via-variable.rs deleted file mode 100644 index f588655d1af..00000000000 --- a/src/test/compile-fail/regions-escape-loop-via-variable.rs +++ /dev/null @@ -1,23 +0,0 @@ -// 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 main() { - let x = 3; - - // Here, the variable `p` gets inferred to a type with a lifetime - // of the loop body. The regionck then determines that this type - // is invalid. - let mut p = &x; - - loop { - let x = 1 + *p; - p = &x; //~ ERROR `x` does not live long enough - } -} diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs deleted file mode 100644 index 8982b5cd98d..00000000000 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -// The type of `y` ends up getting inferred to the type of the block. -fn broken() { - let mut x = 3; - let mut _y = vec![&mut x]; - //~^ NOTE borrow of `x` occurs here - //~| NOTE borrow of `x` occurs here - //~| NOTE borrow of `x` occurs here - while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed - //~^ NOTE use of borrowed `x` - let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed - //~^ NOTE use of borrowed `x` - _y.push(&mut z); //~ ERROR `z` does not live long enough - //~^ NOTE does not live long enough - x += 1; //~ ERROR cannot assign - //~^ NOTE assignment to borrowed `x` occurs here - } - //~^ NOTE borrowed value only lives until here -} -//~^ NOTE borrowed value needs to live until here - -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 deleted file mode 100644 index a05658e9e58..00000000000 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ /dev/null @@ -1,32 +0,0 @@ -// 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 borrow<T>(x: &T) -> &T {x} - -fn foo<C, M>(mut cond: C, mut make_box: M) where - C: FnMut() -> bool, - M: FnMut() -> Box<isize>, -{ - let mut y: &isize; - 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/send-is-not-static-ensures-scoping.rs b/src/test/compile-fail/send-is-not-static-ensures-scoping.rs deleted file mode 100644 index 1b7718d2283..00000000000 --- a/src/test/compile-fail/send-is-not-static-ensures-scoping.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -struct Guard<'a> { - f: Box<Fn() + Send + 'a>, -} - -fn scoped<'a, F: Fn() + Send + 'a>(f: F) -> Guard<'a> { - Guard { f: Box::new(f) } -} - -impl<'a> Guard<'a> { - fn join(self) {} -} - -fn main() { - let bad = { - let x = 1; - let y = &x; //~ ERROR `x` does not live long enough - - scoped(|| { - let _z = y; - //~^ ERROR `y` does not live long enough - }) - }; - - bad.join(); -} diff --git a/src/test/compile-fail/send-is-not-static-std-sync-2.rs b/src/test/compile-fail/send-is-not-static-std-sync-2.rs deleted file mode 100644 index d9d3706586b..00000000000 --- a/src/test/compile-fail/send-is-not-static-std-sync-2.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015 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. - -// basic tests to see that certain "obvious" errors are caught by -// these types no longer requiring `'static` (RFC 458) - -#![allow(dead_code)] - -use std::sync::{Mutex, RwLock, mpsc}; - -fn mutex() { - let lock = { - let x = 1; - Mutex::new(&x) //~ ERROR does not live long enough - }; - - let _dangling = *lock.lock().unwrap(); -} - -fn rwlock() { - let lock = { - let x = 1; - RwLock::new(&x) //~ ERROR does not live long enough - }; - let _dangling = *lock.read().unwrap(); -} - -fn channel() { - let (_tx, rx) = { - let x = 1; - let (tx, rx) = mpsc::channel(); - let _ = tx.send(&x); //~ ERROR does not live long enough - (tx, rx) - }; - - let _dangling = rx.recv(); -} - -fn main() {} diff --git a/src/test/compile-fail/send-is-not-static-std-sync.rs b/src/test/compile-fail/send-is-not-static-std-sync.rs deleted file mode 100644 index 8ec2fe8a1ec..00000000000 --- a/src/test/compile-fail/send-is-not-static-std-sync.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 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. - -// basic tests to see that certain "obvious" errors are caught by -// these types no longer requiring `'static` (RFC 458) - -#![allow(dead_code)] - -use std::sync::{Mutex, RwLock, mpsc}; - -fn mutex() { - let x = 1; - let y = Box::new(1); - let lock = Mutex::new(&x); - *lock.lock().unwrap() = &*y; - drop(y); //~ ERROR cannot move out - { - let z = 2; - *lock.lock().unwrap() = &z; //~ ERROR does not live long enough - } -} - -fn rwlock() { - let x = 1; - let y = Box::new(1); - let lock = RwLock::new(&x); - *lock.write().unwrap() = &*y; - drop(y); //~ ERROR cannot move out - { - let z = 2; - *lock.write().unwrap() = &z; //~ ERROR does not live long enough - } -} - -fn channel() { - let x = 1; - let y = Box::new(1); - let (tx, rx) = mpsc::channel(); - - tx.send(&x).unwrap(); - tx.send(&*y); - drop(y); //~ ERROR cannot move out - { - let z = 2; - tx.send(&z).unwrap(); //~ ERROR does not live long enough - } -} - -fn main() {} diff --git a/src/test/compile-fail/wf-method-late-bound-regions.rs b/src/test/compile-fail/wf-method-late-bound-regions.rs deleted file mode 100644 index b9d292fd156..00000000000 --- a/src/test/compile-fail/wf-method-late-bound-regions.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 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. - -// A method's receiver must be well-formed, even if it has late-bound regions. -// Because of this, a method's substs being well-formed does not imply that -// the method's implied bounds are met. - -struct Foo<'b>(Option<&'b ()>); - -trait Bar<'b> { - fn xmute<'a>(&'a self, u: &'b u32) -> &'a u32; -} - -impl<'b> Bar<'b> for Foo<'b> { - fn xmute<'a>(&'a self, u: &'b u32) -> &'a u32 { u } -} - -fn main() { - let f = Foo(None); - let f2 = f; - let dangling = { - let pointer = Box::new(42); - f2.xmute(&pointer) //~ ERROR `pointer` does not live long enough - }; - println!("{}", dangling); -} |
