Skip to content

Commit 05aee0f

Browse files
authored
Merge pull request #42 from ruma/max/fix-msrv
Fix MSRV of the macros to actually be 1.46
2 parents f60e181 + d09ef37 commit 05aee0f

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

.github/workflows/msrv.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ on:
88

99
jobs:
1010
check:
11-
name: Check
11+
name: Test
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: dtolnay/rust-toolchain@1.46
16-
- name: Check (no default features)
17-
run: cargo check --no-default-features
18-
- name: Check (default features)
19-
run: cargo check
20-
- name: Check (serde)
21-
run: cargo check --features serde
22-
- name: Check (all features)
23-
run: cargo check --all-features
16+
- name: Run tests (no default features)
17+
run: cargo test --no-default-features
18+
- name: Run tests (default features)
19+
run: cargo test
20+
- name: Run tests (serde)
21+
run: cargo test --features serde
22+
- name: Run tests (all features)
23+
run: cargo test --all-features
24+
- name: Run tests (release build)
25+
run: cargo test --release

.github/workflows/stable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
check:
11-
name: Check
11+
name: Test
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ readme = "README.md"
88
repository = "https://github.com/ruma/js_int"
99
keywords = ["integer", "no_std"]
1010
categories = ["no-std"]
11+
rust-version = "1.46.0"
1112

1213
[dependencies.serde]
1314
version = "1.0"

src/macros.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ macro_rules! int {
55
($n:expr) => {{
66
const VALUE: $crate::Int = match $crate::Int::new($n) {
77
Some(int) => int,
8-
None => panic!("Number is outside the range of an Int"),
8+
None => {
9+
// Hack to emulate a panic in this case.
10+
// Inspired by the [`static_assertions`](https://github.com/nvzqz/static-assertions) package.
11+
// Improvements to be made with higher MSRVs:
12+
// * 1.48: Replace the number comparison with `Option::is_none`
13+
// * 1.57: Use `panic!()` directly.
14+
// * 1.83: Replace manual `panic!()` with `Option::expect`
15+
const _: [(); 0 - !{
16+
const ASSERT: bool = $n >= $crate::MIN_SAFE_INT && $n <= $crate::MAX_SAFE_INT;
17+
ASSERT
18+
} as usize] = [];
19+
// This loop should not run, but it produces a never type that keeps the match
20+
// arms having the same type (since never conforms to any type)
21+
loop {}
22+
}
923
};
1024
VALUE
1125
}};
@@ -18,7 +32,22 @@ macro_rules! uint {
1832
($n:expr) => {{
1933
const VALUE: $crate::UInt = match $crate::UInt::new($n) {
2034
Some(int) => int,
21-
None => panic!("Number is outside the range of an Int"),
35+
None => {
36+
// Hack to emulate a panic in this case.
37+
// Inspired by the [`static_assertions`](https://github.com/nvzqz/static-assertions) package.
38+
// Improvements to be made with higher MSRVs:
39+
// * 1.48: Replace the number comparison with `Option::is_none`
40+
// * 1.57: Use `panic!()` directly.
41+
// * 1.83: Replace manual `panic!()` with `Option::expect`
42+
#[allow(unknown_lints, unused_comparisons)]
43+
const _: [(); 0 - !{
44+
const ASSERT: bool = $n <= $crate::MAX_SAFE_UINT;
45+
ASSERT
46+
} as usize] = [];
47+
// This loop should not run, but it produces a never type that keeps the match
48+
// arms having the same type (since never conforms to any type)
49+
loop {}
50+
}
2251
};
2352
VALUE
2453
}};

0 commit comments

Comments
 (0)