about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2018-09-15 18:24:18 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2018-09-19 19:52:55 +0100
commitfcd0cd0adef72e2bc00016eccd97af2ebf70c12c (patch)
tree4be1a154592d8996294b6102febda30292558a33 /src/test
parentb210b3168a572c84710bc160915592307f7a3ac5 (diff)
downloadrust-fcd0cd0adef72e2bc00016eccd97af2ebf70c12c.tar.gz
rust-fcd0cd0adef72e2bc00016eccd97af2ebf70c12c.zip
Don't try to use a path to a type alias as a path to the adt it aliases
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/nll/type-alias-free-regions.rs33
-rw-r--r--src/test/ui/nll/type-alias-free-regions.stderr22
2 files changed, 55 insertions, 0 deletions
diff --git a/src/test/ui/nll/type-alias-free-regions.rs b/src/test/ui/nll/type-alias-free-regions.rs
new file mode 100644
index 00000000000..6e480dcaac0
--- /dev/null
+++ b/src/test/ui/nll/type-alias-free-regions.rs
@@ -0,0 +1,33 @@
+// Test that we don't assume that type aliases have the same type parameters
+// as the type they alias and then panic when we see this.
+
+#![feature(nll)]
+
+type a<'a> = &'a isize;
+type b<'a> = Box<a<'a>>;
+
+struct c<'a> {
+    f: Box<b<'a>>
+}
+
+trait FromBox<'a> {
+    fn from_box(b: Box<b>) -> Self;
+}
+
+impl<'a> FromBox<'a> for c<'a> {
+    fn from_box(b: Box<b>) -> Self {
+        c { f: b } //~ ERROR
+    }
+}
+
+trait FromTuple<'a> {
+    fn from_tuple( b: (b,)) -> Self;
+}
+
+impl<'a> FromTuple<'a> for c<'a> {
+    fn from_tuple(b: (b,)) -> Self {
+        c { f: Box::new(b.0) } //~ ERROR
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/type-alias-free-regions.stderr b/src/test/ui/nll/type-alias-free-regions.stderr
new file mode 100644
index 00000000000..05f2c930944
--- /dev/null
+++ b/src/test/ui/nll/type-alias-free-regions.stderr
@@ -0,0 +1,22 @@
+error: unsatisfied lifetime constraints
+  --> $DIR/type-alias-free-regions.rs:19:9
+   |
+LL | impl<'a> FromBox<'a> for c<'a> {
+   |      -- lifetime `'a` defined here
+LL |     fn from_box(b: Box<b>) -> Self {
+   |                 - has type `std::boxed::Box<std::boxed::Box<&'1 isize>>`
+LL |         c { f: b } //~ ERROR
+   |         ^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
+
+error: unsatisfied lifetime constraints
+  --> $DIR/type-alias-free-regions.rs:29:9
+   |
+LL | impl<'a> FromTuple<'a> for c<'a> {
+   |      -- lifetime `'a` defined here
+LL |     fn from_tuple(b: (b,)) -> Self {
+   |                   - has type `(std::boxed::Box<&'1 isize>,)`
+LL |         c { f: Box::new(b.0) } //~ ERROR
+   |         ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'a`
+
+error: aborting due to 2 previous errors
+