-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Associated types with the same name as a function make an unimplementable trait #35600
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
Comments
I think it should be forbidden. How would you ever refer to the type and function? |
In type context |
@talchas What did you need that for? I don't see any reason to make it work. |
Someone in #rust wanted the ability to generate an associated type for fn names in a macro that generates that trait, ala impl Trait (the fn would then return that associated type, and there would be some trait bound on the type). Given the lack of any usable concat_idents, this came up as an ugly but potentially workable way to have those names, except for this. |
Huh, I guess if it's not ambiguous for normal types then this should be On Aug 12, 2016 01:18, "talchas" [email protected] wrote:
|
It would make sense if this was allowed but it seems really buggy right now. For example the following works (playpen): pub trait Foo {
type bar;
fn bar(&self) {}
}
impl Foo for char {
type bar = u8;
}
fn main() {
Foo::bar(&'a');
let _: <char as Foo>::bar = <char as Foo>::bar::max_value();
} However this fails even though all that's different is the order of items in the trait definition which I thought shouldn't matter (playpen): pub trait Foo {
fn bar(&self) {}
type bar;
}
impl Foo for char {
type bar = u8;
}
fn main() {} Also this fails (playpen): pub trait Foo {
type bar;
fn bar(&self) {}
}
impl Foo for char {
type bar = u8;
}
fn main() {
'a'.bar();
} Giving this nonsense error message:
|
CC #27048. |
is accepted (though generally considered bad style), but is unimplementable:
gives the error "item
bar
is an associated method, which doesn't match its trait<() as Foo>
"This seems kinda silly. Allowing this non-conflicting name reuse might be useful for macros as long as procedural macros don't yet exist and concat_idents is useless. Forbidding it outright seems fine, but should be done at the trait definition.
The text was updated successfully, but these errors were encountered: