Skip to content

Commit 2fb42aa

Browse files
authored
fix: const generic inference for Rust 1.87 MSRV (#56)
Explicitly specify const generic parameters in _transmute calls to fix compilation errors with Rust 1.87, which does not support inference of const generics with `_`. Changes: - int/intrinsics/transmute.rs: Specify <N, M, N> and <N, M, M> explicitly - uint/intrinsics/transmute.rs: Specify <N, M, N> and <N, M, M> explicitly Add GitHub CI workflow: - Test against Rust 1.87 (MSRV) and stable versions - Lint checks (clippy, rustfmt) - Documentation build with nightly - Comprehensive feature matrix testing - MSRV verification with cargo-msrv This fixes the build error: error[E0658]: const arguments cannot yet be inferred with `_`
1 parent 5f7f025 commit 2fb42aa

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

.github/workflows/ci.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
MSRV: '1.87'
13+
14+
jobs:
15+
lint:
16+
name: Lint
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Cache Cargo registry
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.cargo/registry
26+
~/.cargo/git
27+
target
28+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
29+
restore-keys: |
30+
${{ runner.os }}-cargo-registry-
31+
- name: Install Rust toolchain via rustup
32+
run: |
33+
rustup component add clippy
34+
rustup component add rustfmt
35+
- name: Check formatting
36+
run: cargo fmt --all -- --check
37+
- name: Check linting
38+
run: cargo clippy --all-targets --all-features -- -D warnings
39+
40+
docs:
41+
name: Documentation
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 30
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: Cache Cargo registry
47+
uses: actions/cache@v4
48+
with:
49+
path: |
50+
~/.cargo/registry
51+
~/.cargo/git
52+
target
53+
key: ${{ runner.os }}-cargo-docs-${{ hashFiles('**/Cargo.toml') }}
54+
restore-keys: |
55+
${{ runner.os }}-cargo-docs-
56+
${{ runner.os }}-cargo-
57+
- name: Install Rust nightly
58+
run: rustup install nightly --profile minimal
59+
- name: Build docs
60+
run: cargo +nightly doc --all-features --no-deps
61+
env:
62+
RUSTDOCFLAGS: "--cfg docsrs -D warnings"
63+
64+
test:
65+
name: Test (${{ matrix.rust-version }})
66+
runs-on: ubuntu-latest
67+
timeout-minutes: 30
68+
strategy:
69+
matrix:
70+
rust-version: [ '1.87', 'stable' ]
71+
steps:
72+
- uses: actions/checkout@v4
73+
- name: Cache Cargo registry
74+
uses: actions/cache@v4
75+
with:
76+
path: |
77+
~/.cargo/registry
78+
~/.cargo/git
79+
target
80+
key: ${{ runner.os }}-cargo-${{ matrix.rust-version }}-${{ hashFiles('**/Cargo.toml') }}
81+
restore-keys: |
82+
${{ runner.os }}-cargo-${{ matrix.rust-version }}-
83+
${{ runner.os }}-cargo-
84+
- name: Install Rust ${{ matrix.rust-version }}
85+
run: |
86+
if [ "${{ matrix.rust-version }}" != "stable" ]; then
87+
rustup install ${{ matrix.rust-version }} --profile minimal
88+
fi
89+
- name: Build (no features)
90+
run: cargo +${{ matrix.rust-version }} build --no-default-features
91+
- name: Build (default features)
92+
run: cargo +${{ matrix.rust-version }} build
93+
- name: Build (std feature)
94+
run: cargo +${{ matrix.rust-version }} build --features std
95+
- name: Build (numtraits feature)
96+
run: cargo +${{ matrix.rust-version }} build --features numtraits
97+
- name: Build (all features)
98+
run: cargo +${{ matrix.rust-version }} build --all-features
99+
- name: Test (no features)
100+
run: cargo +${{ matrix.rust-version }} test --no-default-features
101+
- name: Test (default features)
102+
run: cargo +${{ matrix.rust-version }} test
103+
- name: Test (std feature)
104+
run: cargo +${{ matrix.rust-version }} test --features std
105+
- name: Test (numtraits feature)
106+
run: cargo +${{ matrix.rust-version }} test --features numtraits
107+
- name: Test (test-util feature for integration tests)
108+
run: cargo +${{ matrix.rust-version }} test --features test-util
109+
- name: Test docs (all features)
110+
run: cargo +${{ matrix.rust-version }} test --doc --all-features
111+
112+
check-msrv:
113+
name: Verify MSRV
114+
runs-on: ubuntu-latest
115+
steps:
116+
- uses: actions/checkout@v4
117+
- name: Install cargo-msrv
118+
run: cargo install cargo-msrv
119+
- name: Verify MSRV
120+
run: cargo msrv verify

src/bint/int/intrinsics/transmute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub const unsafe fn transmute<const N: usize, const M: usize>(v: Int<N>) -> Int<
1717
digits
1818
} else {
1919
// For positive values, initialize with zeros (existing behavior)
20-
_transmute::<_, _, N>(src_digits)
20+
_transmute::<N, M, N>(src_digits)
2121
}
2222
} else {
2323
// Narrowing conversion
2424
debug_assert!(v.last_digit_index() < M);
2525
debug_assert!(v.bits() <= Int::<M>::BITS);
26-
_transmute::<_, _, M>(src_digits)
26+
_transmute::<N, M, M>(src_digits)
2727
};
2828

2929
Int::from_digits(digits)

src/bint/uint/intrinsics/transmute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use crate::bint::{intrinsics::_transmute, UInt};
44
#[inline(always)]
55
pub const unsafe fn transmute<const N: usize, const M: usize>(v: UInt<N>) -> UInt<M> {
66
if N <= M {
7-
UInt::from_digits(_transmute::<_, _, N>(v.digits()))
7+
UInt::from_digits(_transmute::<N, M, N>(v.digits()))
88
} else {
99
debug_assert!(v.last_digit_index() < M);
1010
debug_assert!(v.bits() <= UInt::<M>::BITS);
11-
UInt::from_digits(_transmute::<_, _, M>(v.digits()))
11+
UInt::from_digits(_transmute::<N, M, M>(v.digits()))
1212
}
1313
}

0 commit comments

Comments
 (0)