about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-02-17 15:42:53 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-03-28 17:01:09 +0000
commit53c96ed528257489f5537c69a33b27ffce6fee6f (patch)
treee35fd3d7b9238ae9c6772c4df88558425c2c2dea
parent1f46f771a6b579c1330976c1638ccc4a03e8863f (diff)
downloadrust-53c96ed528257489f5537c69a33b27ffce6fee6f.tar.gz
rust-53c96ed528257489f5537c69a33b27ffce6fee6f.zip
Add some tests around recursion and "revealing"
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion.rs23
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion2.rs21
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr16
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion3.rs21
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion3.stderr19
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion4.rs23
-rw-r--r--src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr29
7 files changed, 152 insertions, 0 deletions
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion.rs b/src/test/ui/lazy-type-alias-impl-trait/recursion.rs
new file mode 100644
index 00000000000..cf7cd5d26ca
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion.rs
@@ -0,0 +1,23 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+type Foo = impl std::fmt::Debug;
+
+fn foo(b: bool) -> Foo {
+    if b {
+        return 42
+    }
+    let x: u32 = foo(false);
+    99
+}
+
+fn bar(b: bool) -> impl std::fmt::Debug {
+    if b {
+        return 42
+    }
+    let x: u32 = bar(false);
+    99
+}
+
+fn main() {}
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs b/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs
new file mode 100644
index 00000000000..1cc64ea17e7
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs
@@ -0,0 +1,21 @@
+#![feature(type_alias_impl_trait)]
+
+type Foo = impl std::fmt::Debug;
+
+fn foo(b: bool) -> Foo {
+    if b {
+        return vec![];
+    }
+    let x: Vec<i32> = foo(false);
+    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
+}
+
+fn bar(b: bool) -> impl std::fmt::Debug {
+    if b {
+        return vec![]
+    }
+    let x: Vec<i32> = bar(false);
+    std::iter::empty().collect()
+}
+
+fn main() {}
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr b/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr
new file mode 100644
index 00000000000..1f6201a8300
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr
@@ -0,0 +1,16 @@
+error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_`
+  --> $DIR/recursion2.rs:10:24
+   |
+LL |     std::iter::empty().collect()
+   |                        ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator<Item=_>`
+   |
+   = help: the trait `FromIterator<_>` is not implemented for `Foo`
+note: required by a bound in `collect`
+  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
+   |
+LL |     fn collect<B: FromIterator<Self::Item>>(self) -> B
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion3.rs b/src/test/ui/lazy-type-alias-impl-trait/recursion3.rs
new file mode 100644
index 00000000000..7f1cedae068
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion3.rs
@@ -0,0 +1,21 @@
+#![feature(type_alias_impl_trait)]
+
+type Foo = impl std::fmt::Debug;
+
+fn foo(b: bool) -> Foo {
+    if b {
+        return 42
+    }
+    let x: u32 = foo(false) + 42; //~ ERROR cannot add
+    99
+}
+
+fn bar(b: bool) -> impl std::fmt::Debug {
+    if b {
+        return 42
+    }
+    let x: u32 = bar(false) + 42; //~ ERROR cannot add
+    99
+}
+
+fn main() {}
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion3.stderr b/src/test/ui/lazy-type-alias-impl-trait/recursion3.stderr
new file mode 100644
index 00000000000..e1d5cafedc8
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion3.stderr
@@ -0,0 +1,19 @@
+error[E0369]: cannot add `{integer}` to `Foo`
+  --> $DIR/recursion3.rs:9:29
+   |
+LL |     let x: u32 = foo(false) + 42;
+   |                  ---------- ^ -- {integer}
+   |                  |
+   |                  Foo
+
+error[E0369]: cannot add `{integer}` to `impl Debug`
+  --> $DIR/recursion3.rs:17:29
+   |
+LL |     let x: u32 = bar(false) + 42;
+   |                  ---------- ^ -- {integer}
+   |                  |
+   |                  impl Debug
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0369`.
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion4.rs b/src/test/ui/lazy-type-alias-impl-trait/recursion4.rs
new file mode 100644
index 00000000000..57dd7fb067c
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion4.rs
@@ -0,0 +1,23 @@
+#![feature(type_alias_impl_trait)]
+
+type Foo = impl std::fmt::Debug;
+
+fn foo(b: bool) -> Foo {
+    if b {
+        return vec![];
+    }
+    let mut x = foo(false);
+    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
+    vec![]
+}
+
+fn bar(b: bool) -> impl std::fmt::Debug {
+    if b {
+        return vec![];
+    }
+    let mut x = bar(false);
+    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
+    vec![]
+}
+
+fn main() {}
diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr b/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr
new file mode 100644
index 00000000000..42a1f782d29
--- /dev/null
+++ b/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr
@@ -0,0 +1,29 @@
+error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_`
+  --> $DIR/recursion4.rs:10:28
+   |
+LL |     x = std::iter::empty().collect();
+   |                            ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator<Item=_>`
+   |
+   = help: the trait `FromIterator<_>` is not implemented for `Foo`
+note: required by a bound in `collect`
+  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
+   |
+LL |     fn collect<B: FromIterator<Self::Item>>(self) -> B
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
+
+error[E0277]: a value of type `impl Debug` cannot be built from an iterator over elements of type `_`
+  --> $DIR/recursion4.rs:19:28
+   |
+LL |     x = std::iter::empty().collect();
+   |                            ^^^^^^^ value of type `impl Debug` cannot be built from `std::iter::Iterator<Item=_>`
+   |
+   = help: the trait `FromIterator<_>` is not implemented for `impl Debug`
+note: required by a bound in `collect`
+  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
+   |
+LL |     fn collect<B: FromIterator<Self::Item>>(self) -> B
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.