Change:
I'm writing a simple Generator that takes a reference to an RNG, and yields values from it. This makes sense as long as the generator doesn't outlive the RNG which it references. I want to name the type of the generator with an existential type, but I can't do so unless I wrap a version of the function that uses an formulation. Here's the direct version which doesn't work and here's the more convoluted version which does and here's a playground link containing both versions, as well as a bit of scaffolding The full error message I'm seeing looks like this
I don't know if this properly counts as a compiler bug, but it feels like one because the "fix" is a very mechanical code transformation.
cc
Yea that's definitely a bug. I'll investigate where this unnamed lifetime is coming from. Maybe I'm accidentally erasing lifetimes somewhere
This is fixed in master. A more minimal example that probably still failed previously (needs to be checked) that doesn't depend on or never type:

Discussion:
<ins> #![feature(type_alias_impl_trait)] type Foo = impl Fn() -> Foo; fn foo() -> Foo { foo //~ ERROR: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` } fn main() {} </ins>

<ins> error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` --> $DIR/issue-53398-cyclic-types.rs:6:5 | LL |     foo |     ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`) error: aborting due to previous error For more information about this error, try `rustc --explain E0275`. </ins>

<ins> // check-pass #![feature(generators, generator_trait)] #![feature(type_alias_impl_trait)] use std::ops::{Generator, GeneratorState}; use std::pin::Pin; type RandGenerator<'a> = impl Generator<Return = (), Yield = u64> + 'a; fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> { move || { let _rng = rng; loop { yield 0; } } } pub type RandGeneratorWithIndirection<'a> = impl Generator<Return = (), Yield = u64> + 'a; pub fn rand_generator_with_indirection<'a>(rng: &'a ()) -> RandGeneratorWithIndirection<'a> { fn helper<'b>(rng: &'b ()) -> impl 'b + Generator<Return = (), Yield = u64> { move || { let _rng = rng; loop { yield 0; } } } helper(rng) } fn main() { let mut gen = rand_generator(&()); match unsafe { Pin::new_unchecked(&mut gen) }.resume(()) { GeneratorState::Yielded(_) => {} GeneratorState::Complete(_) => {} }; } </ins>

<ins> // check-pass #![feature(type_alias_impl_trait)] trait SomeTrait {} impl SomeTrait for () {} trait MyFuture { type Output; } impl<T> MyFuture for T { type Output = T; } trait ReturnsFuture { type Output: SomeTrait; type Future: MyFuture<Output = Result<Self::Output, ()>>; fn func() -> Self::Future; } struct Foo; impl ReturnsFuture for Foo { type Output = impl SomeTrait; type Future = impl MyFuture<Output = Result<Self::Output, ()>>; fn func() -> Self::Future { Result::<(), ()>::Err(()) } } fn main() {} </ins>

<ins> #![feature(type_alias_impl_trait, generator_trait, generators)] use std::ops::Generator; trait Runnable { type Gen: Generator<Yield = (), Return = ()>; fn run(&mut self) -> Self::Gen; } struct Implementor {} impl Runnable for Implementor { type Gen = impl Generator<Yield = (), Return = ()>; fn run(&mut self) -> Self::Gen { move || { //~ ERROR: type mismatch resolving yield 1; } } } fn main() {} </ins>

<ins> error[E0271]: type mismatch resolving `<[generator@$DIR/issue-94429.rs:16:9: 18:10] as Generator>::Yield == ()` --> $DIR/issue-94429.rs:16:9 | LL | /         move || { LL | |             yield 1; LL | |         } | |_________^ expected integer, found `()` error: aborting due to previous error For more information about this error, try `rustc --explain E0271`. </ins>