-
Notifications
You must be signed in to change notification settings - Fork 234
Remove the various Default traits #289
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
Conversation
The Default traits and their corresponding impls interfered with upstream implementations
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ryankurte (or someone else) soon. Please see the contribution instructions for more information. |
Here is the example that I brought up in the meeting: struct GenericSpiDevice<W>(core::marker::PhantomData<W>);
impl<W> embedded_hal::blocking::spi::Write<W> for GenericSpiDevice<W> {
type Error = ();
fn write(&mut self, _: &[W]) -> Result<(), Self::Error> {
todo!()
}
}
I don't think that |
I don't understand how they can interfere. |
That took me a while to figure out too. Apparently, a downstream crate |
Just delete this impl. |
That is a hypothetical impl, it doesn't exist. The mere fact that it could exist (in a different crate) is enough for rustc to forbid |
ahh i've been caught by this before, you can avoid the problem by removing the generic over word length and implementing over concrete
in practice you usually can't do much with the generic trait as they're not object-safe so you'll basically always need to take this approach anyway, does that solve your issue? |
My earlier example is a bit contrived, what I was actually trying to do is create an adapter that takes a I could copy-paste or use a macro to impl this separately for u8 and u16, but that would mean that my adapter wouldn't work for 9-bit words for example. In my opinion there are also other good reasons to remove the default trait markers before v1.0. The way they are implemented is confusing and feels like a hack, and they only save the HALs from having to write a few lines of trivial code. |
FWIW, I'm fine with removing the default impls. As commented here and elsewhere, they add little value, can be slightly problematic as commented above and assume |
I'm in favor of removing the
|
Co-authored-by: GrantM11235 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks.
bors r+
These were removed in rust-embedded#289 but the doc comments were not updated accordingly.
322: Remove docs mentioning the Default marker traits. r=ryankurte a=Dirbaio These were removed in #289 but the doc comments were not updated accordingly. Co-authored-by: Dario Nieuwenhuis <[email protected]>
As discussed in the embedded-hal meeting, the default traits and their corresponding impls interfere with upstream implementations.