Skip to content

Higher-ranked trait bounds on associated types are not elaborated #50346

Open
@shepmaster

Description

@shepmaster

This code works:

trait Boring {}

trait Usage
where
    Self::Thing: Boring,
{
    type Thing;
}

fn value_example<T: Usage>(t: T::Thing) {
    use_the_trait(t);
}

fn use_the_trait<T: Boring>(_: T) {}

fn main() {}

While this code fails:

trait Boring {}

trait Usage
where
    for<'a> &'a Self::Thing: Boring,
{
    type Thing;
}

fn ref_example<T: Usage>(t: T::Thing) {
    use_the_trait(&t);
}

fn use_the_trait<T: Boring>(_: T) {}

fn main() {}
error[E0277]: the trait bound `for<'a> &'a <T as Usage>::Thing: Boring` is not satisfied
  --> src/main.rs:10:1
   |
10 | / fn ref_example<T: Usage>(t: T::Thing) {
11 | |     use_the_trait(&t);
12 | | }
   | |_^ the trait `for<'a> Boring` is not implemented for `&'a <T as Usage>::Thing`
   |
note: required by `Usage`
  --> src/main.rs:3:1
   |
3  | / trait Usage
4  | | where
5  | |     for<'a> &'a Self::Thing: Boring,
6  | | {
7  | |     type Thing;
8  | | }
   | |_^

This is probably related to #20671, but seems slightly different from the examples posited there. Specifically, the "standard" case (the first example) does work.

Also highly relevant: #44656 and #32722.

Tested with Rust 1.25.0 and 1.27.0-nightly (2018-04-29 79252ff)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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