Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shepmaster opened this issue Apr 30, 2018 · 5 comments
Open

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

shepmaster opened this issue Apr 30, 2018 · 5 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@shepmaster
Copy link
Member

shepmaster commented Apr 30, 2018

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)

@shepmaster shepmaster added A-trait-system Area: Trait system A-associated-items Area: Associated items (types, constants & functions) labels Apr 30, 2018
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 2, 2018
@adityashah1212
Copy link

Not sure how come, but this seems to be working on Rust Playground. I am not sure if there was something that changed recently

@shepmaster
Copy link
Member Author

The code posted in the original comment still fails in Rust 1.73 and 1.75.0-nightly (2023-10-15 42b1224), so it seems your situation is distinct.

@fmease fmease added T-types Relevant to the types team, which will review and decide on the PR/issue. A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) labels Sep 24, 2024
@fmease
Copy link
Member

fmease commented Sep 24, 2024

Might get fixed by #120752, haven't double-checked (yet).

@fmease fmease removed the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Sep 24, 2024
@compiler-errors
Copy link
Member

This is not fixed by #120752. This is just because we don't imply/elaborate arbitrary where clauses. To the trait solver, for<'a> &'a _: Trait is just a random type and doesn't really correspond to a supertrait or item bound like Self: Trait or Self::Item: Trait would.

@fmease
Copy link
Member

fmease commented Sep 25, 2024

Thanks for the correction, that makes perfect sense! I should've triaged more carefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants