Rust
E0049 Method Type Parameter Count Fix
E0049 is a counting error, not a type error: the compiler compares the number of type parameters - and, separately, the number of const parameters - on your impl method against the trait declaration, and the two counts differ. The parameter can be missing, extra, or sitting on the impl block where it does not count. This guide works the shapes that produce E0049, shows the repairs running, and separates the neighbors that share the same impl block but are not E0049: a lifetime mismatch, an added bound, a wrong argument type at the same count, an extra method, and a missing one.
Written November 30, 2026 · Tested with Rust 1.99.0 · 24 min read
- The rule underneath: the impl method repeats the trait method's parameters
- How to read the diagnostic
- The first failure: the impl drops the trait's parameter
- Too many parameters fails the same way
Written November 30, 2026
Tested with Rust 1.99.0
What this guide is
Error E0049 is an impl method whose generic parameter count disagrees with its trait declaration. The error codes index opens with the cause - "An attempted implementation of a trait method has the wrong number of type or const parameters" - and its erroneous example is the first failure in this guide: a trait method declared with one type parameter, implemented with none. Its stated repair direction is one sentence: "To fix this error, they must have the same type parameters".
The practical payoff is that E0049 is settled by counting, before you read anything else in the signature. In this guide's probed set, the count is checked for type parameters and for const parameters separately, in both directions - too few and too many both fail - and a parameter declared on the impl block does not count toward the method's total. Just as useful is what the count does not cover: in the probed set, a lifetime-parameter mismatch did not produce E0049 at all, an added trait bound at the same count produced E0276, and a wrong argument type at the same count produced E0053. Read the code on your diagnostic first; three of the five look-alike shapes below want a different repair than recounting.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line, and the transcripts are the programs' full compiler output, warnings included where a program earns one.
The rule underneath: the impl method repeats the trait method's parameters
A generic method's parameters belong to the method, not to the trait and not to the impl block. The Rust Reference's traits section notes that "Type parameters can be specified for a trait to make it generic" and that "Traits are implemented for specific types through separate implementations" - and a method-level parameter is a third place, declared on the method in the trait and repeated on the method in the impl. The Reference's implementations section describes the impl block's own, separate parameter list: "An implementation can take generic parameters, which can be used in the rest of the implementation. Implementation parameters are written directly after the impl keyword." Those impl-level parameters parameterize the whole impl; they are not a substitute for the method's own list, and q9 below shows the compiler treating a method parameter moved up to the impl block as a method with zero parameters.
So the trait declaration is the contract the impl method is checked against, item by item: same method name, and the same number of type parameters and const parameters declared on the method itself. The names of the parameters are not part of that contract in the probed set - f7 below implements a trait method declared with T using a parameter named U, at the same count, and it compiles and runs. The bounds are a separate axis again: dropping a bound the trait declares was accepted in the probed set (f8), while adding one the trait does not declare was E0276 (q8) - neither is E0049, because neither changes the count.
How to read the diagnostic
The E0049 header states both counts: "method get has 1 type parameter but its trait declaration has 0 type parameters". Two spans do the rest. The trait declaration's parameter list is underlined with "expected N type parameter(s)", and the impl method's parameter list is underlined with "found M type parameter(s)". For const parameters the wording swaps in the other noun: "method arr has 0 const parameters but its trait declaration has 1 const parameter". One wording variation in the probed set: a method with no receiver is called an "associated function" in the header instead of a "method" - q1 and q9 both read "associated function foo has 0 type parameters" - with the same expected/found spans. If your diagnostic's header does not state two counts, you are not looking at E0049, whatever the impl block looks like; the neighbors section below covers the headers the look-alike shapes produce instead.
The first failure: the impl drops the trait's parameter
This is the error index's own example, as a complete program - the trait declares foo with one type parameter, T: Default, and the impl writes the method with none, giving the parameter a concrete type instead:
trait Foo {
fn foo<T: Default>(x: T) -> Self;
}
struct Bar;
impl Foo for Bar {
fn foo(x: bool) -> Self { Bar }
}
fn main() {
let _b = Bar::foo(true);
}
error[E0049]: associated function `foo` has 0 type parameters but its trait declaration has 1 type parameter
--> q1.rs:8:11
|
2 | fn foo<T: Default>(x: T) -> Self;
| - expected 1 type parameter
...
8 | fn foo(x: bool) -> Self { Bar }
| ^ found 0 type parameters
warning: unused variable: `x`
--> q1.rs:8:12
|
8 | fn foo(x: bool) -> Self { Bar }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0049`.
Note what the impl tried to do: it did not just omit the parameter, it specialized the method - x: bool where the trait promises any T. That is not a shortcut the language offers for trait methods. The impl has to stay as general as the declaration, which is why the repair (f1 below) restores the parameter rather than picking a type. The unused-variable warning rides along because the stub body ignores x; it is not part of the error.
The same shape with a receiver and a concrete argument type fails identically. Here the trait method takes a generic T and the impl implements it for u32 only:
trait Convert {
fn convert<T>(&self, x: T) -> u32;
}
struct Bar;
impl Convert for Bar {
fn convert(&self, x: u32) -> u32 { x }
}
fn main() {
let b = Bar;
println!("{}", b.convert(7u32));
}
error[E0049]: method `convert` has 0 type parameters but its trait declaration has 1 type parameter
--> q4.rs:8:15
|
2 | fn convert<T>(&self, x: T) -> u32;
| - expected 1 type parameter
...
8 | fn convert(&self, x: u32) -> u32 { x }
| ^ found 0 type parameters
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
If you want a method that works on one concrete type, that method belongs in the trait declared with that concrete type - or not in a trait at all. Inside a trait impl, the declaration's generality is fixed.
Too many parameters fails the same way
The count is an equality, not a minimum. An impl method with two type parameters where the trait declares none is E0049 with the counts reversed:
trait Foo {
fn foo(&self, x: bool) -> bool;
}
struct Bar;
impl Foo for Bar {
fn foo<T, U>(&self, x: bool) -> bool { x }
}
fn main() {
let b = Bar;
println!("{}", b.foo(true));
}
error[E0049]: method `foo` has 2 type parameters but its trait declaration has 0 type parameters
--> q2.rs:8:12
|
2 | fn foo(&self, x: bool) -> bool;
| - expected 0 type parameters
...
8 | fn foo<T, U>(&self, x: bool) -> bool { x }
| ^ ^
| |
| found 2 type parameters
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
The common real-world version of this direction is smaller: one extra parameter where the trait has none at all. A plain getter that grew a <T> in the impl - copied from a generic method nearby, or left over from a refactor - is E0049 at 1 against 0:
trait Getter {
fn get(&self) -> u32;
}
struct Bar;
impl Getter for Bar {
fn get<T>(&self) -> u32 { 42 }
}
fn main() {
let b = Bar;
println!("{}", b.get());
}
error[E0049]: method `get` has 1 type parameter but its trait declaration has 0 type parameters
--> q3.rs:8:12
|
2 | fn get(&self) -> u32;
| - expected 0 type parameters
...
8 | fn get<T>(&self) -> u32 { 42 }
| ^ found 1 type parameter
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
And a partial match is still a mismatch. Two parameters declared, one repeated - with the second argument folded into the first parameter's type - is E0049 at 1 against 2:
trait Pair {
fn pair<T, U>(&self, t: T, u: U) -> u32;
}
struct Bar;
impl Pair for Bar {
fn pair<T>(&self, t: T, u: T) -> u32 {
let _ = (&t, &u);
0
}
}
fn main() {
let b = Bar;
println!("{}", b.pair(1, 2));
}
error[E0049]: method `pair` has 1 type parameter but its trait declaration has 2 type parameters
--> q5.rs:8:13
|
2 | fn pair<T, U>(&self, t: T, u: U) -> u32;
| - -
| |
| expected 2 type parameters
...
8 | fn pair<T>(&self, t: T, u: T) -> u32 {
| ^ found 1 type parameter
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
There is no merging parameters in an impl: if two type parameters in the trait sometimes hold the same type at a call site, that sameness is the caller's choice, expressed by passing the same type twice - the impl still declares both.
Const parameters are counted separately
The index's opening sentence says "type or const parameters", and the probed set confirms const parameters get their own count and their own wording. A trait method with a const parameter, implemented with the size written as a literal instead, is E0049 in the const form:
trait Arr {
fn arr<const N: usize>(&self) -> [u8; N];
}
struct Bar;
impl Arr for Bar {
fn arr(&self) -> [u8; 3] { [0; 3] }
}
fn main() {
let b = Bar;
println!("{:?}", b.arr::<3>());
}
error[E0049]: method `arr` has 0 const parameters but its trait declaration has 1 const parameter
--> q7.rs:8:11
|
2 | fn arr<const N: usize>(&self) -> [u8; N];
| -------------- expected 1 const parameter
...
8 | fn arr(&self) -> [u8; 3] { [0; 3] }
| ^ found 0 const parameters
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
Writing [u8; 3] in the impl is the same specialization move as x: bool in q1, and it fails for the same reason: the declaration promised the caller the choice of N. The other direction fails too - an extra const parameter the trait does not declare is E0049 at 2 against 1:
trait Arr {
fn arr<const N: usize>(&self) -> [u8; N];
}
struct Bar;
impl Arr for Bar {
fn arr<const N: usize, const M: usize>(&self) -> [u8; N] { [7; N] }
}
fn main() {
let b = Bar;
println!("{:?}", b.arr::<3>());
}
error[E0049]: method `arr` has 2 const parameters but its trait declaration has 1 const parameter
--> q10.rs:8:12
|
2 | fn arr<const N: usize>(&self) -> [u8; N];
| -------------- expected 1 const parameter
...
8 | fn arr<const N: usize, const M: usize>(&self) -> [u8; N] { [7; N] }
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
| |
| found 2 const parameters
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
So the count check runs per kind in the probed set: type parameters against type parameters, const parameters against const parameters, each stated in its own header wording. A method that is short one type parameter and one const parameter is two mismatches, not one combined count.
The traps: neighbors that are not E0049
A lifetime-parameter mismatch is not E0049 in the probed set. The trait declares an explicit lifetime tying the argument to the return value; the impl writes the method with elided lifetimes, which elision resolves differently - the return value takes the receiver's lifetime, not the argument's. The compiler reports an unnumbered signature mismatch, then a lifetime error - no E0049 anywhere in the output:
trait Echo {
fn echo<'a>(&self, x: &'a str) -> &'a str;
}
struct Bar;
impl Echo for Bar {
fn echo(&self, x: &str) -> &str { x }
}
fn main() {
let b = Bar;
println!("{}", b.echo("hi"));
}
error: `impl` item signature doesn't match `trait` item signature
--> q6.rs:8:5
|
2 | fn echo<'a>(&self, x: &'a str) -> &'a str;
| ------------------------------------------ expected `fn(&'1 Bar, &'a str) -> &'a str`
...
8 | fn echo(&self, x: &str) -> &str { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Bar, &'2 str) -> &'1 str`
|
= note: expected signature `fn(&'1 Bar, &'a str) -> &'a str`
found signature `fn(&'1 Bar, &'2 str) -> &'1 str`
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
error: lifetime may not live long enough
--> q6.rs:8:39
|
8 | fn echo(&self, x: &str) -> &str { x }
| - - ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
| | |
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
help: consider introducing a named lifetime parameter and update trait if needed
|
8 | fn echo<'a>(&self, x: &'a str) -> &'a str { x }
| ++++ ++ ++
error: aborting due to 2 previous errors
So do not generalize the index's "type or const parameters" to lifetimes: in the probed set, lifetimes are checked as part of the signature, not counted, and the repair is to write the declared lifetime relationships explicitly in the impl - f6 below is this program with the trait's <'a> repeated, compiling and running. If your error has no code and talks about signatures and lifetimes, recounting type parameters will not touch it.
A parameter on the impl block is not a parameter on the method. Moving the trait method's T up to the impl - a natural move if you are used to impl-level generics - leaves the method itself with zero parameters, and the compiler says so, alongside two further errors the misplaced parameter causes: the impl-level T constrains nothing (E0207), and the call site cannot infer it (E0282). The full output:
trait Foo {
fn foo<T>(x: T) -> u32;
}
struct Bar;
impl<T> Foo for Bar {
fn foo(x: T) -> u32 { 0 }
}
fn main() {
println!("{}", Bar::foo(5u32));
}
error[E0049]: associated function `foo` has 0 type parameters but its trait declaration has 1 type parameter
--> q9.rs:8:11
|
2 | fn foo<T>(x: T) -> u32;
| - expected 1 type parameter
...
8 | fn foo(x: T) -> u32 { 0 }
| ^ found 0 type parameters
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> q9.rs:7:6
|
7 | impl<T> Foo for Bar {
| ^ unconstrained type parameter
|
help: use the type parameter `T` in the `Bar` type and use it in the type definition
|
5 ~ struct Bar<T>;
6 |
7 ~ impl<T> Foo for Bar<T> {
|
error[E0282]: type annotations needed
--> q9.rs:12:20
|
12 | println!("{}", Bar::foo(5u32));
| ^^^ cannot infer type for type parameter `T`
warning: unused variable: `x`
--> q9.rs:8:12
|
8 | fn foo(x: T) -> u32 { 0 }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 3 previous errors; 1 warning emitted
Some errors have detailed explanations: E0049, E0207, E0282.
For more information about an error, try `rustc --explain E0049`.
The E0049 line is the one to fix first: put the parameter back on the method. The E0207 and E0282 errors are downstream of the same misplacement in this program - the impl-level T has nothing to attach to - and they go away with it, as the matching-count programs in the fixes section show. This is also the shape to suspect when E0049 arrives in a cluster: a lone E0049 is a miscounted method, an E0049 with E0207 beside it is a parameter on the wrong line.
An added bound at the same count is E0276, "impl has stricter requirements than trait". The counts match here - one type parameter on each side - but the impl narrows the parameter with a bound the trait does not declare:
trait Foo {
fn foo<T>(x: T) -> u32;
}
struct Bar;
impl Foo for Bar {
fn foo<T: Default>(x: T) -> u32 { 0 }
}
fn main() {
println!("{}", Bar::foo(5));
}
error[E0276]: impl has stricter requirements than trait
--> q8.rs:8:15
|
2 | fn foo<T>(x: T) -> u32;
| ----------------------- definition of `foo` from trait
...
8 | fn foo<T: Default>(x: T) -> u32 { 0 }
| ^^^^^^^ impl has extra requirement `T: Default`
warning: unused variable: `x`
--> q8.rs:8:24
|
8 | fn foo<T: Default>(x: T) -> u32 { 0 }
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0276`.
The asymmetry matters for repairs: the impl may not demand more than the trait promises callers, but it may demand less - f8 below drops the trait's bound in the impl and runs. If your body needs the bound, the bound belongs in the trait declaration, where q1's T: Default sits, not added at the impl.
A wrong argument type at the same count is E0053, "method foo has an incompatible type for trait". Both sides declare one type parameter here; what differs is where the parameter is used - Vec<T> in the impl where the trait has the bare T:
trait Foo {
fn foo<T>(x: T) -> T;
}
struct Bar;
impl Foo for Bar {
fn foo<T>(x: Vec<T>) -> Vec<T> { x }
}
fn main() {
println!("{:?}", Bar::foo(vec![1, 2]));
}
error[E0053]: method `foo` has an incompatible type for trait
--> n3.rs:8:18
|
8 | fn foo<T>(x: Vec<T>) -> Vec<T> { x }
| - ^^^^^^ expected type parameter `T`, found `Vec<T>`
| |
| expected this type parameter
|
note: type in trait
--> n3.rs:2:18
|
2 | fn foo<T>(x: T) -> T;
| ^
= note: expected signature `fn(T) -> T`
found signature `fn(Vec<T>) -> Vec<T>`
help: change the parameter type to match the trait
|
8 - fn foo<T>(x: Vec<T>) -> Vec<T> { x }
8 + fn foo<T>(x: T) -> Vec<T> { x }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0053`.
The split between E0049 and E0053 in the probed set is exactly count versus use: declare a different number of parameters and it is E0049; declare the same number and use them in different types and it is E0053. (The compiler's suggested edit in this transcript fixes the argument type only and would leave the return type mismatched - follow the note's expected signature, not the one-line help, if you hit this shape.)
The last two neighbors are about which methods exist, not their parameters. An extra method in the impl - one the trait does not declare - is E0407, "method extra is not a member of trait Foo":
trait Foo {
fn foo(&self) -> u32;
}
struct Bar;
impl Foo for Bar {
fn foo(&self) -> u32 { 1 }
fn extra(&self) -> u32 { 2 }
}
fn main() {
let b = Bar;
println!("{}", b.foo());
}
error[E0407]: method `extra` is not a member of trait `Foo`
--> n1.rs:9:5
|
9 | fn extra(&self) -> u32 { 2 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Foo`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0407`.
Extra items belong in an inherent impl for the type, or in the trait declaration - and the type-level version of this mistake, an associated type the trait does not declare, is a different code again, covered in the E0437 guide. And a declared method missing from the impl entirely is E0046, "not all trait items implemented" - the subject of the E0046 guide, reproduced here only to draw the line:
trait Foo {
fn foo(&self) -> u32;
fn bar(&self) -> u32;
}
struct Bar;
impl Foo for Bar {
fn foo(&self) -> u32 { 1 }
}
fn main() {
let b = Bar;
println!("{}", b.foo());
}
error[E0046]: not all trait items implemented, missing: `bar`
--> n2.rs:8:1
|
3 | fn bar(&self) -> u32;
| --------------------- `bar` from trait
...
8 | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^ missing `bar` in implementation
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0046`.
Fixes in reach order
First, repeat the trait declaration's parameter list on the impl method - count, kind, and bounds. The index's own fix for the first failure restores T: Default to the impl method, and the program compiles and runs:
trait Foo {
fn foo<T: Default>(x: T) -> Self;
}
struct Bar;
impl Foo for Bar {
fn foo<T: Default>(x: T) -> Self {
let _ = x;
Bar
}
}
fn main() {
let _b = Bar::foo(5u32);
println!("ok");
}
ok
The output is ok - the call Bar::foo(5u32) type-checks against the restored generic method. Note the bound travels with the parameter: the trait's T: Default is repeated as T: Default, matching the declaration exactly.
Second, delete parameters the trait does not declare. The two-extra-parameters program, with the impl method's list emptied to match the trait, compiles and runs:
trait Foo {
fn foo(&self, x: bool) -> bool;
}
struct Bar;
impl Foo for Bar {
fn foo(&self, x: bool) -> bool { x }
}
fn main() {
let b = Bar;
println!("{}", b.foo(true));
}
true
The output is true, the argument passed through. The one-extra-parameter getter is the same repair at 1 against 0 - drop the <T>:
trait Getter {
fn get(&self) -> u32;
}
struct Bar;
impl Getter for Bar {
fn get(&self) -> u32 { 42 }
}
fn main() {
let b = Bar;
println!("{}", b.get());
}
42
The output is 42. If the dropped parameter was doing real work - the method genuinely needs to be generic - the fix runs the other way: add the parameter to the trait declaration, and every impl of that trait picks it up.
Third, match a multi-parameter declaration in full, bounds included. The two-parameter trait, with its bounds declared in the trait and repeated in the impl, compiles and runs:
trait Pair {
fn pair<T: std::fmt::Display, U: std::fmt::Display>(&self, t: T, u: U) -> String;
}
struct Bar;
impl Pair for Bar {
fn pair<T: std::fmt::Display, U: std::fmt::Display>(&self, t: T, u: U) -> String {
format!("{}-{}", t, u)
}
}
fn main() {
let b = Bar;
println!("{}", b.pair(1, "x"));
}
1-x
The output is 1-x - the two arguments formatted together. The bounds sit in the trait declaration here, which is the only place they can be added: putting them only in the impl is the E0276 shape from q8, and putting them only in a where clause on the impl side fails the same way in the probed set's first attempt at this program.
Fourth, give a const-parameter method its const parameter back. The array method with <const N: usize> repeated in the impl compiles and runs, and the caller picks the size:
trait Arr {
fn arr<const N: usize>(&self) -> [u8; N];
}
struct Bar;
impl Arr for Bar {
fn arr<const N: usize>(&self) -> [u8; N] { [7; N] }
}
fn main() {
let b = Bar;
let a = b.arr::<4>();
println!("{} {:?}", a.len(), a);
}
4 [7, 7, 7, 7]
The output is 4 [7, 7, 7, 7] - length 4, chosen by the caller's arr::<4>(), with every element the impl's 7. That caller-chosen size is exactly what the [u8; 3] specialization in q7 was trying to take away.
Fifth, for the lifetime neighbor, write the declared lifetimes explicitly. The echo method with the trait's <'a> and its two uses repeated in the impl compiles and runs:
trait Echo {
fn echo<'a>(&self, x: &'a str) -> &'a str;
}
struct Bar;
impl Echo for Bar {
fn echo<'a>(&self, x: &'a str) -> &'a str { x }
}
fn main() {
let b = Bar;
println!("{}", b.echo("hi"));
}
hi
The output is hi, the argument returned. Elision is what broke q6 - left to elision, the impl's return value took the receiver's lifetime - so where the trait names a lifetime, the impl names it too, in the same places.
Last, two things you do not need to match. The parameter's name is free: this impl renames the trait's T to U, at the same count, and compiles and runs:
trait Foo {
fn foo<T>(x: T) -> u32;
}
struct Bar;
impl Foo for Bar {
fn foo<U>(x: U) -> u32 { 9 }
}
fn main() {
println!("{}", Bar::foo("anything"));
}
9
The output is 9, and the call passes a &str - the renamed parameter is still fully generic. Compiling this program also warns that x is unused, since the body returns a constant; the block above is the run output only. And the impl may drop a bound the trait declares: this impl repeats the count but not the Default bound, and compiles and runs, because the body never uses it:
trait Val {
fn val<T: Default>(&self) -> u32;
}
struct Bar;
impl Val for Bar {
fn val<T>(&self) -> u32 { 3 }
}
fn main() {
let b = Bar;
println!("{}", b.val::<u32>());
}
3
The output is 3. Dropping a bound widens what the impl accepts, which never breaks the trait's promise to callers; adding one narrows it, which is why only the adding direction is an error (E0276, in q8). Match the count exactly; match the bounds by not exceeding the declaration.
Decision summary
E0049, "has N type parameters but its trait declaration has M type parameters" - or the same sentence with "const parameters" - is one shape in this guide's probed set: an impl method whose type-parameter count, or whose const-parameter count, differs from the trait declaration's, in either direction. It covers the impl dropping a parameter to specialize the method (0 against 1, including the concrete-argument form), adding parameters the trait does not have (1 or 2 against 0), merging two declared parameters into one (1 against 2), specializing a const parameter into a literal (0 const against 1), adding an extra const parameter (2 const against 1), and declaring the parameter on the impl block instead of the method (0 against 1, with E0207 and E0282 alongside). The diagnostic states both counts and underlines both parameter lists with "expected" and "found". The repair is always on the method's own parameter list: repeat the declaration's count and kind, with its bounds, or change the trait declaration if the method's generality is what is actually wrong. The neighbors are distinct in the probed set: a lifetime mismatch is an unnumbered signature error plus a lifetime error, an added bound at the same count is E0276, a wrong argument type at the same count is E0053, an extra method is E0407, and a missing method is E0046. Parameter names need not match, and dropping a declared bound in the impl is accepted when the body does not use it.
Checklist
- Count first: in the probed set, E0049 is a difference in the number of type parameters, or separately in the number of const parameters, between the impl method and the trait declaration - in either direction.
- Check where the parameter sits: in the probed set, a parameter on the impl block does not count toward the method, and it arrives with E0207 beside the E0049.
- Do not specialize in the impl: in the probed set, replacing a type parameter with a concrete type, or a const parameter with a literal, is the 0-against-1 form of this error.
- Do not merge parameters: in the probed set, two declared parameters folded into one is still a mismatch - the caller expresses sameness by passing the same type twice.
- Lifetimes are not counted here: in the probed set, a lifetime mismatch produced an unnumbered signature error, and the repair was repeating the declared lifetime explicitly.
- Bounds are a different axis: in the probed set, adding a bound in the impl was E0276 and dropping one was accepted - if the body needs a bound, declare it in the trait.
- Names are free: in the probed set, renaming a parameter in the impl at the same count compiled and ran.
Related guides on this site
- E0091 Unused Type Parameter Fix
- E0210 Type Parameter Orphan Rule Fix
- E0310 Type May Not Live Long Enough Fix
- E0207 Unconstrained Type Parameter Fix
Sources
- Rust error codes index, E0049 - an attempted implementation of a trait method has the wrong number of type or const parameters; the erroneous example with the trait method
foo<T: Default>implemented without the parameter forBar; the note that the trait has a methodfoowith a type parameterTbut the implementation forBaris missing this parameter; the fix example repeating the parameter so both sides have the same type parameters. - The Rust Reference, Traits - type parameters can be specified for a trait to make it generic, appearing after the trait name with the same syntax used in generic functions; all traits define an implicit type parameter
Self; traits are implemented for specific types through separate implementations. - The Rust Reference, Implementations - a trait implementation is defined like an inherent implementation except that the generic declarations are followed by the trait and the implementing type; an implementation can take generic parameters, which can be used in the rest of the implementation, written directly after the
implkeyword; type and const parameters must always constrain the implementation.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.