Skip to content
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

Fix missing import for no_std builds #13

Merged
merged 4 commits into from
Feb 20, 2025

Conversation

ralphtandetzky
Copy link
Contributor

@ralphtandetzky ralphtandetzky commented Feb 16, 2025

  • Added a CHANGELOG.md entry

Summary

This PR fixes a missing import for no_std builds for rustc version 1.83 and older.

Motivation

When I tried to update my crate to rand 0.9.0 and rand_distr 0.5.0, my CI failed. So I needed to do something about it. What can be better than fixing the issue upstream?

Details

When rand_distr is build with --no-default-features using

rustup run "1.63.0" cargo build --no-default-features

or any other rustc version up to 1.83, the build fails in src/utils.rs in the line

let test_x = if symmetric { x.abs() } else { x };

complaining that f64 does not offer the method abs(). The added import

use num_traits::Float;

fixes this issue.

In addition, I updated .github/workflows/test.yml, so cargo build is executed for all existing test configurations. Previously, only cargo test was executed, but it looks like this is not sufficient to trigger the build failure.

This fixes issue #12.

Previously, only `cargo test` was run. Now `cargo build` with the same arguments is run before the tests. It looks like this makes a difference locally.
Before this commit, the command
```bash
rustup run "1.63.0" cargo build --no-default-features
```
failed in the line
```rust
let test_x = if symmetric { x.abs() } else { x };
```
in file `src/utils.rs` with the error that `abs()` is not a method of `f64`. This is true for all `rustc` version up to `1.83.0`. From `1.84.0` onwards, this appears to be fixed without the change. However, the change is still necessary for `no_std` builds on older versions of `rustc`.
@ralphtandetzky ralphtandetzky marked this pull request as ready for review February 16, 2025 23:10
@ralphtandetzky ralphtandetzky changed the title Add building the crate to CI. Fix missing import for no_std builds Feb 16, 2025
Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This looks good to me.

If you'd like an imminent release, please bump the version (0.5.1) and fix up the "[Unreleased]" line and I'll get this published.

@ralphtandetzky
Copy link
Contributor Author

Thanks. This looks good to me.

If you'd like an imminent release, please bump the version (0.5.1) and fix up the "[Unreleased]" line and I'll get this published.

Yes, please. I updated the version number and the [Unreleased] line.

@dhardy dhardy merged commit c5de6c7 into rust-random:master Feb 20, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants