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

Bounds on associated types of super-traits are not implied #85978

Closed
jonhoo opened this issue Jun 3, 2021 · 1 comment
Closed

Bounds on associated types of super-traits are not implied #85978

jonhoo opened this issue Jun 3, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jun 3, 2021

Let me first qualify this with: I'm not 100% sure this is a bug — it could be that this is simply unsupported at the moment, and that it is therefore a feature request instead.

I tried this code:

trait Bar {
    type Baz;
}

trait Foo: Bar where Self::Baz: Send {}

struct X<C>(C);
impl<C> X<C> where C: Foo {}

I expected to see this happen: the code compiles.

Instead, this happened: compilation fails with

error[E0277]: `<C as Bar>::Baz` cannot be sent between threads safely
 --> src/lib.rs:8:23
  |
5 | trait Foo: Bar where Self::Baz: Send {}
  |                                 ---- required by this bound in `Foo`
...
8 | impl<C> X<C> where C: Foo {}
  |                       ^^^ `<C as Bar>::Baz` cannot be sent between threads safely
  |
  = help: the trait `Send` is not implemented for `<C as Bar>::Baz`
help: consider further restricting the associated type
  |
8 | impl<C> X<C> where C: Foo, <C as Bar>::Baz: Send {}
  |                          ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

My hope was that the C: Foo bound would imply the <C as Bar>::Baz: Send bound from Foo, but that does not appear to be the case. It does however work if no associated types are involved:

trait Bar2 {
}

trait Foo2: Bar2 where Self: Send {}

struct X2<C>(C);
impl<C> X2<C> where C: Foo2 {}

Which is what lead me to the belief that this is a bug (or at least "missing smartness").

The reason I want this construction in the first place is to construct what is effectively a trait bound alias for an impl block in my code that has a fairly hairy bound otherwise.

Meta

rustc --version --verbose:

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0

The same issue arises on nightly. I also checked 1.48.0 in case #79904 was related, but 1.48.0 also fails to compile.

@jonhoo jonhoo added the C-bug Category: This is a bug. label Jun 3, 2021
@jonas-schievink
Copy link
Contributor

This is a duplicate of #20671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants