-
-
Notifications
You must be signed in to change notification settings - Fork 777
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
The "std" feature isn't additive #918
Comments
I believe the correct way to do no_std is an std feature, not a no_std feature, because that isn't additive? This is the other crate's fault. Wouldn't it be broken without it's own no_std anyway? |
Well serde has an We need to document this at the minimum. |
Yes. A feature adding a new public type vs one adding methods should behave the same? Features aren't aware of semantics. Could you elaborate? |
Well... adding new methods to a trait will break anyone implementing said trait for a type. Adding a new public type breaks glob imports in rare cases. |
I agree that this is implemented correctly and not something we need to fix. I opened serde-rs/serde-rs.github.io#59 to follow up on docs. |
Is this really implemented correctly? Can't there be two traints, one with common methods and another, deriving from it, that has the std-dependent ones? |
Yes really. Of the 800+ dependencies on serde in crates.io, there are 6 that depend on no_std:
The current approach is dramatically simpler in terms of total engineering effort, compared to having two Visitor traits and four Error traits and requiring practically everybody to keep them straight and implement them separately. |
Features are additive. Having a In general, if you want to use no_std, all the crates in your deptree have to be no_std compatible. It's not too much to ask for reverse dependencies to propagate no_std down because they will be doing the work anyway to be no_std compat. |
Or rather they could have never used std in the first place... |
Fair, but in that case again it's up to them to depend on the no_std version of serde if they intend the crate to be no_std. |
Yeah, I misunderstood this as "a |
Features are supposed to be additive. That means, in other words, enabling a feature should not, in general, break public API. In this case, the crate |
This is working as intended. Please send a PR if you disagree. |
If I'm understanding serde's case correctly (am I?) the core of the issue here is that code generated by serde differs depending on whether liballoc and libcollections are available. I.e. with just bare Since serde normally works on stable Rust, there are essentially two choices here:
Both of these are unsatisfying. First, while most Second, many Note that it does not matter whether the traits are split into two (say, @dtolnay Can you confirm that my understanding is correct? |
Nope, the generated code is identical with or without std. You can tell because I'm not sure how this issue came up initially (maybe @oli-obk could clarify) but I suspect it may be the |
Perhaps as a longer-term solution upstream, the |
Since |
I just followed a conversation on Irc. But it didn't have much detail. |
I was curious, just to clarify. Here's the snippet for the #[cfg(feature = "std")]
declare_error_trait!(Error: Sized + error::Error);
#[cfg(not(feature = "std"))]
declare_error_trait!(Error: Sized + Debug + Display); This makes the crate feature |
We have a crate
a
depending onserde
withdefault-features = false
set. Crateb
also depends onserde
, but doesn't enable that feature. Now if cratec
depends on botha
andb
,a
doesn't compile anymore.cc @whitequark
The text was updated successfully, but these errors were encountered: