-
-
Notifications
You must be signed in to change notification settings - Fork 465
std
feature of rand_core
changes API
#738
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It seems to me that the impl From<TimerError> for Error {
fn from(err: TimerError) -> Error {
// Timer check is already quite permissive of failures so we don't
// expect false-positive failures, i.e. any error is irrecoverable.
#[cfg(feature = "std")] {
Error::with_cause(ErrorKind::Unavailable, "timer jitter failed basic quality tests", err)
}
#[cfg(not(feature = "std"))] {
Error::new(ErrorKind::Unavailable, "timer jitter failed basic quality tests")
}
}
} |
For some reason `--all-features` causes `rand v0.5.6` to be built without `std` against a `rand-core` with `std`, which fails because of rust-random/rand#738 Just force `rand v0.5.6` to be built with `std` during docs build.
Hmm, I'm not quite sure what to do about this. We have a much simpler design for What I regret that we have two different versions of |
I don't have any usecases for this myself, I opened this issue because I have a failing build from this situation somehow occurring via my dependencies, even though I'm not directly using |
Then simpler may be better — unfortunately for you, I don't think any change here will happen soon. |
I'm in the same spot as Nemo157, w/ compilation errors in rand_jitter, from a completely different crate where I'm not even using any randomization. ¯\_(ツ)_/¯ |
Both Which version(s) of which |
How about using the following approach for new struct ErrorCode(NonZerou32);
pub struct Error {
#[cfg(not(feature="std"))]
code: ErrorCode,
#[cfg(feature="std")]
cause: Box<StdError + Send + Sync>>,
}
impl Error {
fn with_code(code: NonZerou32) -> Self {
let code = ErrorCode(code);
#[cfg(not(feature="std"))] {
Self { code }
}
#[cfg(feature="std")] {
Self { cause: Box::new(code) }
}
}
#[cfg(feature="std")]
fn with_cause(cause: Box<StdError + Send + Sync>>) {
Self { cause }
}
}
#[cfg(feature="std")]
impl StdError for ErrorCode { .. }
#[cfg(feature="std")]
impl StdError for Error { .. } @dhardy thoughts? |
Why would you box a Do we still have a reason to chain causes? I guess it might make for better error messages from Is this going to cause big issues with backwards compatibility? I guess we can deprecate the |
No, it's not a typo, with enabled I think one important use-case for boxed errors is external hardware RNGs. Plus if you unconditionally enable I don't think it will cause big issues with backwards compatibility, as I doubt that there are many users who check |
This is not a correct use of cargo features. cargo features are intended to be strictly additive; a library cannot expect that its reverse dependencies will have features turned on when it has a feature turned on. I cannot build my dependencies because of how they depend on rand. I am now investigating what I have to do to make my build work correctly, even though the code I'm writing has nothing to do with the rand_jitter crate at all. Please fix this bug; the current design is not correct and has a harmful impact on the ecosystem as a whole. |
This will be fixed in the next Rand version, but possibly not soon (it could easily be a month or two away). |
I've maybe bumped into this. It's caused by slicing the crates up too small I suppose? |
You could put it that way, or you could say that Cargo really needs whole-build feature flags. |
Specifically if you are calling
rand_core::Error::with_cause
with something that doesn't implementstd::error::Error
(because you don't directly rely onstd
) then another dependency activates therand_core/std
feature you will get a compilation error.Simplest way to see this is to use
rand
as the library that is built onrand_core
without thestd
feature, then activate thestd
feature in an empty library that depends on both:This will fail to build with the error:
The text was updated successfully, but these errors were encountered: