Skip to content

Associated types aren't normalized with impl cycles #31593

Closed

Description

@strega-nil
trait Doop {
    type Shaboom;
    fn badoowop(self) -> Self::Shaboom;
}
trait BaDoop: Doop { }

impl<T: BaDoop> Doop for T {
    type Shaboom = T;
    fn badoowop(self) -> Self {
        self
    }
}

fn main() { }

errors with

error: method `badoowop` has an incompatible type for trait: 
 expected associated type,
 found type parameter

playground

A similar issue happens when you now return Self::Shaboom:

error: mismatched types: expected `<T as Doop>::Shaboom`,
    found `T`

playground

Activity

  1. changed the title [-]Associated types aren't lowered with looped impls[/-] [+]Associated types aren't normalized with looped impls[/+] on Feb 12, 2016
  2. changed the title [-]Associated types aren't normalized with looped impls[/-] [+]Associated types aren't normalized with impl cycles[/+] on Feb 12, 2016
  3. strega-nil commented on Feb 12, 2016

    @strega-nil
    ContributorAuthor

    Honestly, it probably just needs a better error message.

  4. eddyb commented on Feb 12, 2016

    @eddyb
    Contributor

    This seems related to #29859, but not... actually working?
    AFAICT, <T as Doop> in the impl<T: Doop> of Doop for T cannot refer to the same impl.

    cc @nikomatsakis

  5. strega-nil commented on Feb 12, 2016

    @strega-nil
    ContributorAuthor

    @eddyb looks like the forest may have fixed this? #30533

  6. oli-obk commented on Jan 25, 2020

    @oli-obk
    Contributor

    The error message seems reasonable to me now as we get

    error[E0053]: method `badoowop` has an incompatible type for trait
     --> src/main.rs:9:26
      |
    3 |     fn badoowop(self) -> Self::Shaboom;
      |                          ------------- type in trait
    ...
    9 |     fn badoowop(self) -> Self {
      |                          ^^^^ expected associated type, found type parameter
      |
      = note: expected type `fn(T) -> <T as Doop>::Shaboom`
                 found type `fn(T) -> T`
      = note: you might be missing a type parameter or trait bound
    

    Please reopen if you disagree

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-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions