Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"This generic parameter must be used with a generic lifetime parameter" on RPIT with precise capturing #135152

Open
ugur-a opened this issue Jan 6, 2025 · 2 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@ugur-a
Copy link

ugur-a commented Jan 6, 2025

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:

  1. use an anonymous lifetime instead of 'p, like this:
fn failing(&'a self, param: &Bar) -> impl Iterator<Item = String> + use<'a, '_> { /* ... */ }
  1. 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))
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@ugur-a ugur-a added the C-bug Category: This is a bug. label Jan 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 6, 2025
@fmease fmease added F-precise_capturing `#![feature(precise_capturing)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. and removed F-precise_capturing `#![feature(precise_capturing)]` labels Jan 6, 2025
@fmease
Copy link
Member

fmease commented Jan 6, 2025

Smaller:

//@ edition: 2021

struct Foo<'a> { children: Vec<&'a Foo<'a>> }

impl Foo<'_> {
    fn failing(&self) -> impl Iterator<Item = String> + use<'_> {
        self.children.iter().flat_map(|child| child.failing())
    }
}
//@ edition: 2024

struct Foo<'a> { children: Vec<&'a Foo<'a>> }

impl Foo<'_> {
    fn failing(&self) -> impl Iterator<Item = String> {
        self.children.iter().flat_map(|child| child.failing())
    }
}

@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jan 6, 2025
@ugur-a
Copy link
Author

ugur-a commented Jan 6, 2025

Oh okay, I though having at least one other parameter was necessary as well. If it's not, then struct Bar; isn't either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants