Email me

Rust errors / Ownership and borrowing

Rust compiler error · checked with rustc 1.99.0

Rust error E0195: lifetime parameters do not match the trait definition

What it meansThe lifetime parameters of the method do not match the trait declaration.

What rustc prints

error[E0195]: lifetime parameters do not match the trait definition
 --> main.rs:8:12
  |
8 |     fn bar<'a,'b>(x: &'a str, y: &'b str) {
  |            ^^ ^^
  |
  = note: lifetime parameters differ in whether they are early- or late-bound
note: `'a` differs between the trait and impl
 --> main.rs:2:12
  |
1 | trait Trait {
  | ----------- in this trait...
2 |     fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
  |            ^^    -- this lifetime bound makes `'a` early-bound
  |            |
  |            `'a` is early-bound
...
7 | impl Trait for Foo {
  | ------------------ in this impl...
8 |     fn bar<'a,'b>(x: &'a str, y: &'b str) {
  |            ^^ `'a` is late-bound
note: `'b` differs between the trait and impl
 --> main.rs:2:15
  |
1 | trait Trait {
  | ----------- in this trait...
2 |     fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
  |               ^^ -- this lifetime bound makes `'b` early-bound
  |               |
  |               `'b` is early-bound
...
7 | impl Trait for Foo {
  | ------------------ in this impl...
8 |     fn bar<'a,'b>(x: &'a str, y: &'b str) {
  |               ^^ `'b` is late-bound

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.

E0195Ownership and borrowing
Activein rustc 1.99.0
7related errors linked below

The compiler team's explanation

The lifetime parameters of the method do not match the trait declaration.

Erroneous code example:

trait Trait {
    fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
}

struct Foo;

impl Trait for Foo {
    fn bar<'a,'b>(x: &'a str, y: &'b str) {
    // error: lifetime parameters or bounds on method `bar`
    // do not match the trait declaration
    }
}

The lifetime constraint 'b for bar() implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example:

trait Trait {
    fn t<'a,'b:'a>(x: &'a str, y: &'b str);
}

struct Foo;

impl Trait for Foo {
    fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
    }
}

From rustc --explain E0195 (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 nextE0382: borrow of moved valueA 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