Unhelpful error message "ambiguous lifetime bound, explicit lifetime bound required"
Open
Nobody has claimed this yet.
A-diagnostics
A-dyn-trait
A-lifetimes
D-terse
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust reproduction in the issue and inspect how rustc produces error E0227 for the trait-object lifetime bounds. The issue does not specify desired wording; done means replacing the current unhelpful diagnostic with a clearer explanation of the required explicit lifetime bound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100