Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impls with TAIT reject valid unconstraining lifetimes #91601

Open
aliemjay opened this issue Dec 6, 2021 · 3 comments
Open

impls with TAIT reject valid unconstraining lifetimes #91601

aliemjay opened this issue Dec 6, 2021 · 3 comments
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented Dec 6, 2021

I tried this code:

#![feature(impl_trait_in_assoc_type)]

trait Callable {
    type Out;
    fn call() -> Self::Out;
}

impl<'a> Callable for () {
    type Out = impl Sized;
    fn call() -> Self::Out {}
}

(Playground)

I expected this to compile fine since it is accepted without TAIT.

Instead, code was rejected because lifetime 'a is non-constraining.

error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
 --> src/main.rs:8:6
  |
8 | impl<'a> Callable for () {
  |      ^^ unconstrained lifetime parameter

error[E0792]: expected generic lifetime parameter, found `'_`
  --> src/main.rs:10:28
   |
8  | impl<'a> Callable for () {
   |      -- this generic parameter must be used with a generic lifetime parameter
9  |     type Out = impl Sized;
10 |     fn call() -> Self::Out {}
   |                            ^^
@aliemjay aliemjay added the C-bug Category: This is a bug. label Dec 6, 2021
@aliemjay
Copy link
Member Author

aliemjay commented Dec 6, 2021

@rustbot label F-type_alias_impl_trait T-compiler

@rustbot rustbot added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 6, 2021
@oli-obk oli-obk self-assigned this May 3, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Jul 5, 2022

fwiw, the limitation can be worked around by moving the type alias impl trait into a free type alias, which just has the generics that you want to bind.

#![feature(type_alias_impl_trait)]

trait Callable {
    type Out;
    fn call() -> Self::Out;
}

type Any = impl std::any::Any;

impl<'a> Callable for () {
    type Out = Any;
    fn call() -> Self::Out {}
}

@oli-obk oli-obk removed their assignment Sep 8, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Sep 8, 2022

Triage: not a blocker for stabilization, as workarounds exist. Definitely a bug we should fix though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Can do after stabilization
Development

No branches or pull requests

3 participants