From 0fd6e29ceedb9d70594d088f655b9b553cebdae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 14 Jun 2024 09:28:28 +0200 Subject: [PATCH 1/3] Remove workaround using inline consts (stable in 1.79) --- Cargo.toml | 1 + src/lib.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 943bde7..c11a44a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "Apache-2.0 OR MIT" documentation = "https://docs.rs/interchange" keywords = ["cortex-m", "nxp", "lpc"] categories = ["development-tools", "embedded"] +rust-version = "1.79" [target.'cfg(loom)'.dependencies] loom = "0.5" diff --git a/src/lib.rs b/src/lib.rs index 84409e1..3e4b144 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -331,9 +331,6 @@ pub struct Channel { } impl Channel { - #[cfg(not(loom))] - const CHANNEL_INIT: Channel = Self::new(); - // Loom's atomics are not const :/ #[cfg(not(loom))] pub const fn new() -> Self { @@ -889,7 +886,16 @@ impl Interchange { #[cfg(not(loom))] pub const fn new() -> Self { Self { - channels: [Channel::::CHANNEL_INIT; N], + channels: [const { Channel::new() }; N], + last_claimed: AtomicUsize::new(0), + } + } + + /// Create a new Interchange + #[cfg(loom)] + pub fn new() -> Self { + Self { + channels: core::array::from_fn(|_| Channel::new()), last_claimed: AtomicUsize::new(0), } } @@ -958,7 +964,6 @@ impl<'alloc, Rq, Rp> InterchangeRef<'alloc, Rq, Rp> { } } -#[cfg(not(loom))] impl Default for Interchange { fn default() -> Self { Self::new() From b80645cbd0e9a763ea8a5c2de845740cd4be3930 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 14 Jan 2025 10:29:32 +0100 Subject: [PATCH 2/3] Disable unexpected cfg lint for cfg(loom) --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c11a44a..1f92965 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,6 @@ rust-version = "1.79" [target.'cfg(loom)'.dependencies] loom = "0.5" + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(loom)"] } From 63e9cd3c9d4359e99f654efc195a2e7cf6729289 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 14 Jan 2025 12:47:02 +0100 Subject: [PATCH 3/3] Remove unnecessary explicit lifetimes --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3e4b144..6af9676 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -410,7 +410,7 @@ pub struct Requester<'i, Rq, Rp> { channel: &'i Channel, } -impl<'i, Rq, Rp> Drop for Requester<'i, Rq, Rp> { +impl Drop for Requester<'_, Rq, Rp> { fn drop(&mut self) { self.channel .requester_claimed @@ -551,7 +551,7 @@ impl<'i, Rq, Rp> Requester<'i, Rq, Rp> { } } -impl<'i, Rq, Rp> Requester<'i, Rq, Rp> +impl Requester<'_, Rq, Rp> where Rq: Default, { @@ -627,7 +627,7 @@ pub struct Responder<'i, Rq, Rp> { channel: &'i Channel, } -impl<'i, Rq, Rp> Drop for Responder<'i, Rq, Rp> { +impl Drop for Responder<'_, Rq, Rp> { fn drop(&mut self) { self.channel .responder_claimed @@ -768,7 +768,7 @@ impl<'i, Rq, Rp> Responder<'i, Rq, Rp> { } } -impl<'i, Rq, Rp> Responder<'i, Rq, Rp> +impl Responder<'_, Rq, Rp> where Rp: Default, {