From 13e37016bdc612c6625e9b9f991f61942b4e7449 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 17 Feb 2023 23:47:53 +0000 Subject: [PATCH 1/3] Added directives to Rust code to suppress a stylistic lint check. --- rust-no-heap/src/lib.rs | 1 + rust/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/rust-no-heap/src/lib.rs b/rust-no-heap/src/lib.rs index b595fcc..6b2d363 100644 --- a/rust-no-heap/src/lib.rs +++ b/rust-no-heap/src/lib.rs @@ -965,6 +965,7 @@ impl FinderPenalty { let n = rh[1]; debug_assert!(n <= self.qr_size * 3); let core = n > 0 && rh[2] == n && rh[3] == n * 3 && rh[4] == n && rh[5] == n; + #[allow(unused_parens)] ( i32::from(core && rh[0] >= n * 4 && rh[6] >= n) + i32::from(core && rh[6] >= n * 4 && rh[0] >= n)) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 5f26b25..c1cbf72 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -839,6 +839,7 @@ impl FinderPenalty { let n = rh[1]; debug_assert!(n <= self.qr_size * 3); let core = n > 0 && rh[2] == n && rh[3] == n * 3 && rh[4] == n && rh[5] == n; + #[allow(unused_parens)] ( i32::from(core && rh[0] >= n * 4 && rh[6] >= n) + i32::from(core && rh[6] >= n * 4 && rh[0] >= n)) } From 5d9ec8dfdddbd66e14833130aa849b7ca5a894e1 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 17 Feb 2023 23:50:47 +0000 Subject: [PATCH 2/3] Replaced some Rust object method calls with primitive arithmetic in order to support constant evaluation. --- rust-no-heap/src/lib.rs | 2 +- rust/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-no-heap/src/lib.rs b/rust-no-heap/src/lib.rs index 6b2d363..a70fd9e 100644 --- a/rust-no-heap/src/lib.rs +++ b/rust-no-heap/src/lib.rs @@ -1433,7 +1433,7 @@ impl Version { /// /// Panics if the number is outside the range [1, 40]. pub fn new(ver: u8) -> Self { - assert!((Version::MIN.value() ..= Version::MAX.value()).contains(&ver), "Version number out of range"); + assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range"); Self(ver) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c1cbf72..bfe335e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1266,7 +1266,7 @@ impl Version { /// /// Panics if the number is outside the range [1, 40]. pub fn new(ver: u8) -> Self { - assert!((Version::MIN.value() ..= Version::MAX.value()).contains(&ver), "Version number out of range"); + assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range"); Self(ver) } From 2643e824eb15064662e6c4d99b010740275a0be1 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 17 Feb 2023 23:53:35 +0000 Subject: [PATCH 3/3] Enabled constant evaluation of Rust Version/Mask functions/methods. --- rust-no-heap/src/lib.rs | 8 ++++---- rust/src/lib.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust-no-heap/src/lib.rs b/rust-no-heap/src/lib.rs index a70fd9e..453d9f9 100644 --- a/rust-no-heap/src/lib.rs +++ b/rust-no-heap/src/lib.rs @@ -1432,13 +1432,13 @@ impl Version { /// Creates a version object from the given number. /// /// Panics if the number is outside the range [1, 40]. - pub fn new(ver: u8) -> Self { + pub const fn new(ver: u8) -> Self { assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range"); Self(ver) } /// Returns the value, which is in the range [1, 40]. - pub fn value(self) -> u8 { + pub const fn value(self) -> u8 { self.0 } @@ -1459,13 +1459,13 @@ impl Mask { /// Creates a mask object from the given number. /// /// Panics if the number is outside the range [0, 7]. - pub fn new(mask: u8) -> Self { + pub const fn new(mask: u8) -> Self { assert!(mask <= 7, "Mask value out of range"); Self(mask) } /// Returns the value, which is in the range [0, 7]. - pub fn value(self) -> u8 { + pub const fn value(self) -> u8 { self.0 } } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index bfe335e..b4f2aaf 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1265,13 +1265,13 @@ impl Version { /// Creates a version object from the given number. /// /// Panics if the number is outside the range [1, 40]. - pub fn new(ver: u8) -> Self { + pub const fn new(ver: u8) -> Self { assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range"); Self(ver) } /// Returns the value, which is in the range [1, 40]. - pub fn value(self) -> u8 { + pub const fn value(self) -> u8 { self.0 } } @@ -1285,13 +1285,13 @@ impl Mask { /// Creates a mask object from the given number. /// /// Panics if the number is outside the range [0, 7]. - pub fn new(mask: u8) -> Self { + pub const fn new(mask: u8) -> Self { assert!(mask <= 7, "Mask value out of range"); Self(mask) } /// Returns the value, which is in the range [0, 7]. - pub fn value(self) -> u8 { + pub const fn value(self) -> u8 { self.0 } }