Broken Well-Formedness for HRTB in Struct Implementations
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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