Refactor lib.rs into choice, ctoption, and traits submodules#151
Open
tarcieri wants to merge 3 commits intodalek-cryptography:developfrom
Open
Refactor lib.rs into choice, ctoption, and traits submodules#151tarcieri wants to merge 3 commits intodalek-cryptography:developfrom
lib.rs into choice, ctoption, and traits submodules#151tarcieri wants to merge 3 commits intodalek-cryptography:developfrom
Conversation
This commit is intended as the base commit for other proposed breaking
changes, almost all of which will involve bumping the MSRV close to this
(in fact if we want `const fn` support for `black_box` we need to go all
the way to 1.86, this doesn't quite do that yet).
It includes a few different changes, and I'm happy to split these up
into separate PRs if that's helpful:
- Updates CI config
- sets `permissions` to read-only
- sets `RUSTFLAGS` to `-D warnings` to deny warnings
- uses `dtolnay/rust-toolchain` instead of the unmaintained
`actions-rs/toolchain@v1`
- uses `run` directly instead of the unmaintained
`actions-rs/cargo@v1`
- removes feature-specific tests because features have been removed(!)
- adds additional `unsafe` code testing using `cargo careful` and
`cargo miri`
- tests both `dev` and `release` builds
- Bumps version to `3.0.0-pre` to denote breaking changes
- Removes obsolete `html_root_url`
- Bumps edition to 2024; note this changed rustfmt rules and so rustfmt
has also been applied with the new rules
- Bumps MSRV to 1.85.0 and adds `rust-version` setting to `Cargo.toml`
- Removes obsolete settings related to Travis CI (which has since been
replaced by GitHub Actions)
- Adds `.github` to `exclude` in `Cargo.toml`
- Bumps `rand` from `0.8` to `0.9` (though `0.10` will be released soon)
- Removes all features: with the MSRV bump, we no longer need any of
these feature gates as all features will be available (the `std`
feature didn't actually use anything from `std` and is thus pointless)
- Makes `core::hint::black_box` the only value barrier/fence strategy
for `Choice`: despite the scary documentation, it should be superior
to the previous `core::ptr::read_volatile` approach, at least based
on questions I have posed to various Rust compiler engineers, and
is also `const fn` stable in Rust 1.86.
There is a lot of functionality already in `lib.rs`. Refactoring into submodules helps you find the specific types (or traits) that you are looking for. This also refactors the tests so the relevant tests for any of the three things above can be found in a conditionally-included `tests` submodule so you don't have to change files to find the tests, and only see tests relevant to what is being defined in a particular submodule.
tarcieri
commented
Jan 4, 2026
| let y = OsRng.next_u64() as $ty; | ||
| let z = x.ct_gt(&y); | ||
|
|
||
| println!("x={}, y={}, z={:?}", x, y, z); |
Contributor
Author
There was a problem hiding this comment.
One thing I wasn't able to preserve are these useful println!s in the event of a randomized test failure, since tests in the crate itself don't have access to std.
Alternatively to this approach, I tend to use the proptest crate, and define tests like this in something like tests/proptests.rs. It handles printing out the random seed used to reproduce a particular failing test case from CI, which conveniently can go in reproductions file for all previous failing tests case, so you don't need to add separate regression tests for each previously failing proptest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a lot of functionality already in
lib.rs.Refactoring into submodules helps you find the specific types (or traits) that you are looking for.
This also refactors the tests so the relevant tests for any of the three things above can be found in a conditionally-included
testssubmodule so you don't have to change files to find the tests, and only see tests relevant to what is being defined in a particular submodule.