Skip to content

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

Closed

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

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    C-bugCategory: This is a bug.
    on Mar 8, 2019
  2. Centril commented on Mar 9, 2019

    @Centril
    Contributor

    cc @nikomatsakis, is this a lazy-norm issue?

  3. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Apr 3, 2020
  4. jonas-schievink commented on Apr 3, 2020

    @jonas-schievink
    Contributor

    This was fixed by #62221, which includes tests, so maybe this should just be closed?

  5. added a commit that references this issue on Apr 3, 2020
  6. nikomatsakis commented on Apr 3, 2020

    @nikomatsakis
    Contributor

    Closing per @jonas-schievink's comment

  7. added a commit that references this issue on Apr 3, 2020
  8. added a commit that references this issue on Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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