From 53c96ed528257489f5537c69a33b27ffce6fee6f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 17 Feb 2022 15:42:53 +0000 Subject: [PATCH] Add some tests around recursion and "revealing" --- .../lazy-type-alias-impl-trait/recursion.rs | 23 +++++++++++++++ .../lazy-type-alias-impl-trait/recursion2.rs | 21 ++++++++++++++ .../recursion2.stderr | 16 ++++++++++ .../lazy-type-alias-impl-trait/recursion3.rs | 21 ++++++++++++++ .../recursion3.stderr | 19 ++++++++++++ .../lazy-type-alias-impl-trait/recursion4.rs | 23 +++++++++++++++ .../recursion4.stderr | 29 +++++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion.rs create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion2.rs create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion3.rs create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion3.stderr create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion4.rs create mode 100644 src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr 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 = 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 = 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` + | + = 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>(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` + | + = 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>(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` + | + = 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>(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`.