Skip to content

Types inside higher-ranked binders sometimes aren't checked for WF. #152467

@theemathas

Description

@theemathas

The following code errors

trait Trait: 'static {}

fn wut()
where
    for<'a> dyn Trait + 'a + Send:,
{
}

fn main() {
    wut();
}
error: higher-ranked lifetime error
  --> src/main.rs:10:5
   |
10 |     wut();
   |     ^^^^^
   |
   = note: could not prove `for<'a> (dyn Trait + Send + 'a) well-formed`

However, adding a Send bound makes it compile for some reason.

trait Trait: 'static {}

fn wut()
where
    for<'a> dyn Trait + 'a + Send: Send,
{
}

fn main() {
    wut();
}

This seems incorrect.

Also, here's a variant that makes rust produce an error mentioning #100013:

trait Trait<'b>: 'b {}

fn wut()
where
    for<'a, 'b> dyn Trait<'b> + 'a + Send:,
{
}

fn main() {
    wut();
}
error: lifetime bound not satisfied
  --> src/main.rs:10:5
   |
10 |     wut();
   |     ^^^^^
   |
note: the lifetime `'b` defined here...
  --> src/main.rs:5:13
   |
 5 |     for<'a, 'b> dyn Trait<'b> + 'a + Send:,
   |             ^^
note: ...must outlive the lifetime `'a` defined here
  --> src/main.rs:5:9
   |
 5 |     for<'a, 'b> dyn Trait<'b> + 'a + Send:,
   |         ^^
   = note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)

Again, adding a Send bound makes it compile.

trait Trait<'b>: 'b {}

fn wut()
where
    for<'a, 'b> dyn Trait<'b> + 'a + Send: Send,
{
}

fn main() {
    wut();
}

cc @lcnr

Meta

Reproducible on the playground with version 1.95.0-nightly (2026-02-09 18d13b5332916ffca8ea)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions