Add some tests around recursion and "revealing"

This commit is contained in:
Oli Scherer 2022-02-17 15:42:53 +00:00
parent 1f46f771a6
commit 53c96ed528
7 changed files with 152 additions and 0 deletions

View File

@ -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() {}

View File

@ -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() {}

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.