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

associated_type_bounds: errors with ambiguous associated type #61752

Closed
RustyYato opened this issue Jun 11, 2019 · 6 comments · Fixed by #61919
Closed

associated_type_bounds: errors with ambiguous associated type #61752

RustyYato opened this issue Jun 11, 2019 · 6 comments · Fixed by #61919
Assignees
Labels
A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. F-associated_type_bounds `#![feature(associated_type_bounds)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RustyYato
Copy link
Contributor

I think I found a bug with associated type bounds! #52662

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=28d566e7244a0b3ad21b73e31418894d

#![feature(associated_type_bounds)]

trait Foo {
    type Bar;
}

fn works<F: Foo>() where F::Bar: Copy {}

// This should be fine, but I get `error[E0221]` instead
fn breaks<F: Foo<Bar: Foo>>() where F::Bar: Copy {}

This is the exact same error you get when you do this

trait Foo<T> {
    type Bar;
}

fn breaks<F: Foo<String> + Foo<u32>>() where F::Bar: Copy {}

Because Rust can't tell which Foo::<_>::Bar you mean, but in the case of associated_type_bounds, there is no ambiguity, which makes this error confusing.

@RustyYato RustyYato changed the title Wrong Error in associated_type_bounds Incorrect error emitted in associated_type_bounds Jun 11, 2019
@Centril Centril added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2019
@Centril
Copy link
Contributor

Centril commented Jun 11, 2019

Seems like a bug indeed!

cc @alexreg @nikomatsakis

@Centril Centril added A-traits Area: Trait system A-typesystem Area: The type system labels Jun 11, 2019
@Centril
Copy link
Contributor

Centril commented Jun 11, 2019

Same error with:

fn breaks2<F>() where F: Foo<Bar: Foo>, F::Bar: Copy {}

Although the following results in the same problem:

fn breaks3_no_atb<F>() where F: Foo, Foo::Bar: Foo, F::Bar: Copy {}

so it may not be a bug after all?

@Centril Centril changed the title Incorrect error emitted in associated_type_bounds associated_type_bounds: errors with ambiguous associated type Jun 11, 2019
@RustyYato
Copy link
Contributor Author

RustyYato commented Jun 11, 2019

Ignore this, I got myself confused.

Ok, maybe just the wrong error in the desugaring? I guess this never came up because people tend to group up the bounds.

So, they would do this instead

fn breaks3_no_atb<F>() where F: Foo, Foo::Bar: Foo + Copy {}

Which works fine
edit: this should say

fn breaks3_no_atb<F>() where F: Foo, F::Bar: Foo + Copy {}

Which does work fine, but I copy pasted from Centril's comment earlier.

@Centril
Copy link
Contributor

Centril commented Jun 11, 2019

@KrishnaSannasi Oops; I wrote Foo::Bar: Foo; should be F::Bar: Foo. Sorry!

So it is a bug after all...

@alexreg
Copy link
Contributor

alexreg commented Jun 12, 2019

It's a very weird bug yes, confirmed. For now, just avoid splitting up your associated type bounds like this, but I'll try to get it fixed soon.

@alexreg
Copy link
Contributor

alexreg commented Jun 18, 2019

@KrishnaSannasi Hopefully you can see above a fix PR has been submitted now. It seems to do the job, but will need review then merge...

@Centril Centril added the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Jul 30, 2019
bors added a commit that referenced this issue Aug 7, 2019
Fix for "ambiguous associated type" issue with ATBs

Fixes #61752.

r? @nikomatsakis

CC @Centril
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. F-associated_type_bounds `#![feature(associated_type_bounds)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants