-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Compiler error when trying to access function pointer in struct. #33784
Comments
It isn't a bug that you have to write However, I seem to remember rustc being helpful and giving you advice when this happens -- either that was never in place for this specific case or it has been lost. |
[citation needed] |
Fair enough. You'll admit that my version sounds better 😉 |
Well that definitely clears things up. I didn't know that you could have members and methods with the same name, that seems a bit unecessary. thanks @birkenfeld. |
@damnMeddlingKid Rust has to allow this because methods don't only come from But it's also pretty handy for having property-like accessor methods (the recommended naming is |
UFCS is not really related here - fields can't be accessed through it. Fields being in a different namespace from methods/associated items is the situation since forever, and it feels quite intentional (at least, the field-and-accessor-with-the-same-name pattern is very commonly used). |
No, it was definitely a conscious decision, but it long predates RFCs etc. There are probably some e-mails about it on the old rust-dev mailing list if you search hard enough. :) |
Yup. Given that this was a conscious decision, and not a bug, closing. |
running rustc 1.8.0 (db29394 2016-04-11).
I have a simple struct that contains a function pointer named
get_func
and when i try to access the function pointer in an implemented method i get:heres the code for reproducing
oddly enough replacing
self.get_func(self, key)
with(self.get_func)(self, key)
fixes the error, so I'm calling this a compiler bug.The text was updated successfully, but these errors were encountered: