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

ICE when using a trait with an associated type as a trait object #19121

Closed
nrc opened this issue Nov 19, 2014 · 6 comments · Fixed by #19478
Closed

ICE when using a trait with an associated type as a trait object #19121

nrc opened this issue Nov 19, 2014 · 6 comments · Fixed by #19478
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nrc
Copy link
Member

nrc commented Nov 19, 2014

#![feature(associated_types)]

trait Foo {
    type A;
}

fn bar(x: &Foo) {}

pub fn main() {
}
@nrc nrc self-assigned this Nov 19, 2014
@nrc
Copy link
Member Author

nrc commented Nov 19, 2014

cc @nikomatsakis @aturon

The best thing to do here is to use &Foo<A=Baz> (#18432). Is the correct behaviour when using &Foo to treat A as an unbounded type variable or to cause an error because &Foo is not well-specified?

@nrc
Copy link
Member Author

nrc commented Nov 19, 2014

My reading of the RFC is that it should be a compile error to use &Foo - all associated types in an object must be bound in the type (it is unclear from the RFC if having a default type for the associated type means we don't need an equality constraint for that type).

@nrc
Copy link
Member Author

nrc commented Nov 19, 2014

#17732 is very similar, but not quite a dup, the error message here is find_associated_type_in_generics(): no self type (which is wrong - it is not a self type issue).

@aturon
Copy link
Member

aturon commented Nov 20, 2014

My reading of the RFC is that it should be a compile error to use &Foo - all associated types in an object must be bound in the type (it is unclear from the RFC if having a default type for the associated type means we don't need an equality constraint for that type).

Yes in general. I think it's fine to allow you to leave it off if there's a default.

@huonw huonw added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-associated-items Area: Associated items (types, constants & functions) labels Nov 20, 2014
@nikomatsakis
Copy link
Contributor

I agree it should be a compile-time error to have an object type for which the values of some associated types are not specified (whether explicitly or via default). However, we have to be careful, because there can be a default that references Self (which is erased). We should catch this and report a nice error. See #18956, which is related.

@nrc
Copy link
Member Author

nrc commented Dec 2, 2014

The ICE is fixed by #19391

nrc added a commit to nrc/rust that referenced this issue Dec 2, 2014
@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 12, 2014
nrc added a commit to nrc/rust that referenced this issue Dec 16, 2014
bors added a commit that referenced this issue Dec 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants