Skip to content

Commit 2ca778f

Browse files
authored
Rollup merge of #96686 - JohnTitor:impl-trait-tests, r=oli-obk
Add some TAIT-related tests Closes #53398 Closes #58662 Closes #89952 Closes #94429 r? `@oli-obk` as you're familiar with it
2 parents 731ad8a + 81a4f4b commit 2ca778f

6 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl Fn() -> Foo;
4+
5+
fn foo() -> Foo {
6+
foo //~ ERROR: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
2+
--> $DIR/issue-53398-cyclic-types.rs:6:5
3+
|
4+
LL | foo
5+
| ^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// check-pass
2+
3+
#![feature(generators, generator_trait)]
4+
#![feature(type_alias_impl_trait)]
5+
6+
use std::ops::{Generator, GeneratorState};
7+
use std::pin::Pin;
8+
9+
type RandGenerator<'a> = impl Generator<Return = (), Yield = u64> + 'a;
10+
fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> {
11+
move || {
12+
let _rng = rng;
13+
loop {
14+
yield 0;
15+
}
16+
}
17+
}
18+
19+
pub type RandGeneratorWithIndirection<'a> = impl Generator<Return = (), Yield = u64> + 'a;
20+
pub fn rand_generator_with_indirection<'a>(rng: &'a ()) -> RandGeneratorWithIndirection<'a> {
21+
fn helper<'b>(rng: &'b ()) -> impl 'b + Generator<Return = (), Yield = u64> {
22+
move || {
23+
let _rng = rng;
24+
loop {
25+
yield 0;
26+
}
27+
}
28+
}
29+
30+
helper(rng)
31+
}
32+
33+
fn main() {
34+
let mut gen = rand_generator(&());
35+
match unsafe { Pin::new_unchecked(&mut gen) }.resume(()) {
36+
GeneratorState::Yielded(_) => {}
37+
GeneratorState::Complete(_) => {}
38+
};
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait SomeTrait {}
6+
impl SomeTrait for () {}
7+
8+
trait MyFuture {
9+
type Output;
10+
}
11+
impl<T> MyFuture for T {
12+
type Output = T;
13+
}
14+
15+
trait ReturnsFuture {
16+
type Output: SomeTrait;
17+
type Future: MyFuture<Output = Result<Self::Output, ()>>;
18+
fn func() -> Self::Future;
19+
}
20+
21+
struct Foo;
22+
23+
impl ReturnsFuture for Foo {
24+
type Output = impl SomeTrait;
25+
type Future = impl MyFuture<Output = Result<Self::Output, ()>>;
26+
fn func() -> Self::Future {
27+
Result::<(), ()>::Err(())
28+
}
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(type_alias_impl_trait, generator_trait, generators)]
2+
use std::ops::Generator;
3+
4+
trait Runnable {
5+
type Gen: Generator<Yield = (), Return = ()>;
6+
7+
fn run(&mut self) -> Self::Gen;
8+
}
9+
10+
struct Implementor {}
11+
12+
impl Runnable for Implementor {
13+
type Gen = impl Generator<Yield = (), Return = ()>;
14+
15+
fn run(&mut self) -> Self::Gen {
16+
move || { //~ ERROR: type mismatch resolving
17+
yield 1;
18+
}
19+
}
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0271]: type mismatch resolving `<[generator@$DIR/issue-94429.rs:16:9: 18:10] as Generator>::Yield == ()`
2+
--> $DIR/issue-94429.rs:16:9
3+
|
4+
LL | / move || {
5+
LL | | yield 1;
6+
LL | | }
7+
| |_________^ expected integer, found `()`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)