rust-lang / rust-lang/rust

RPIT can't capture LUB of two lifetimes

Open
#148,401 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-impl-trait A-lifetimes C-bug needs-triage T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I'm not sure if this is a bug or not.

fn weird(x: &i32, y: &i32) -> impl Sized {
    [x, y]
}

This code doesn't compile, giving the following error.

error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
 --> src/lib.rs:2:5
  |
1 | fn weird(x: &i32, y: &i32) -> impl Sized {
  |                               ---------- opaque type defined here
2 |     [x, y]
  |     ^^^^^^
  |
  = note: hidden type `[&i32; 2]` captures lifetime `'_`

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

The return type captures the lifetime that outlives both the input lifetimes. There is not an easy way to name this lifetime. At the very least, the error is rather confusing.

Seems related to https://github.com/rust-lang/rust/issues/128752

Meta

Reproducible on the playground in version 1.93.0-nightly (2025-11-01 bd3ac0330018c23b111b)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust Playground reproduction on nightly 1.93.0 and inspect the E0700 diagnostic for the weird function. Compare the behavior and proposed scope with issue 128752; the work is complete when the behavior is classified and, if appropriate, the lifetime-capture error is made less confusing.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.