Skip to content

Simple example of HRTB bound not resolving correctly #107699

Open
@Swire42

Description

@Swire42

I tried this code:

pub trait A {}
pub trait B where for<'a> &'a Self: A {}
pub trait C<X: B> {}
pub trait D<X: B> where for<'a> &'a X: A {}

I expected it to compile. However, while D works just fine, C produces the following error:

error[E0277]: the trait bound `for<'a> &'a X: A` is not satisfied
 --> src/lib.rs:3:16
  |
3 | pub trait C<X: B> {}
  |                ^ the trait `for<'a> A` is not implemented for `&'a X`
  |
note: required by a bound in `B`
 --> src/lib.rs:2:37
  |
2 | pub trait B where for<'a> &'a Self: A {}
  |                                     ^ required by this bound in `B`

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

This fails in all versions currently available in playground.

My original use case was requiring an operator to be implemented on references.

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 systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions