Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0107: missing generics for struct `Foo`

What it meansAn incorrect number of generic arguments was provided.

What rustc prints

error[E0107]: missing generics for struct `Foo`
 --> main.rs:3:17
  |
3 | struct Bar { x: Foo }             // error: wrong number of type arguments:
  |                 ^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `T`
 --> main.rs:1:8
  |
1 | struct Foo<T> { x: T }
  |        ^^^ -
help: add missing generic argument
  |
3 | struct Bar { x: Foo<T> }             // error: wrong number of type arguments:
  |                    +++

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

E0107Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

An incorrect number of generic arguments was provided.

Erroneous code example:

struct Foo<T> { x: T }

struct Bar { x: Foo }             // error: wrong number of type arguments:
                                  //        expected 1, found 0
struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
                                  //        expected 1, found 2

fn foo<T, U>(x: T, y: U) {}
fn f() {}

fn main() {
    let x: bool = true;
    foo::<bool>(x);                 // error: wrong number of type arguments:
                                    //        expected 2, found 1
    foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
                                    //        expected 2, found 3
    f::<'static>();                 // error: wrong number of lifetime arguments
                                    //        expected 0, found 1
}

When using/declaring an item with generic arguments, you must provide the exact same number:

struct Foo<T> { x: T }

struct Bar<T> { x: Foo<T> }               // ok!
struct Baz<S, T> { x: Foo<S>, y: Foo<T> } // ok!

fn foo<T, U>(x: T, y: U) {}
fn f() {}

fn main() {
    let x: bool = true;
    foo::<bool, u32>(x, 12);              // ok!
    f();                                  // ok!
}

From rustc --explain E0107 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ