Can't find generic in scope?

The following code does not compile and I have no idea why. I could swear I've done this before but now I'm just lost.

pub trait MyTrait { 
    fn foo();
}

pub struct ILI9486<CSX, RSX, IF> {
    interface: IF,
    chip_select: CSX,
    reset: RSX,
}

impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
where
    IF: WriteOnlyDataCommand,
    CSX: OutputPin,
    RSX: OutputPin,
{
}

The compiler tells me:

error[E0412]: cannot find type `CSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:14
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -        ^^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<CSX>`

error[E0412]: cannot find type `RSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:19
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -             ^^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<RSX>`

error[E0412]: cannot find type `IF` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:24
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -                  ^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<IF>`

error[E0412]: cannot find type `CSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:40
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -                                  ^^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<CSX>`

error[E0412]: cannot find type `RSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:45
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -                                       ^^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<RSX>`

error[E0412]: cannot find type `IF` in this scope
  --> crates/ili9486-rs/src/lib.rs:16:50
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |     -                                            ^^ not found in this scope
   |     |
   |     help: you might be missing a type parameter: `<IF>`

error[E0412]: cannot find type `IF` in this scope
  --> crates/ili9486-rs/src/lib.rs:18:5
   |
18 |     IF: WriteOnlyDataCommand,
   |     ^^ not found in this scope

error[E0412]: cannot find type `CSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:19:5
   |
19 |     CSX: OutputPin,
   |     ^^^ not found in this scope

error[E0412]: cannot find type `RSX` in this scope
  --> crates/ili9486-rs/src/lib.rs:20:5
   |
20 |     RSX: OutputPin,
   |     ^^^ not found in this scope

error[E0107]: wrong number of type arguments: expected 0, found 3
  --> crates/ili9486-rs/src/lib.rs:16:14
   |
16 | impl MyTrait<CSX, RSX, IF> for ILI9486<CSX, RSX, IF>
   |              ^^^  ^^^  ^^ unexpected type argument
   |              |    |
   |              |    unexpected type argument
   |              unexpected type argument

error: aborting due to 10 previous errors

What am I doing wrong?

You need to introduce the generic parameters with impl<CSX, RSX, IF>. (This is what the help is trying to tell you.)

They're there?

You need to put them on the impl keyword itself.

Nevermind stupid me

Ok, so now I can post my actual question, will create a new thread.

1 Like