Skip to content

impl Trait with < as Trait>::Type syntax does not work in return position #59023

Closed
@mtak-

Description

@mtak-

Using the as syntax does not work as a generic to an impl Trait in return position.

trait A { type Foo; }
impl<T> A for T { type Foo = (); }

fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
    ()
}

Error

error[E0277]: the trait bound `(): std::borrow::Borrow<<u8 as A>::Foo>` is not satisfied
 --> src/lib.rs:4:13
  |
4 | fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::borrow::Borrow<<u8 as A>::Foo>` is not implemented for `()`
  |
  = help: consider adding a `where (): std::borrow::Borrow<<u8 as A>::Foo>` bound
  = note: the return type of a function must have a statically known size

As a parameter it does work:

trait A { type Foo; }
impl<T> A for T { type Foo = (); }

fn foo(p: impl std::borrow::Borrow<<u8 as A>::Foo>) {}

fn call_foo() {
    foo(())
}

This issue looks related, but specifically calls out type equality constraints. #53984

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions