Skip to content

Fails to infer associated type bounds with for #57671

New issue

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

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

Already on GitHub? # to your account

Closed
jonhoo opened this issue Jan 16, 2019 · 2 comments
Closed

Fails to infer associated type bounds with for #57671

jonhoo opened this issue Jan 16, 2019 · 2 comments

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jan 16, 2019

The following code does not compile (playground):

trait Bar<T> {
    type Assoc;
}
impl<'a> Bar<&'a ()> for () {
    type Assoc = Box<Send>;
}

fn oops<C>()
where
    for<'a> C: Bar<&'a ()>,
    for<'a> <C as Bar<&'a ()>>::Assoc: Send,
{
}

fn main() {
    oops::<()>();
}

with

error[E0277]: `<() as Bar<&'a ()>>::Assoc` cannot be sent between threads safely
  --> src/lib.rs:16:5
   |
16 |     oops::<()>();
   |     ^^^^^^^^^^ `<() as Bar<&'a ()>>::Assoc` cannot be sent between threads safely
   |
   = help: the trait `for<'a> std::marker::Send` is not implemented for `<() as Bar<&'a ()>>::Assoc`
note: required by `oops`
  --> src/lib.rs:8:1
   |
8  | / fn oops<C>()
9  | | where
10 | |     for<'a> C: Bar<&'a ()>,
11 | |     for<'a> <C as Bar<&'a ()>>::Assoc: Send,
12 | | {
13 | | }
   | |_^

The issue seems to be that the for<'a> does not "carry along" the Send bound for Assoc in the impl Bar for (). This code compiles on the other hand compiles just fine:

trait Bar<T> {
    type Assoc;
}
impl<'a> Bar<&'a ()> for () {
    type Assoc = Box<Send>;
}

fn oops<'a, C>()
where
    C: Bar<&'a ()>,
    <C as Bar<&'a ()>>::Assoc: Send,
{
}

fn main() {
    oops::<()>();
}

Notice that the only change is that 'a is now a lifetime parameter of oops, which removes the need for the for<'a>. I believe the for<'a> version should also be correct though?

@sfackler
Copy link
Member

This looks like a duplicate of #56556.

@jonhoo
Copy link
Contributor Author

jonhoo commented Jan 16, 2019

@sfackler hmm, yes, I believe that's right! Closing in favor of #56556, and then posting this example code there to add a test case.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants