"This generic parameter must be used with a generic lifetime parameter" on RPIT with precise capturing
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
struct Foo<'a> {
children: Vec<&'a Foo<'a>>,
}
struct Bar;
impl<'a> Foo<'a> {
fn failing<'p>(&'a self, param: &'p Bar) -> impl Iterator<Item = String> + use<'a, 'p> {
self.children.iter().flat_map(|child| child.failing(param))
}
}
I expected to see this happen:
the code compiles, since param gets used by all the children
Or, if the code actually violates ownership rules, get a clearer error message.
Instead, this happened:
compiler complains with "This generic parameter must be used with a generic lifetime parameter"
I've tried the following solutions:
- use an anonymous lifetime instead of
'p, like this:
fn failing(&'a self, param: &Bar) -> impl Iterator<Item = String> + use<'a, '_> { /* ... */ }
- make the two lifetimes the same:
fn failing(&'a self, param: &'a Bar) -> impl Iterator<Item = String> + use<'a> { /* ... */ }
And still got the same bizarre error.
Meta
rustc 1.82.0 (f6e511eec 2024-10-15) (built from a source tarball)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 18.1.8
also present on latest stable (1.83.0), beta (1.84.0-beta.6), and nightly (2025-01-05)
Backtrace
error[E0792]: expected generic lifetime parameter, found `'_`
--> src/tree.rs:656:9
|
655 | fn failing<'p>(&'a self, param: &'p Bar) -> impl Iterator<Item = String> + use<'a, 'p> {
| -- this generic parameter must be used with a generic lifetime parameter
656 | self.children.iter().flat_map(|child| child.failing(param))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 by reproducing the RPIT precise-capturing example and its E0792 diagnostic using the compiler versions listed in the issue; the reported location is src/tree.rs:656. Trace the compiler's handling of generic lifetime parameters in this case and add regression coverage. Done means the example either compiles as expected or produces a clear, correct ownership diagnostic.
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
- Mostly clear
- Newbie friendliness
- 35/100