Skip to content

RPIT can't capture LUB of two lifetimes #148401

@theemathas

Description

@theemathas

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 #128752

Meta

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions