about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorTaylor Cramer <cramertj@google.com>2017-11-16 22:59:45 -0800
committerNiko Matsakis <niko@alum.mit.edu>2017-11-22 12:44:09 -0500
commit91b7920c09004ed4dcbad0ab4128a664ca794848 (patch)
treebb18e5558bcef5aeeadfa70dbac668a980c0e6af /src/test
parent1dc0b573e7ce4314eb196b21b7e0ea4a1bf1f673 (diff)
Implement in-band lifetime bindings
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/feature-gate-in_band_lifetimes.rs72
-rw-r--r--src/test/run-pass/in-band-lifetimes.rs84
-rw-r--r--src/test/ui/in-band-lifetimes/E0687.rs26
-rw-r--r--src/test/ui/in-band-lifetimes/E0687.stderr26
-rw-r--r--src/test/ui/in-band-lifetimes/E0687_where.rs18
-rw-r--r--src/test/ui/in-band-lifetimes/E0687_where.stderr14
-rw-r--r--src/test/ui/in-band-lifetimes/E0688.rs26
-rw-r--r--src/test/ui/in-band-lifetimes/E0688.stderr26
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched.rs18
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched.stderr18
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched_trait.rs20
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched_trait.stderr10
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched_trait_impl.rs24
-rw-r--r--src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr39
-rw-r--r--src/test/ui/in-band-lifetimes/mut_while_borrow.rs21
-rw-r--r--src/test/ui/in-band-lifetimes/mut_while_borrow.stderr10
-rw-r--r--src/test/ui/in-band-lifetimes/no_in_band_in_struct.rs22
-rw-r--r--src/test/ui/in-band-lifetimes/no_in_band_in_struct.stderr14
-rw-r--r--src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.rs23
-rw-r--r--src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.stderr14
-rw-r--r--src/test/ui/in-band-lifetimes/shadow.rs21
-rw-r--r--src/test/ui/in-band-lifetimes/shadow.stderr19
22 files changed, 565 insertions, 0 deletions
diff --git a/src/test/compile-fail/feature-gate-in_band_lifetimes.rs b/src/test/compile-fail/feature-gate-in_band_lifetimes.rs
new file mode 100644
index 00000000000..ae1f81c2f57
--- /dev/null
+++ b/src/test/compile-fail/feature-gate-in_band_lifetimes.rs
@@ -0,0 +1,72 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+
+fn foo(x: &'x u8) -> &'x u8 { x }
+//~^ ERROR use of undeclared lifetime name
+//~^^ ERROR use of undeclared lifetime name
+
+struct X<'a>(&'a u8);
+
+impl<'a> X<'a> {
+    fn inner(&self) -> &'a u8 {
+        self.0
+    }
+}
+
+impl<'a> X<'b> {
+//~^ ERROR use of undeclared lifetime name
+    fn inner_2(&self) -> &'b u8 {
+    //~^ ERROR use of undeclared lifetime name
+        self.0
+    }
+}
+
+impl X<'b> {
+//~^ ERROR use of undeclared lifetime name
+    fn inner_3(&self) -> &'b u8 {
+    //~^ ERROR use of undeclared lifetime name
+        self.0
+    }
+}
+
+struct Y<T>(T);
+
+impl Y<&'a u8> {
+    //~^ ERROR use of undeclared lifetime name
+    fn inner(&self) -> &'a u8 {
+    //~^ ERROR use of undeclared lifetime name
+        self.0
+    }
+}
+
+trait MyTrait<'a> {
+    fn my_lifetime(&self) -> &'a u8;
+    fn any_lifetime() -> &'b u8;
+    //~^ ERROR use of undeclared lifetime name
+    fn borrowed_lifetime(&'b self) -> &'b u8;
+    //~^ ERROR use of undeclared lifetime name
+    //~^^ ERROR use of undeclared lifetime name
+}
+
+impl MyTrait<'a> for Y<&'a u8> {
+//~^ ERROR use of undeclared lifetime name
+//~^^ ERROR use of undeclared lifetime name
+    fn my_lifetime(&self) -> &'a u8 { self.0 }
+    //~^ ERROR use of undeclared lifetime name
+    fn any_lifetime() -> &'b u8 { &0 }
+    //~^ ERROR use of undeclared lifetime name
+    fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
+    //~^ ERROR use of undeclared lifetime name
+    //~^^ ERROR use of undeclared lifetime name
+}
+
+fn main() {}
diff --git a/src/test/run-pass/in-band-lifetimes.rs b/src/test/run-pass/in-band-lifetimes.rs
new file mode 100644
index 00000000000..d7a837f23b1
--- /dev/null
+++ b/src/test/run-pass/in-band-lifetimes.rs
@@ -0,0 +1,84 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes, universal_impl_trait)]
+
+fn foo(x: &'x u8) -> &'x u8 { x }
+fn foo2(x: &'a u8, y: &u8) -> &'a u8 { x }
+
+fn check_in_band_can_be_late_bound() {
+    let _: for<'x> fn(&'x u8, &u8) -> &'x u8 = foo2;
+}
+
+struct ForInherentNoParams;
+
+impl ForInherentNoParams {
+    fn foo(x: &'a u32, y: &u32) -> &'a u32 { x }
+}
+
+struct X<'a>(&'a u8);
+
+impl<'a> X<'a> {
+    fn inner(&self) -> &'a u8 {
+        self.0
+    }
+
+    fn same_lifetime_as_parameter(&mut self, x: &'a u8) {
+        self.0 = x;
+    }
+}
+
+impl X<'b> {
+    fn inner_2(&self) -> &'b u8 {
+        self.0
+    }
+
+    fn reference_already_introduced_in_band_from_method_with_explicit_binders<'a>(
+        &'b self, x: &'a u32
+    ) {}
+}
+
+struct Y<T>(T);
+
+impl Y<&'a u8> {
+    fn inner(&self) -> &'a u8 {
+        self.0
+    }
+}
+
+trait MyTrait<'a> {
+    fn my_lifetime(&self) -> &'a u8;
+    fn any_lifetime() -> &'b u8;
+    fn borrowed_lifetime(&'b self) -> &'b u8;
+    fn default_impl(&self, x: &'b u32, y: &u32) -> &'b u32 { x }
+    fn in_band_def_explicit_impl(&self, x: &'b u8);
+}
+
+impl MyTrait<'a> for Y<&'a u8> {
+    fn my_lifetime(&self) -> &'a u8 { self.0 }
+    fn any_lifetime() -> &'b u8 { &0 }
+    fn borrowed_lifetime(&'b self) -> &'b u8 { &*self.0 }
+    fn in_band_def_explicit_impl<'b>(&self, x: &'b u8) {}
+}
+
+fn test_hrtb_defined_lifetime_where<F>(_: F) where for<'a> F: Fn(&'a u8) {}
+fn test_hrtb_defined_lifetime_polytraitref<F>(_: F) where F: for<'a> Fn(&'a u8) {}
+
+fn reference_in_band_from_locals(x: &'test u32) -> &'test u32 {
+    let y: &'test u32 = x;
+    y
+}
+
+fn in_generics_in_band<T: MyTrait<'a>>(x: &T) {}
+fn where_clause_in_band<T>(x: &T) where T: MyTrait<'a> {}
+fn impl_trait_in_band(x: &impl MyTrait<'a>) {}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/E0687.rs b/src/test/ui/in-band-lifetimes/E0687.rs
new file mode 100644
index 00000000000..57b355cbb6a
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0687.rs
@@ -0,0 +1,26 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+fn foo(x: fn(&'a u32)) {}
+
+fn bar(x: &Fn(&'a u32)) {}
+
+fn baz(x: fn(&'a u32), y: &'a u32) {}
+
+struct Foo<'a> { x: &'a u32 }
+
+impl Foo<'a> {
+    fn bar(&self, x: fn(&'a u32)) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/E0687.stderr b/src/test/ui/in-band-lifetimes/E0687.stderr
new file mode 100644
index 00000000000..14b513fc52a
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0687.stderr
@@ -0,0 +1,26 @@
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687.rs:14:15
+   |
+14 | fn foo(x: fn(&'a u32)) {}
+   |               ^^ in-band lifetime definition
+
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687.rs:16:16
+   |
+16 | fn bar(x: &Fn(&'a u32)) {}
+   |                ^^ in-band lifetime definition
+
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687.rs:18:15
+   |
+18 | fn baz(x: fn(&'a u32), y: &'a u32) {}
+   |               ^^ in-band lifetime definition
+
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687.rs:23:26
+   |
+23 |     fn bar(&self, x: fn(&'a u32)) {}
+   |                          ^^ in-band lifetime definition
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/E0687_where.rs b/src/test/ui/in-band-lifetimes/E0687_where.rs
new file mode 100644
index 00000000000..6f04720dd4a
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0687_where.rs
@@ -0,0 +1,18 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes, universal_impl_trait)]
+
+fn bar<F>(x: &F) where F: Fn(&'a u32) {}
+
+fn baz(x: &impl Fn(&'a u32)) {}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/E0687_where.stderr b/src/test/ui/in-band-lifetimes/E0687_where.stderr
new file mode 100644
index 00000000000..db50076fe7c
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0687_where.stderr
@@ -0,0 +1,14 @@
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687_where.rs:14:31
+   |
+14 | fn bar<F>(x: &F) where F: Fn(&'a u32) {}
+   |                               ^^ in-band lifetime definition
+
+error[E0687]: lifetimes used in `fn` or `Fn` syntax must be explicitly declared using `<...>` binders
+  --> $DIR/E0687_where.rs:16:21
+   |
+16 | fn baz(x: &impl Fn(&'a u32)) {}
+   |                     ^^ in-band lifetime definition
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/E0688.rs b/src/test/ui/in-band-lifetimes/E0688.rs
new file mode 100644
index 00000000000..e6fe4e138e4
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0688.rs
@@ -0,0 +1,26 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+fn foo<'a>(x: &'a u32, y: &'b u32) {}
+
+struct Foo<'a> { x: &'a u32 }
+
+impl Foo<'a> {
+    fn bar<'b>(x: &'a u32, y: &'b u32, z: &'c u32) {}
+}
+
+impl<'b> Foo<'a> {
+    fn baz() {}
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/E0688.stderr b/src/test/ui/in-band-lifetimes/E0688.stderr
new file mode 100644
index 00000000000..1289e7fd010
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/E0688.stderr
@@ -0,0 +1,26 @@
+error[E0688]: cannot mix in-band and explicit lifetime definitions
+  --> $DIR/E0688.rs:14:28
+   |
+14 | fn foo<'a>(x: &'a u32, y: &'b u32) {}
+   |        --                  ^^ in-band lifetime definition here
+   |        |
+   |        explicit lifetime definition here
+
+error[E0688]: cannot mix in-band and explicit lifetime definitions
+  --> $DIR/E0688.rs:19:44
+   |
+19 |     fn bar<'b>(x: &'a u32, y: &'b u32, z: &'c u32) {}
+   |            --                              ^^ in-band lifetime definition here
+   |            |
+   |            explicit lifetime definition here
+
+error[E0688]: cannot mix in-band and explicit lifetime definitions
+  --> $DIR/E0688.rs:22:14
+   |
+22 | impl<'b> Foo<'a> {
+   |      --      ^^ in-band lifetime definition here
+   |      |
+   |      explicit lifetime definition here
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/mismatched.rs b/src/test/ui/in-band-lifetimes/mismatched.rs
new file mode 100644
index 00000000000..6b0a3fedfc5
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched.rs
@@ -0,0 +1,18 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+fn foo(x: &'a u32, y: &u32) -> &'a u32 { y }
+
+fn foo2(x: &'a u32, y: &'b u32) -> &'a u32 { y }
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/mismatched.stderr b/src/test/ui/in-band-lifetimes/mismatched.stderr
new file mode 100644
index 00000000000..bbc25869f46
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched.stderr
@@ -0,0 +1,18 @@
+error[E0621]: explicit lifetime required in the type of `y`
+  --> $DIR/mismatched.rs:14:42
+   |
+14 | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y }
+   |                    -                     ^ lifetime `'a` required
+   |                    |
+   |                    consider changing the type of `y` to `&'a u32`
+
+error[E0623]: lifetime mismatch
+  --> $DIR/mismatched.rs:16:46
+   |
+16 | fn foo2(x: &'a u32, y: &'b u32) -> &'a u32 { y }
+   |                        -------     -------   ^ ...but data from `y` is returned here
+   |                        |
+   |                        this parameter and the return type are declared with different lifetimes...
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/mismatched_trait.rs b/src/test/ui/in-band-lifetimes/mismatched_trait.rs
new file mode 100644
index 00000000000..2e316770404
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched_trait.rs
@@ -0,0 +1,20 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+trait Get {
+    fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 {
+        y
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/mismatched_trait.stderr b/src/test/ui/in-band-lifetimes/mismatched_trait.stderr
new file mode 100644
index 00000000000..315e881bf07
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched_trait.stderr
@@ -0,0 +1,10 @@
+error[E0621]: explicit lifetime required in the type of `y`
+  --> $DIR/mismatched_trait.rs:16:9
+   |
+15 |     fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 {
+   |                               - consider changing the type of `y` to `&'a u32`
+16 |         y
+   |         ^ lifetime `'a` required
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/in-band-lifetimes/mismatched_trait_impl.rs b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.rs
new file mode 100644
index 00000000000..1be32e5c51e
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.rs
@@ -0,0 +1,24 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+trait Get {
+    fn foo(&self, x: &'a u32, y: &u32) -> &'a u32;
+}
+
+impl Get for i32 {
+    fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+        x
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr
new file mode 100644
index 00000000000..d1f3ae450f8
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr
@@ -0,0 +1,39 @@
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'a in generic type due to conflicting requirements
+  --> $DIR/mismatched_trait_impl.rs:19:5
+   |
+19 | /     fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+20 | |         x
+21 | |     }
+   | |_____^
+   |
+note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 19:5...
+  --> $DIR/mismatched_trait_impl.rs:19:5
+   |
+19 | /     fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+20 | |         x
+21 | |     }
+   | |_____^
+note: ...so that method type is compatible with trait (expected fn(&i32, &'a u32, &u32) -> &'a u32, found fn(&i32, &u32, &u32) -> &u32)
+  --> $DIR/mismatched_trait_impl.rs:19:5
+   |
+19 | /     fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+20 | |         x
+21 | |     }
+   | |_____^
+note: but, the lifetime must be valid for the lifetime 'a as defined on the method body at 19:5...
+  --> $DIR/mismatched_trait_impl.rs:19:5
+   |
+19 | /     fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+20 | |         x
+21 | |     }
+   | |_____^
+note: ...so that method type is compatible with trait (expected fn(&i32, &'a u32, &u32) -> &'a u32, found fn(&i32, &u32, &u32) -> &u32)
+  --> $DIR/mismatched_trait_impl.rs:19:5
+   |
+19 | /     fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
+20 | |         x
+21 | |     }
+   | |_____^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/in-band-lifetimes/mut_while_borrow.rs b/src/test/ui/in-band-lifetimes/mut_while_borrow.rs
new file mode 100644
index 00000000000..fabf531968a
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mut_while_borrow.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+fn foo(x: &'a u32) -> &'a u32 { x }
+
+fn main() {
+    let mut p = 3;
+    let r = foo(&p);
+    p += 1;
+    println!("{}", r);
+}
diff --git a/src/test/ui/in-band-lifetimes/mut_while_borrow.stderr b/src/test/ui/in-band-lifetimes/mut_while_borrow.stderr
new file mode 100644
index 00000000000..4800e39269f
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/mut_while_borrow.stderr
@@ -0,0 +1,10 @@
+error[E0506]: cannot assign to `p` because it is borrowed
+  --> $DIR/mut_while_borrow.rs:19:5
+   |
+18 |     let r = foo(&p);
+   |                  - borrow of `p` occurs here
+19 |     p += 1;
+   |     ^^^^^^ assignment to borrowed `p` occurs here
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/in-band-lifetimes/no_in_band_in_struct.rs b/src/test/ui/in-band-lifetimes/no_in_band_in_struct.rs
new file mode 100644
index 00000000000..b421e16092c
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/no_in_band_in_struct.rs
@@ -0,0 +1,22 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+struct Foo {
+    x: &'test u32,
+}
+
+enum Bar {
+    Baz(&'test u32),
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/no_in_band_in_struct.stderr b/src/test/ui/in-band-lifetimes/no_in_band_in_struct.stderr
new file mode 100644
index 00000000000..7ffbfbd89b6
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/no_in_band_in_struct.stderr
@@ -0,0 +1,14 @@
+error[E0261]: use of undeclared lifetime name `'test`
+  --> $DIR/no_in_band_in_struct.rs:15:9
+   |
+15 |     x: &'test u32,
+   |         ^^^^^ undeclared lifetime
+
+error[E0261]: use of undeclared lifetime name `'test`
+  --> $DIR/no_in_band_in_struct.rs:19:10
+   |
+19 |     Baz(&'test u32),
+   |          ^^^^^ undeclared lifetime
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.rs b/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.rs
new file mode 100644
index 00000000000..a7c9d4ece95
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.rs
@@ -0,0 +1,23 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+fn foo(x: &u32) {
+    let y: &'test u32 = x;
+}
+
+fn foo2(x: &u32) {}
+fn bar() {
+    let y: fn(&'test u32) = foo2;
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.stderr b/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.stderr
new file mode 100644
index 00000000000..a0c2e819969
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/no_introducing_in_band_in_locals.stderr
@@ -0,0 +1,14 @@
+error[E0261]: use of undeclared lifetime name `'test`
+  --> $DIR/no_introducing_in_band_in_locals.rs:15:13
+   |
+15 |     let y: &'test u32 = x;
+   |             ^^^^^ undeclared lifetime
+
+error[E0261]: use of undeclared lifetime name `'test`
+  --> $DIR/no_introducing_in_band_in_locals.rs:20:16
+   |
+20 |     let y: fn(&'test u32) = foo2;
+   |                ^^^^^ undeclared lifetime
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/in-band-lifetimes/shadow.rs b/src/test/ui/in-band-lifetimes/shadow.rs
new file mode 100644
index 00000000000..a9053d09f6c
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/shadow.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 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.
+
+#![allow(warnings)]
+#![feature(in_band_lifetimes)]
+
+struct Foo<T>(T);
+
+impl Foo<&'s u8> {
+    fn bar<'s>(&self, x: &'s u8) {}
+    fn baz(x: for<'s> fn(&'s u32)) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/in-band-lifetimes/shadow.stderr b/src/test/ui/in-band-lifetimes/shadow.stderr
new file mode 100644
index 00000000000..f05b76fbea4
--- /dev/null
+++ b/src/test/ui/in-band-lifetimes/shadow.stderr
@@ -0,0 +1,19 @@
+error[E0496]: lifetime name `'s` shadows a lifetime name that is already in scope
+  --> $DIR/shadow.rs:17:12
+   |
+16 | impl Foo<&'s u8> {
+   |           -- first declared here
+17 |     fn bar<'s>(&self, x: &'s u8) {}
+   |            ^^ lifetime 's already in scope
+
+error[E0496]: lifetime name `'s` shadows a lifetime name that is already in scope
+  --> $DIR/shadow.rs:18:19
+   |
+16 | impl Foo<&'s u8> {
+   |           -- first declared here
+17 |     fn bar<'s>(&self, x: &'s u8) {}
+18 |     fn baz(x: for<'s> fn(&'s u32)) {}
+   |                   ^^ lifetime 's already in scope
+
+error: aborting due to 2 previous errors
+