Skip to content

Unhelpful error message "ambiguous lifetime bound, explicit lifetime bound required" #130952

Open
@oberien

Description

Code

trait MyTrait<'a, 'b> where Self: 'a + 'b {}

pub struct Foo<'a, 'b> {
    expr: Box<dyn MyTrait<'a, 'b>>,
}
// Fix:
pub struct Bar<'all, 'a, 'b> where 'all: 'a, 'all: 'b {
    expr: Box<dyn MyTrait<'a, 'b> + 'all>,
}

Current output

error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
 --> src/lib.rs:4:15
  |
4 |     expr: Box<dyn MyTrait<'a, 'b>>,
  |               ^^^^^^^^^^^^^^^^^^^

For more information about this error, try rustc --explain E0227.

Desired output

No response

Rationale and extra context

No response

Other cases

No response

Rust Version

$ rustc -Vv
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsA-trait-objectsArea: trait objects, vtable layoutD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions