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

Trouble unifying function types involving HRTB #89436

Closed
Manishearth opened this issue Oct 1, 2021 · 5 comments
Closed

Trouble unifying function types involving HRTB #89436

Manishearth opened this issue Oct 1, 2021 · 5 comments
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system

Comments

@Manishearth
Copy link
Member

Manishearth commented Oct 1, 2021

Spawned off of #84937 (comment)

Code example
trait MiniYokeable<'a> {
    type Output;
}

struct MiniYoke<Y: for<'a> MiniYokeable<'a>> {
    pub yokeable: Y,
}

fn map_project_broken<Y, P>(
    source: MiniYoke<Y>,
    f: impl for<'a> FnOnce(
        <Y as MiniYokeable<'a>>::Output,
        core::marker::PhantomData<&'a ()>,
    ) -> <P as MiniYokeable<'a>>::Output,
) -> MiniYoke<P>
where
    Y: for<'a> MiniYokeable<'a>,
    P: for<'a> MiniYokeable<'a>
{
    unimplemented!()
}

struct Bar<'a> {
    string_1: &'a str,
    string_2: &'a str,
}

impl<'a> MiniYokeable<'a> for Bar<'static> {
    type Output = Bar<'a>;
}

impl<'a> MiniYokeable<'a> for &'static str {
    type Output = &'a str;
}

fn demo_broken(bar: MiniYoke<Bar<'static>>) -> MiniYoke<&'static str> {
    map_project_broken(bar, |bar, _| bar.string_1)
}

(playpen)
throws an error of

51 |     map_project_broken(bar, |bar, _| bar.string_1)
   |     ^^^^^^^^^^^^^^^^^^      --------------------- found signature of `for<'r> fn(Bar<'r>, PhantomData<&'r ()>) -> _`
   |     |
   |     expected signature of `for<'a> fn(<Bar<'_> as MiniYokeable<'a>>::Output, PhantomData<&'a ()>) -> _`

This error is incorrect: <Bar<'_> as MiniYokeable<'a>>::Output is the same thing as Bar<'a>.

cc @sffc @jackh726

@jackh726
Copy link
Member

jackh726 commented Oct 1, 2021

I wonder if #88441 will fix this.

@Manishearth
Copy link
Member Author

@jackh726 it changes the error to

error[E0271]: type mismatch resolving `for<'a> <&str as MiniYokeable<'_>>::Output == <&str as MiniYokeable<'a>>::Output`
  --> test.rs:51:5
   |
51 |     map_project_broken(bar, |bar, _| bar.string_1)
   |     ^^^^^^^^^^^^^^^^^^ expected associated type, found `&str`
   |
   = note: expected associated type `<&str as MiniYokeable<'a>>::Output`
                    found reference `&str`
   = help: consider constraining the associated type `<&str as MiniYokeable<'a>>::Output` to `&str` or calling a method that returns `<&str as MiniYokeable<'a>>::Output`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required by a bound in `map_project_broken`
  --> test.rs:14:10
   |
9  | fn map_project_broken<Y, P>(
   |    ------------------ required by a bound in this
...
14 |     ) -> <P as MiniYokeable<'a>>::Output,
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map_project_broken`

error: aborting due to previous error

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

@jackh726
Copy link
Member

jackh726 commented Oct 1, 2021

Hmm

@aliemjay
Copy link
Member

Seems to be the same as #90875; adding type annotations fixes the problem (playground).

@Manishearth can you confirm this? You may want to close this in favor of #90875 which contains a minimal example otherwise I'm happy to close mine as a duplicate.

@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2021

@aliemjay Ah, I see. Thanks!

Dylan-DPC pushed a commit to Dylan-DPC/rust that referenced this issue Jul 15, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 15, 2022
Add regression test for rust-lang#89436

I never got around to adding such a test.

In general I think the `yoke` crate has a bunch of interesting testcases that exercise various edges of the algorithms here, it would be nice if we could simply depend on the crate and add some tests that exercise it, but I don't think that's possible. Do you or `@eddyb` think there's any use trying to upstream a bunch of common yoke minimal working example code to the testsuite and having a ton of yoke tests?
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 15, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#99113 (Simplify [a]rc code a little)
 - rust-lang#99131 (Add label for generic arg (+ APIT) and RPIT callables in `label_fn_like`)
 - rust-lang#99237 (removed unused CSS and unused HTML IDs)
 - rust-lang#99239 (Add myself to the set of people notified when MIR changes.)
 - rust-lang#99241 (Remove comment referring to constness.rs)
 - rust-lang#99257 (Add regression test for rust-lang#89436)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

3 participants