Closed
Description
I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f758d0536248cf9a970114bf75257429
#![feature(type_alias_impl_trait)]
type Ty<'a> = impl FnOnce() -> &'a str;
fn defining(s: &str) -> Ty<'_> { move || s }
fn execute(ty: Ty<'_>) -> &str { ty() }
I expected to see this happen: program compiles
Instead, this happened:
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
--> src/lib.rs:4:27
|
4 | fn execute(ty: Ty<'_>) -> &str { ty() }
| ^^^^
|
= note: lifetimes appearing in an associated type are not considered constrained
Same code compiles if type params are used instead:
#![feature(type_alias_impl_trait)]
type Ty<T> = impl FnOnce() -> T;
fn defining<T>(s: T) -> Ty<T> { move || s }
fn execute<T>(ty: Ty<T>) -> T { ty() }
Meta
Nightly playground : 1.62.0-nightly (2022-04-28 e85edd9)
Backtrace
<backtrace>
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done