Skip to content

feat: add support for the Rust range types, guarded by a new_range_api flag#1785

Draft
kristof-mattei wants to merge 2 commits into
rust-random:masterfrom
kristof-mattei:rust-1.96.0-new-range-api
Draft

feat: add support for the Rust range types, guarded by a new_range_api flag#1785
kristof-mattei wants to merge 2 commits into
rust-random:masterfrom
kristof-mattei:rust-1.96.0-new-range-api

Conversation

@kristof-mattei
Copy link
Copy Markdown

@kristof-mattei kristof-mattei commented May 29, 2026

Closes #1784.

@kristof-mattei kristof-mattei marked this pull request as draft May 29, 2026 17:48
Copy link
Copy Markdown
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.

I agree broadly with the approach here (also with @vks that we don't want a build.rs script for this).

Could you add some testing too? I.e. a use-case for each of the new impls as well as something like this in test.yml:

      - name: Rust >= 1.96.0
        if: ${{ matrix.variant != 'MSRV' }}
        run: |
          cargo test --target ${{ matrix.target }} --features=rust_1_96

Comment thread src/distr/uniform.rs
Comment on lines +525 to +528
// `core::range::RangeTo` is set to be a re-export of `core::ops::RangeTo`:
// > A Rust version in the near future will also add `core::range::RangeFull` and `core::range::RangeTo`
// as re-exports from `core::ops` (these do not implement `Iterator` and already implement `Copy`)
// Source: https://blog.rust-lang.org/2026/05/28/Rust-1.96.0/#new-range-types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It suffices to say that we impl SampleRange<_> for the legacy core::ops::{RangeTo, RangeFull} types for compatibility with our MSRV.

(We will presumably get a deprecation warning when updating the MSRV/edition at some point in the future.)

Comment thread Cargo.toml Outdated
Comment on lines +67 to +77
chacha20 = { version = "0.10.0", default-features = false, features = ["rng"], optional = true }
chacha20 = { version = "0.10.0", default-features = false, features = [
"rng",
], optional = true }
getrandom = { version = "0.4.0", optional = true }

[dev-dependencies]
rand_pcg = "0.10"
# Only to test serde
postcard = {version = "1.1.3", default-features = false, features = ["alloc"]}
postcard = { version = "1.1.3", default-features = false, features = ["alloc"] }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we drop the reformatting please? (Or else push it to a new PR with CI check.)

Comment thread Cargo.toml Outdated
# Deprecated option: enable logging
log = []

new_range_api = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
new_range_api = []
# Support the std::range types stabilised in Rust 1.96.0.
rust_1_96 = []

This should make it clearer that this option only exists to support features requiring a more recent Rust version than the MSRV.

@kristof-mattei kristof-mattei force-pushed the rust-1.96.0-new-range-api branch from 658b663 to 576efe2 Compare May 30, 2026 16:58
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.

Extend the impl_sample_range_u to implement the new std/core::range::Range* types.

2 participants