Skip to content

RPIT with 'static bound lifetime capture issue with generic parameter #125075

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

Closed
drdo opened this issue May 13, 2024 · 1 comment
Closed

RPIT with 'static bound lifetime capture issue with generic parameter #125075

drdo opened this issue May 13, 2024 · 1 comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@drdo
Copy link

drdo commented May 13, 2024

I tried this code:

pub fn bar(x: &str) -> impl Iterator<Item=String> + 'static {
    foo(x)
}
            
pub fn foo<A>(_arg: A) -> impl Iterator<Item=String> + 'static {
    std::iter::empty()
}

I expected to see this happen:
Successful compilation.

Instead, this happened:

error[E0700]: hidden type for `impl Iterator<Item = String> + 'static` captures lifetime that does not appear in bounds
 --> main.rs:4:5
  |
3 | pub fn bar(x: &str) -> impl Iterator<Item=String> + 'static {
  |               ----     ------------------------------------ opaque type defined here
  |               |
  |               hidden type `impl Iterator<Item = String> + 'static` captures the anonymous lifetime defined here
4 |     foo(x)
  |     ^^^^^^

error: aborting due to 1 previous error

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

The RPIT returned from foo has a 'static bound so it is unclear why there would be any complaints about
capturing a smaller lifetime (which still doesn't happen in this case as the RPIT returned from foo does not depend on _arg at all).

If the definition of foo above is changed to (by replacing the generic parameter A with &str):

pub fn foo(_arg: &str) -> impl Iterator<Item=String> + 'static {
    std::iter::empty()
}

then the code compiles without a problem.

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (ef0027897 2024-05-12)
binary: rustc
commit-hash: ef0027897d2e9014766fb47dce9ddbb925d2f540
commit-date: 2024-05-12
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4
Backtrace

<backtrace>

@drdo drdo added the C-bug Category: This is a bug. label May 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2024
@jieyouxu jieyouxu added 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. labels May 13, 2024
@fmease
Copy link
Member

fmease commented May 13, 2024

Closing as dupe of #106684 (which is probably a dupe itself).

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2024
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants