rust-lang / rust-lang/rust

Broken Well-Formedness for HRTB in Struct Implementations

Open
#155,875 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-higher-ranked A-trait-system C-bug needs-triage T-types
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I tried this code:

trait Trait<'x> {
    type Output;
}

struct Struct<G>(G);

impl<'a, G> Struct<G>
where
    G: Trait<'a>,
{
    fn foo(f: impl for<'life> std::convert::AsRef<<G as Trait<'life>>::Output>) {}
}

I expected to see this happen: Compilation error due to G not bounded with for<'life>.

Instead, this happened: Successful compilation.

Meta

rustc --version --verbose:

1.97.0-nightly
(2026-04-26 ca9a134e0985765ded9c)
Backtrace

Irrelevant

I failed to create an unsound example, though, because the only trait I could use inside foo() was still Trait<'a>.

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 by compiling the provided HRTB struct-implementation snippet with rustc 1.97.0-nightly and confirm that it currently succeeds. Trace the well-formedness checking for the impl and its higher-ranked bound; done means the example is rejected for lacking the required for<'life> bound, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.