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

Type parameter bounded as associated type does not inherit associated type bounds #86284

Closed
sharnoff opened this issue Jun 14, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@sharnoff
Copy link
Contributor

sharnoff commented Jun 14, 2021

My apologies in advance if this is a duplicate or a known limitation. I spent a long while looking and it appears to be similar to #24159 (resolved by #81671), but not quite the same (and this behavior is still present).

Rustc version

Both current stable (1.52.1) and nightly (1.55.0-nightly (2021-06-12 24bdc6d)) fail to compile the following code.

Minimal example

(playground link)

trait Foo {
    // There isn't anything special about `Clone` here; it just happens to be
    // a trait we can bound this by.
    type Bar: Clone;
}

// Because `<F as Foo>::Bar = B`, and `Foo::Bar: Clone`, we'd expect that this
// also requires `B: Clone`.
fn do_thing<F, B>(bar: B) where F: Foo<Bar = B> {
    // rustc says that `B` does not implement clone, so there is no `.clone()`
    // method we can call here.
    bar.clone();
}

I used a function to create the bound conflict here, but it works in a variety of other contexts as well -- I first noticed it in an impl block with the call to clone in one of the methods.

Essentially, the issue seems to be that the compiler is failing to make the following deduction:

trait Foo with Foo::Bar: MyTrait and T: Foo<Bar = B> implies B: MyTrait

If there's anything I can do, I'm happy to help where possible.

@sharnoff sharnoff added the C-bug Category: This is a bug. label Jun 14, 2021
@sharnoff sharnoff changed the title Type parameters bounded by associated type equality do not inherit associated type bounds Type parameter bounded as associated type does not inherit associated type bounds Jun 14, 2021
@jonas-schievink
Copy link
Contributor

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