]> git.lizzy.rs Git - rust.git/commitdiff
Improve "Doesn't live long enough" error
authorMikhail Modin <mikhailm1@gmail.com>
Wed, 26 Oct 2016 16:10:39 +0000 (19:10 +0300)
committerMikhail Modin <mikhailm1@gmail.com>
Tue, 1 Nov 2016 16:39:28 +0000 (19:39 +0300)
case with different lifetime with spans

42 files changed:
src/librustc_borrowck/borrowck/mod.rs
src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs [deleted file]
src/test/compile-fail/destructor-restrictions.rs [deleted file]
src/test/compile-fail/mut-ptr-cant-outlive-ref.rs [deleted file]
src/test/compile-fail/range-2.rs [deleted file]
src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs [deleted file]
src/test/compile-fail/regions-close-over-type-parameter-2.rs [deleted file]
src/test/compile-fail/regions-escape-loop-via-variable.rs [deleted file]
src/test/compile-fail/regions-escape-loop-via-vec.rs [deleted file]
src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs [deleted file]
src/test/compile-fail/send-is-not-static-ensures-scoping.rs [deleted file]
src/test/compile-fail/send-is-not-static-std-sync-2.rs [deleted file]
src/test/compile-fail/send-is-not-static-std-sync.rs [deleted file]
src/test/compile-fail/wf-method-late-bound-regions.rs [deleted file]
src/test/ui/span/borrowck-ref-into-rvalue.rs [new file with mode: 0644]
src/test/ui/span/borrowck-ref-into-rvalue.stderr [new file with mode: 0644]
src/test/ui/span/destructor-restrictions.rs [new file with mode: 0644]
src/test/ui/span/destructor-restrictions.stderr [new file with mode: 0644]
src/test/ui/span/issue-11925.stderr
src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr
src/test/ui/span/mut-ptr-cant-outlive-ref.rs [new file with mode: 0644]
src/test/ui/span/mut-ptr-cant-outlive-ref.stderr [new file with mode: 0644]
src/test/ui/span/range-2.rs [new file with mode: 0644]
src/test/ui/span/range-2.stderr [new file with mode: 0644]
src/test/ui/span/regionck-unboxed-closure-lifetimes.rs [new file with mode: 0644]
src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr [new file with mode: 0644]
src/test/ui/span/regions-close-over-type-parameter-2.rs [new file with mode: 0644]
src/test/ui/span/regions-close-over-type-parameter-2.stderr [new file with mode: 0644]
src/test/ui/span/regions-escape-loop-via-variable.rs [new file with mode: 0644]
src/test/ui/span/regions-escape-loop-via-variable.stderr [new file with mode: 0644]
src/test/ui/span/regions-escape-loop-via-vec.rs [new file with mode: 0644]
src/test/ui/span/regions-escape-loop-via-vec.stderr [new file with mode: 0644]
src/test/ui/span/regions-infer-borrow-scope-within-loop.rs [new file with mode: 0644]
src/test/ui/span/regions-infer-borrow-scope-within-loop.stderr [new file with mode: 0644]
src/test/ui/span/send-is-not-static-ensures-scoping.rs [new file with mode: 0644]
src/test/ui/span/send-is-not-static-ensures-scoping.stderr [new file with mode: 0644]
src/test/ui/span/send-is-not-static-std-sync-2.rs [new file with mode: 0644]
src/test/ui/span/send-is-not-static-std-sync-2.stderr [new file with mode: 0644]
src/test/ui/span/send-is-not-static-std-sync.rs [new file with mode: 0644]
src/test/ui/span/send-is-not-static-std-sync.stderr [new file with mode: 0644]
src/test/ui/span/wf-method-late-bound-regions.rs [new file with mode: 0644]
src/test/ui/span/wf-method-late-bound-regions.stderr [new file with mode: 0644]

index ef6936b6e7db3184894abb60cf72d047cb1ee46f..0d084d9b930dbc894c7739ad80bd7e14a8b4f6c8 100644 (file)
@@ -1064,6 +1064,19 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
                         db.note("values in a scope are dropped in the opposite order \
                                 they are created");
                     }
+                    (Some(s1), Some(s2)) if !is_temporary && !is_closure => {
+                        db.span = MultiSpan::from_span(s2);
+                        db.span_label(error_span, &format!("borrow occurs here"));
+                        let msg = match opt_loan_path(&err.cmt) {
+                            None => "borrowed value".to_string(),
+                            Some(lp) => {
+                                format!("`{}`", self.loan_path_to_string(&lp))
+                            }
+                        };
+                        db.span_label(s2,
+                                      &format!("{} dropped here while still borrowed", msg));
+                        db.span_label(s1, &format!("{} needs to live until here", value_kind));
+                    }
                     _ => {
                         match sub_span {
                             Some(s) => {
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 (file)
index 726d4bc..0000000
+++ /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 (file)
index 22f615c..0000000
+++ /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 (file)
index 8e968d9..0000000
+++ /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 (file)
index 9496769..0000000
+++ /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 (file)
index 8ec6036..0000000
+++ /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 (file)
index 053af49..0000000
+++ /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 (file)
index f588655..0000000
+++ /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 (file)
index 8982b5c..0000000
+++ /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 (file)
index a05658e..0000000
+++ /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 (file)
index 1b7718d..0000000
+++ /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 (file)
index d9d3706..0000000
+++ /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 (file)
index 8ec2fe8..0000000
+++ /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 (file)
index b9d292f..0000000
+++ /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);
-}
diff --git a/src/test/ui/span/borrowck-ref-into-rvalue.rs b/src/test/ui/span/borrowck-ref-into-rvalue.rs
new file mode 100644 (file)
index 0000000..726d4bc
--- /dev/null
@@ -0,0 +1,20 @@
+// 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/ui/span/borrowck-ref-into-rvalue.stderr b/src/test/ui/span/borrowck-ref-into-rvalue.stderr
new file mode 100644 (file)
index 0000000..adbf39b
--- /dev/null
@@ -0,0 +1,16 @@
+error: borrowed value does not live long enough
+  --> $DIR/borrowck-ref-into-rvalue.rs:18:5
+   |
+14 |         Some(ref m) => { //~ ERROR borrowed value does not live long enough
+   |              ----- borrow occurs here
+...
+18 |     }
+   |     ^ borrowed value dropped here while still borrowed
+19 |     println!("{}", *msg);
+20 | }
+   | - borrowed value needs to live until here
+   |
+   = note: consider using a `let` binding to increase its lifetime
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/destructor-restrictions.rs b/src/test/ui/span/destructor-restrictions.rs
new file mode 100644 (file)
index 0000000..22f615c
--- /dev/null
@@ -0,0 +1,21 @@
+// 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/ui/span/destructor-restrictions.stderr b/src/test/ui/span/destructor-restrictions.stderr
new file mode 100644 (file)
index 0000000..3253212
--- /dev/null
@@ -0,0 +1,12 @@
+error: `*a` does not live long enough
+  --> $DIR/destructor-restrictions.rs:19:5
+   |
+18 |         *a.borrow() + 1    //~ ERROR `*a` does not live long enough
+   |          - borrow occurs here
+19 |     };
+   |     ^- borrowed value needs to live until here
+   |     |
+   |     `*a` dropped here while still borrowed
+
+error: aborting due to previous error
+
index 3fedb2884bc58c8cd3c52f469c3f19f3cdf5d224..6ad9c27b8b9101418959815e2a929c52f5ed2538 100644 (file)
@@ -4,8 +4,8 @@ error: `x` does not live long enough
 18 |         let f = to_fn_once(move|| &x);
    |                                    ^
    |                                    |
-   |                                    does not live long enough
-   |                                    borrowed value only lives until here
+   |                                    borrow occurs here
+   |                                    `x` dropped here while still borrowed
 ...
 23 | }
    | - borrowed value needs to live until here
index f10ba0bf2210f2fe1aac312149ce712758f4bb91..85a0002f2418081f2d43b4c12082fab811fcf94b 100644 (file)
@@ -9,14 +9,14 @@ error: `y` does not live long enough
    = note: values in a scope are dropped in the opposite order they are created
 
 error: `y` does not live long enough
-  --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:27:9
+  --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:28:5
    |
 27 |         y.borrow().clone() //~ ERROR `y` does not live long enough
-   |         ^ does not live long enough
+   |         - borrow occurs here
 28 |     };
-   |     -- borrowed value needs to live until here
+   |     ^- borrowed value needs to live until here
    |     |
-   |     borrowed value only lives until here
+   |     `y` dropped here while still borrowed
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/span/mut-ptr-cant-outlive-ref.rs b/src/test/ui/span/mut-ptr-cant-outlive-ref.rs
new file mode 100644 (file)
index 0000000..8e968d9
--- /dev/null
@@ -0,0 +1,20 @@
+// 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/ui/span/mut-ptr-cant-outlive-ref.stderr b/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr
new file mode 100644 (file)
index 0000000..0417eb0
--- /dev/null
@@ -0,0 +1,12 @@
+error: `b` does not live long enough
+  --> $DIR/mut-ptr-cant-outlive-ref.rs:19:5
+   |
+18 |         p = &*b; //~ ERROR `b` does not live long enough
+   |               - borrow occurs here
+19 |     }
+   |     ^ `b` dropped here while still borrowed
+20 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/range-2.rs b/src/test/ui/span/range-2.rs
new file mode 100644 (file)
index 0000000..9496769
--- /dev/null
@@ -0,0 +1,21 @@
+// 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/ui/span/range-2.stderr b/src/test/ui/span/range-2.stderr
new file mode 100644 (file)
index 0000000..9f11de7
--- /dev/null
@@ -0,0 +1,24 @@
+error: `a` does not live long enough
+  --> $DIR/range-2.rs:20:5
+   |
+17 |         &a..&b
+   |          - borrow occurs here
+...
+20 |     };
+   |     ^ `a` dropped here while still borrowed
+21 | }
+   | - borrowed value needs to live until here
+
+error: `b` does not live long enough
+  --> $DIR/range-2.rs:20:5
+   |
+17 |         &a..&b
+   |              - borrow occurs here
+...
+20 |     };
+   |     ^ `b` dropped here while still borrowed
+21 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs b/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs
new file mode 100644 (file)
index 0000000..8ec6036
--- /dev/null
@@ -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.
+
+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/ui/span/regionck-unboxed-closure-lifetimes.stderr b/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr
new file mode 100644 (file)
index 0000000..9c369e0
--- /dev/null
@@ -0,0 +1,13 @@
+error: `c` does not live long enough
+  --> $DIR/regionck-unboxed-closure-lifetimes.rs:19:5
+   |
+17 |         let c_ref = &c; //~ ERROR `c` does not live long enough
+   |                      - borrow occurs here
+18 |         f = move |a: isize, b: isize| { a + b + *c_ref };
+19 |     }
+   |     ^ `c` dropped here while still borrowed
+20 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/regions-close-over-type-parameter-2.rs b/src/test/ui/span/regions-close-over-type-parameter-2.rs
new file mode 100644 (file)
index 0000000..053af49
--- /dev/null
@@ -0,0 +1,36 @@
+// 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/ui/span/regions-close-over-type-parameter-2.stderr b/src/test/ui/span/regions-close-over-type-parameter-2.stderr
new file mode 100644 (file)
index 0000000..ea652da
--- /dev/null
@@ -0,0 +1,13 @@
+error: `tmp0` does not live long enough
+  --> $DIR/regions-close-over-type-parameter-2.rs:35:5
+   |
+33 |         let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough
+   |                     ---- borrow occurs here
+34 |         repeater3(tmp1)
+35 |     };
+   |     ^- borrowed value needs to live until here
+   |     |
+   |     `tmp0` dropped here while still borrowed
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/regions-escape-loop-via-variable.rs b/src/test/ui/span/regions-escape-loop-via-variable.rs
new file mode 100644 (file)
index 0000000..f588655
--- /dev/null
@@ -0,0 +1,23 @@
+// 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/ui/span/regions-escape-loop-via-variable.stderr b/src/test/ui/span/regions-escape-loop-via-variable.stderr
new file mode 100644 (file)
index 0000000..09f2154
--- /dev/null
@@ -0,0 +1,12 @@
+error: `x` does not live long enough
+  --> $DIR/regions-escape-loop-via-variable.rs:22:5
+   |
+21 |         p = &x; //~ ERROR `x` does not live long enough
+   |              - borrow occurs here
+22 |     }
+   |     ^ `x` dropped here while still borrowed
+23 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/regions-escape-loop-via-vec.rs b/src/test/ui/span/regions-escape-loop-via-vec.rs
new file mode 100644 (file)
index 0000000..8982b5c
--- /dev/null
@@ -0,0 +1,31 @@
+// 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/ui/span/regions-escape-loop-via-vec.stderr b/src/test/ui/span/regions-escape-loop-via-vec.stderr
new file mode 100644 (file)
index 0000000..58f7849
--- /dev/null
@@ -0,0 +1,41 @@
+error: `z` does not live long enough
+  --> $DIR/regions-escape-loop-via-vec.rs:26:5
+   |
+22 |         _y.push(&mut z); //~ ERROR `z` does not live long enough
+   |                      - borrow occurs here
+...
+26 |     }
+   |     ^ `z` dropped here while still borrowed
+27 |     //~^ NOTE borrowed value only lives until here
+28 | }
+   | - borrowed value needs to live until here
+
+error[E0503]: cannot use `x` because it was mutably borrowed
+  --> $DIR/regions-escape-loop-via-vec.rs:18:11
+   |
+14 |     let mut _y = vec![&mut x];
+   |                            - borrow of `x` occurs here
+...
+18 |     while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed
+   |           ^ use of borrowed `x`
+
+error[E0503]: cannot use `x` because it was mutably borrowed
+  --> $DIR/regions-escape-loop-via-vec.rs:20:13
+   |
+14 |     let mut _y = vec![&mut x];
+   |                            - borrow of `x` occurs here
+...
+20 |         let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed
+   |             ^^^^^ use of borrowed `x`
+
+error[E0506]: cannot assign to `x` because it is borrowed
+  --> $DIR/regions-escape-loop-via-vec.rs:24:9
+   |
+14 |     let mut _y = vec![&mut x];
+   |                            - borrow of `x` occurs here
+...
+24 |         x += 1; //~ ERROR cannot assign
+   |         ^^^^^^ assignment to borrowed `x` occurs here
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/span/regions-infer-borrow-scope-within-loop.rs b/src/test/ui/span/regions-infer-borrow-scope-within-loop.rs
new file mode 100644 (file)
index 0000000..a05658e
--- /dev/null
@@ -0,0 +1,32 @@
+// 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/ui/span/regions-infer-borrow-scope-within-loop.stderr b/src/test/ui/span/regions-infer-borrow-scope-within-loop.stderr
new file mode 100644 (file)
index 0000000..0e7b64e
--- /dev/null
@@ -0,0 +1,14 @@
+error: `*x` does not live long enough
+  --> $DIR/regions-infer-borrow-scope-within-loop.rs:28:5
+   |
+24 |         y = borrow(&*x); //~ ERROR `*x` does not live long enough
+   |                     -- borrow occurs here
+...
+28 |     }
+   |     ^ `*x` dropped here while still borrowed
+29 |     assert!(*y != 0);
+30 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/span/send-is-not-static-ensures-scoping.rs b/src/test/ui/span/send-is-not-static-ensures-scoping.rs
new file mode 100644 (file)
index 0000000..1b7718d
--- /dev/null
@@ -0,0 +1,35 @@
+// 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/ui/span/send-is-not-static-ensures-scoping.stderr b/src/test/ui/span/send-is-not-static-ensures-scoping.stderr
new file mode 100644 (file)
index 0000000..5897921
--- /dev/null
@@ -0,0 +1,28 @@
+error: `x` does not live long enough
+  --> $DIR/send-is-not-static-ensures-scoping.rs:32:5
+   |
+26 |         let y = &x; //~ ERROR `x` does not live long enough
+   |                  - borrow occurs here
+...
+32 |     };
+   |     ^ `x` dropped here while still borrowed
+...
+35 | }
+   | - borrowed value needs to live until here
+
+error: `y` does not live long enough
+  --> $DIR/send-is-not-static-ensures-scoping.rs:29:22
+   |
+28 |         scoped(|| {
+   |                -- capture occurs here
+29 |             let _z = y;
+   |                      ^ does not live long enough
+...
+32 |     };
+   |     - borrowed value only lives until here
+...
+35 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/span/send-is-not-static-std-sync-2.rs b/src/test/ui/span/send-is-not-static-std-sync-2.rs
new file mode 100644 (file)
index 0000000..d9d3706
--- /dev/null
@@ -0,0 +1,46 @@
+// 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/ui/span/send-is-not-static-std-sync-2.stderr b/src/test/ui/span/send-is-not-static-std-sync-2.stderr
new file mode 100644 (file)
index 0000000..08f85f1
--- /dev/null
@@ -0,0 +1,36 @@
+error: `x` does not live long enough
+  --> $DIR/send-is-not-static-std-sync-2.rs:22:5
+   |
+21 |         Mutex::new(&x) //~ ERROR does not live long enough
+   |                     - borrow occurs here
+22 |     };
+   |     ^ `x` dropped here while still borrowed
+...
+25 | }
+   | - borrowed value needs to live until here
+
+error: `x` does not live long enough
+  --> $DIR/send-is-not-static-std-sync-2.rs:31:5
+   |
+30 |         RwLock::new(&x) //~ ERROR does not live long enough
+   |                      - borrow occurs here
+31 |     };
+   |     ^ `x` dropped here while still borrowed
+32 |     let _dangling = *lock.read().unwrap();
+33 | }
+   | - borrowed value needs to live until here
+
+error: `x` does not live long enough
+  --> $DIR/send-is-not-static-std-sync-2.rs:41:5
+   |
+39 |         let _ = tx.send(&x); //~ ERROR does not live long enough
+   |                          - borrow occurs here
+40 |         (tx, rx)
+41 |     };
+   |     ^ `x` dropped here while still borrowed
+...
+44 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/span/send-is-not-static-std-sync.rs b/src/test/ui/span/send-is-not-static-std-sync.rs
new file mode 100644 (file)
index 0000000..8ec2fe8
--- /dev/null
@@ -0,0 +1,56 @@
+// 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/ui/span/send-is-not-static-std-sync.stderr b/src/test/ui/span/send-is-not-static-std-sync.stderr
new file mode 100644 (file)
index 0000000..a86cf1e
--- /dev/null
@@ -0,0 +1,56 @@
+error: `z` does not live long enough
+  --> $DIR/send-is-not-static-std-sync.rs:27:5
+   |
+26 |         *lock.lock().unwrap() = &z; //~ ERROR does not live long enough
+   |                                  - borrow occurs here
+27 |     }
+   |     ^ `z` dropped here while still borrowed
+28 | }
+   | - borrowed value needs to live until here
+
+error[E0505]: cannot move out of `y` because it is borrowed
+  --> $DIR/send-is-not-static-std-sync.rs:23:10
+   |
+22 |     *lock.lock().unwrap() = &*y;
+   |                              -- borrow of `*y` occurs here
+23 |     drop(y); //~ ERROR cannot move out
+   |          ^ move out of `y` occurs here
+
+error: `z` does not live long enough
+  --> $DIR/send-is-not-static-std-sync.rs:39:5
+   |
+38 |         *lock.write().unwrap() = &z; //~ ERROR does not live long enough
+   |                                   - borrow occurs here
+39 |     }
+   |     ^ `z` dropped here while still borrowed
+40 | }
+   | - borrowed value needs to live until here
+
+error[E0505]: cannot move out of `y` because it is borrowed
+  --> $DIR/send-is-not-static-std-sync.rs:35:10
+   |
+34 |     *lock.write().unwrap() = &*y;
+   |                               -- borrow of `*y` occurs here
+35 |     drop(y); //~ ERROR cannot move out
+   |          ^ move out of `y` occurs here
+
+error: `z` does not live long enough
+  --> $DIR/send-is-not-static-std-sync.rs:53:5
+   |
+52 |         tx.send(&z).unwrap(); //~ ERROR does not live long enough
+   |                  - borrow occurs here
+53 |     }
+   |     ^ `z` dropped here while still borrowed
+54 | }
+   | - borrowed value needs to live until here
+
+error[E0505]: cannot move out of `y` because it is borrowed
+  --> $DIR/send-is-not-static-std-sync.rs:49:10
+   |
+48 |     tx.send(&*y);
+   |              -- borrow of `*y` occurs here
+49 |     drop(y); //~ ERROR cannot move out
+   |          ^ move out of `y` occurs here
+
+error: aborting due to 6 previous errors
+
diff --git a/src/test/ui/span/wf-method-late-bound-regions.rs b/src/test/ui/span/wf-method-late-bound-regions.rs
new file mode 100644 (file)
index 0000000..b9d292f
--- /dev/null
@@ -0,0 +1,33 @@
+// 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);
+}
diff --git a/src/test/ui/span/wf-method-late-bound-regions.stderr b/src/test/ui/span/wf-method-late-bound-regions.stderr
new file mode 100644 (file)
index 0000000..aeac310
--- /dev/null
@@ -0,0 +1,13 @@
+error: `pointer` does not live long enough
+  --> $DIR/wf-method-late-bound-regions.rs:31:5
+   |
+30 |         f2.xmute(&pointer) //~ ERROR `pointer` does not live long enough
+   |                   ------- borrow occurs here
+31 |     };
+   |     ^ `pointer` dropped here while still borrowed
+32 |     println!("{}", dangling);
+33 | }
+   | - borrowed value needs to live until here
+
+error: aborting due to previous error
+