intellij-rust icon indicating copy to clipboard operation
intellij-rust copied to clipboard

Good code red with associated types and generic impls

Open jendrikw opened this issue 3 years ago • 0 comments

Environment

  • IntelliJ Rust plugin version: 0.4.175.4772-222
  • Rust toolchain version: 1.62.1 (e092d0b6b 2022-07-16) x86_64-unknown-linux-gnu
  • IDE name and version: CLion 2022.2 (CL-222.3345.126)
  • Operating system: Linux 5.17.8-arch1-1
  • Macro expansion engine: new
  • Name resolution engine: new

Problem description

Good code highlighted with error.

Steps to reproduce

pub trait MyTrait: Iterator<Item = Self::Assoc> {
    type Assoc;
}

impl<I, A> MyTrait for I
where
    I: Iterator<Item = A>,
{
    type Assoc = A;
}

MyTrait on line 5 is marked red. The error message is:

The trait bound I: Iterator<Item=::Assoc> is not satisfied [E0277]. The trait Iterator<Item=::Assoc> is not implemented for I.

There is a suggestion implement supertrait which produces garbage code. Notice I isn't bound anywhere and ::Assoc is a syntax error.

impl Iterator<Item = ::Assoc> for I {
    type Item = ();

    fn next(&mut self) -> Option<Self::Item> {
        todo!()
    }
}

jendrikw avatar Aug 07 '22 19:08 jendrikw