Skip to content

Commit ba01a1c

Browse files
committed
Change the range syntax that is giving ctest problems
`ctest` is iffy about whether or not it accepts `..=` syntax, and I can't figure out what makes it decide whether or not to accept it and sometimes random changes seem to make things fail, so just replace the syntax. This is simpler anyway, and closer matches the upstream definition [1]. Link: https://github.com/torvalds/linux/blob/80e54e84911a923c40d7bee33a34c1b4be148d7a/Makefile#L1316 [1] (backport <rust-lang#4311>) (cherry picked from commit 1779f14)
1 parent b40637e commit ba01a1c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
//! Compare libc's KERNEL_VERSION macro against a specific kernel version.
22
3-
#[cfg(
4-
target_os = "linux",
5-
)]
3+
#[cfg(target_os = "linux")]
64
mod t {
75
use libc;
86

97
#[test]
108
fn test_kernel_version() {
11-
unsafe {
12-
assert_eq!(libc::KERNEL_VERSION(6, 0, 0), 393216);
13-
}
9+
assert_eq!(unsafe { libc::KERNEL_VERSION(6, 0, 0) }, 393216);
10+
// Check that the patch level saturates
11+
assert_eq!(unsafe { libc::KERNEL_VERSION(6, 0, 255) }, 393471);
12+
assert_eq!(unsafe { libc::KERNEL_VERSION(6, 0, 256) }, 393471);
13+
assert_eq!(unsafe { libc::KERNEL_VERSION(6, 0, 300) }, 393471);
14+
assert_eq!(unsafe { libc::KERNEL_VERSION(6, 0, u32::MAX) }, 393471);
1415
}
1516
}

src/unix/linux_like/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1756,11 +1756,7 @@ safe_f! {
17561756

17571757
#[allow(ellipsis_inclusive_range_patterns)]
17581758
pub {const} fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 {
1759-
((a << 16) + (b << 8))
1760-
+ match c {
1761-
0..=255 => c,
1762-
_ => 255,
1763-
}
1759+
((a << 16) + (b << 8)) + if c > 255 { 255 } else { c }
17641760
}
17651761
}
17661762

0 commit comments

Comments
 (0)