-
Notifications
You must be signed in to change notification settings - Fork 226
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
Blanket impls for &mut can cause trait methods to be preferred over inherent methods. #341
Comments
Ugh. Ugly indeed. Nice catch, though. |
StatefulOutputPin requires OutputPin, so Perhaps another option is to make StatefulOutputPin not require OutputPin, and add a blanket impl for |
fixed by #547 |
For future reference, #547 didn't fix this, and it now affects We decided that this is okay because the problem is rare and the solution is easy: replace |
I found one ugly side effect of the
&mut
blanket impls while experimenting updating stm32f4xx-hal's GPIO.it's making the trait methods take priority over the inherent methods in some cases: Dirbaio/stm32f4xx-hal@091d945#diff-a49fe1ed5910761241be27a9c10bb8e11cac30ec0a80b839278ae3a1630384bcR102
It seems to be a consequence of the autoderef rules: rust-lang/rust#26007 . It happens when you mix
&self
with&mut self
. Since the blanket impl is for&mut self
, it matches "first" before Rust tries to autoderef.I don't think this is especially bad. It might be annoying in HAL code, but non-generic end user code won't be importing the traits if they're indending to call inherent methods.
What should we do?
The text was updated successfully, but these errors were encountered: