Repository: probe-rs/probe-rs
Pull request #3192 (2025-03-27 20:49:57)

Migrate to Rust Edition 2024


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index 79d36eef..e79912fe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [workspace.package]
 version = "0.27.0"
-edition = "2021"
+edition = "2024"
 
 documentation = "https://docs.rs/probe-rs/"
 homepage = "https://github.com/probe-rs/probe-rs"
diff --git a/changelog/changed-edition-2024.md b/changelog/changed-edition-2024.md
new file mode 100644
index 00000000..1448ad21
--- /dev/null
+++ b/changelog/changed-edition-2024.md
@@ -0,0 +1,1 @@
+* Use Rust edition 2024.
diff --git a/probe-rs-target/Cargo.toml b/probe-rs-target/Cargo.toml
index b1a967a3..a6f0ad3c 100644
--- a/probe-rs-target/Cargo.toml
+++ b/probe-rs-target/Cargo.toml
@@ -17,7 +17,9 @@ serde = { version = "1", features = ["derive"] }
 base64 = "0.22.1"
 url = { version = "2.5", features = ["serde"] }
 indexmap = { version = "2.2", features = ["serde"] }
-serde_with = { version = "3.8", default-features = false, features = ["indexmap_2"] }
+serde_with = { version = "3.8", default-features = false, features = [
+    "indexmap_2",
+] }
 
 [lints]
 workspace = true
diff --git a/probe-rs-tools/Cargo.toml b/probe-rs-tools/Cargo.toml
index c6aee1d5..87560c25 100644
--- a/probe-rs-tools/Cargo.toml
+++ b/probe-rs-tools/Cargo.toml
@@ -109,8 +109,13 @@ svg = "0.18"
 tokio = { version = "1.0", features = ["full"] }
 tokio-util = "0.7"
 futures-util = { version = "0.3" }
-rustls = { version = "0.23", default-features = false, features = ["std", "ring"], optional = true }
-tokio-tungstenite = { version = "0.26", features = ["rustls-tls-webpki-roots"], optional = true }
+rustls = { version = "0.23", default-features = false, features = [
+    "std",
+    "ring",
+], optional = true }
+tokio-tungstenite = { version = "0.26", features = [
+    "rustls-tls-webpki-roots",
+], optional = true }
 axum = { version = "0.8", features = ["ws"], optional = true }
 axum-extra = { version = "0.10", features = ["typed-header"], optional = true }
 tempfile = { version = "3.0", optional = true }
diff --git a/probe-rs-tools/src/bin/probe-rs/cmd/benchmark.rs b/probe-rs-tools/src/bin/probe-rs/cmd/benchmark.rs
index 7ac618ff..f9b1b471 100644
--- a/probe-rs-tools/src/bin/probe-rs/cmd/benchmark.rs
+++ b/probe-rs-tools/src/bin/probe-rs/cmd/benchmark.rs
@@ -228,19 +228,19 @@ impl DataType {
     pub fn fill_data(&mut self, data_size_words: usize) {
         let mut rng = fastrand::Rng::new();
         match self {
-            DataType::U8(ref mut test_data, ref mut read_data) => {
+            DataType::U8(test_data, read_data) => {
                 *test_data = vec![0u8; data_size_words];
                 *read_data = vec![0u8; data_size_words];
                 rng.fill(&mut test_data[..]);
             }
-            DataType::U32(ref mut test_data, ref mut read_data) => {
+            DataType::U32(test_data, read_data) => {
                 *test_data = vec![0u32; data_size_words];
                 *read_data = vec![0u32; data_size_words];
                 for out in test_data.iter_mut() {
                     *out = rng.u32(..);
                 }
             }
-            DataType::U64(ref mut test_data, ref mut read_data) => {
+            DataType::U64(test_data, read_data) => {
                 *test_data = vec![0u64; data_size_words];
                 *read_data = vec![0u64; data_size_words];
                 for out in test_data.iter_mut() {
@@ -309,13 +309,13 @@ impl TestData {
     fn block_read(&mut self, core: &mut probe_rs::Core) -> Result<f64, anyhow::Error> {
         let read_start = Instant::now();
         match &mut self.data_type {
-            DataType::U8(_, ref mut readback_data) => core
+            DataType::U8(_, readback_data) => core
                 .read_8(self.address, readback_data)
                 .expect("Reading the sample data failed"),
-            DataType::U32(_, ref mut readback_data) => core
+            DataType::U32(_, readback_data) => core
                 .read_32(self.address, readback_data)
                 .expect("Reading the sample data failed"),
-            DataType::U64(_, ref mut readback_data) => core
+            DataType::U64(_, readback_data) => core
                 .read_64(self.address, readback_data)
                 .expect("Reading the sample data failed"),
         }
@@ -330,10 +330,10 @@ impl TestData {
     fn block_write(&mut self, core: &mut probe_rs::Core) -> Result<f64, anyhow::Error> {
         let write_start = Instant::now();
         match &self.data_type {
-            DataType::U8(ref test_data, _) => core
+            DataType::U8(test_data, _) => core
                 .write_8(self.address, test_data)
                 .context("Writing the sample data failed")?,
-            DataType::U32(ref test_data, _) => core
+            DataType::U32(test_data, _) => core
                 .write_32(self.address, test_data)
                 .context("Writing the sample data failed")?,
             DataType::U64(test_data, _) => core
diff --git a/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/error.rs b/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/error.rs
index 73fb627f..cd74879f 100644
--- a/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/error.rs
+++ b/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/error.rs
@@ -12,9 +12,9 @@ pub enum DownloadError {
 impl Error for DownloadError {
     fn source(&self) -> Option<&(dyn Error + 'static)> {
         match self {
-            Self::DebugProbe(ref e) => Some(e),
-            Self::AccessPort(ref e) => Some(e),
-            Self::StdIO(ref e) => Some(e),
+            Self::DebugProbe(e) => Some(e),
+            Self::AccessPort(e) => Some(e),
+            Self::StdIO(e) => Some(e),
         }
     }
 }
@@ -22,9 +22,9 @@ impl Error for DownloadError {
 impl fmt::Display for DownloadError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            Self::DebugProbe(ref e) => e.fmt(f),
-            Self::AccessPort(ref e) => e.fmt(f),
-            Self::StdIO(ref e) => e.fmt(f),
+            Self::DebugProbe(e) => e.fmt(f),
+            Self::AccessPort(e) => e.fmt(f),
+            Self::StdIO(e) => e.fmt(f),
         }
     }
 }
diff --git a/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/rttui/channel.rs b/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/rttui/channel.rs
index c541dec1..b1a45a31 100644
--- a/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/rttui/channel.rs
+++ b/probe-rs-tools/src/bin/probe-rs/cmd/cargo_embed/rttui/channel.rs
@@ -14,7 +14,7 @@ pub enum ChannelData {
 
 impl RttDataHandler for (&mut Option<TcpPublisher>, &mut ChannelData) {
     fn on_string_data(&mut self, data: String) -> Result<(), Error> {
-        if let Some(ref mut stream) = self.0 {
+        if let Some(stream) = self.0 {
             stream.send(data.as_bytes());
         }
 
@@ -27,7 +27,7 @@ impl RttDataHandler for (&mut Option<TcpPublisher>, &mut ChannelData) {
     }
 
     fn on_binary_data(&mut self, incoming: &[u8]) -> Result<(), Error> {
-        if let Some(ref mut stream) = self.0 {
+        if let Some(stream) = self.0 {
             stream.send(incoming);
         }
 
diff --git a/probe-rs-tools/src/bin/probe-rs/rpc/functions.rs b/probe-rs-tools/src/bin/probe-rs/rpc/functions.rs
index dda3317f..c38d39ca 100644
--- a/probe-rs-tools/src/bin/probe-rs/rpc/functions.rs
+++ b/probe-rs-tools/src/bin/probe-rs/rpc/functions.rs
@@ -155,14 +155,14 @@ impl RpcSpawnContext {
         self.state.dry_run(sessid)
     }
 
-    fn session_blocking(&self, sessid: Key<Session>) -> impl DerefMut<Target = Session> {
+    fn session_blocking(&self, sessid: Key<Session>) -> impl DerefMut<Target = Session> + use<> {
         self.state.session_blocking(sessid)
     }
 
     pub fn object_mut_blocking<T: Any + Send>(
         &self,
         key: Key<T>,
-    ) -> impl DerefMut<Target = T> + Send {
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         self.state.object_mut_blocking(key)
     }
 
@@ -325,7 +325,10 @@ impl RpcContext {
             .map_err(|e| anyhow!("{:?}", e))
     }
 
-    pub async fn object_mut<T: Any + Send>(&self, key: Key<T>) -> impl DerefMut<Target = T> + Send {
+    pub async fn object_mut<T: Any + Send>(
+        &self,
+        key: Key<T>,
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         self.state.object_mut(key).await
     }
 
@@ -337,7 +340,10 @@ impl RpcContext {
         self.state.set_session(session, dry_run).await
     }
 
-    pub async fn session(&self, sid: Key<Session>) -> impl DerefMut<Target = Session> + Send {
+    pub async fn session(
+        &self,
+        sid: Key<Session>,
+    ) -> impl DerefMut<Target = Session> + Send + use<> {
         self.object_mut(sid).await
     }
 
@@ -345,7 +351,7 @@ impl RpcContext {
         Lister::with_lister(Box::new(LimitedLister::new(self.probe_access.clone())))
     }
 
-    pub async fn registry(&self) -> impl DerefMut<Target = Registry> + Send {
+    pub async fn registry(&self) -> impl DerefMut<Target = Registry> + Send + use<> {
         self.state.registry.clone().lock_owned().await
     }
 
diff --git a/probe-rs-tools/src/bin/probe-rs/rpc/mod.rs b/probe-rs-tools/src/bin/probe-rs/rpc/mod.rs
index 053d537c..6fac776b 100644
--- a/probe-rs-tools/src/bin/probe-rs/rpc/mod.rs
+++ b/probe-rs-tools/src/bin/probe-rs/rpc/mod.rs
@@ -96,7 +96,10 @@ impl ObjectStorage {
         key
     }
 
-    pub async fn object_mut<T: Any + Send>(&self, key: Key<T>) -> impl DerefMut<Target = T> + Send {
+    pub async fn object_mut<T: Any + Send>(
+        &self,
+        key: Key<T>,
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         let obj = self.storage.get(&key.key).unwrap();
         let guard = obj.clone().lock_owned().await;
         tokio::sync::OwnedMutexGuard::map(guard, |e: &mut (dyn Any + Send)| {
@@ -107,7 +110,7 @@ impl ObjectStorage {
     pub fn object_mut_blocking<T: Any + Send>(
         &self,
         key: Key<T>,
-    ) -> impl DerefMut<Target = T> + Send {
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         let obj = self.storage.get(&key.key).unwrap();
         let guard = obj.clone().blocking_lock_owned();
         tokio::sync::OwnedMutexGuard::map(guard, |e: &mut (dyn Any + Send)| {
@@ -141,14 +144,17 @@ impl SessionState {
         self.object_storage.blocking_lock().store_object(obj)
     }
 
-    pub async fn object_mut<T: Any + Send>(&self, key: Key<T>) -> impl DerefMut<Target = T> + Send {
+    pub async fn object_mut<T: Any + Send>(
+        &self,
+        key: Key<T>,
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         self.object_storage.lock().await.object_mut(key).await
     }
 
     pub fn object_mut_blocking<T: Any + Send>(
         &self,
         key: Key<T>,
-    ) -> impl DerefMut<Target = T> + Send {
+    ) -> impl DerefMut<Target = T> + Send + use<T> {
         self.object_storage.blocking_lock().object_mut_blocking(key)
     }
 
@@ -158,7 +164,10 @@ impl SessionState {
         key
     }
 
-    pub fn session_blocking(&self, sid: Key<Session>) -> impl DerefMut<Target = Session> + Send {
+    pub fn session_blocking(
+        &self,
+        sid: Key<Session>,
+    ) -> impl DerefMut<Target = Session> + Send + use<> {
         self.object_mut_blocking(sid)
     }
 
diff --git a/probe-rs-tools/src/bin/probe-rs/util/rtt/processing.rs b/probe-rs-tools/src/bin/probe-rs/util/rtt/processing.rs
index d98248cd..7c34a9b0 100644
--- a/probe-rs-tools/src/bin/probe-rs/util/rtt/processing.rs
+++ b/probe-rs-tools/src/bin/probe-rs/util/rtt/processing.rs
@@ -76,7 +76,7 @@ impl RttDecoder {
             RttDecoder::BinaryLE => collector.on_binary_data(buffer),
             RttDecoder::String {
                 timestamp_offset,
-                ref mut last_line_done,
+                last_line_done,
             } => {
                 let string = Self::process_string(buffer, *timestamp_offset, last_line_done)?;
                 collector.on_string_data(string)
diff --git a/probe-rs/src/flashing/builder.rs b/probe-rs/src/flashing/builder.rs
index 4467b062..27e97ba1 100644
--- a/probe-rs/src/flashing/builder.rs
+++ b/probe-rs/src/flashing/builder.rs
@@ -227,7 +227,10 @@ impl FlashBuilder {
     /// If a staged chunk is not fully contained in the range, only the contained part is
     /// returned. ie for each returned item (addr, data), it's guaranteed that the condition
     /// `start <= addr && addr + data.len() <= end` upholds.
-    pub(crate) fn data_in_range(&self, range: &Range<u64>) -> impl Iterator<Item = (u64, &[u8])> {
+    pub(crate) fn data_in_range<'s>(
+        &'s self,
+        range: &Range<u64>,
+    ) -> impl Iterator<Item = (u64, &'s [u8])> + use<'s> {
         let range = range.clone();
 
         let mut adjusted_start = range.start;
diff --git a/probe-rs/src/probe/cmsisdap/commands/mod.rs b/probe-rs/src/probe/cmsisdap/commands/mod.rs
index c383c0b7..eac4938c 100644
--- a/probe-rs/src/probe/cmsisdap/commands/mod.rs
+++ b/probe-rs/src/probe/cmsisdap/commands/mod.rs
@@ -258,15 +258,11 @@ impl CmsisDapDevice {
     pub(super) fn set_packet_size(&mut self, packet_size: usize) {
         tracing::debug!("Configuring probe to use packet size {}", packet_size);
         match self {
-            CmsisDapDevice::V1 {
-                ref mut report_size,
-                ..
-            } => {
+            CmsisDapDevice::V1 { report_size, .. } => {
                 *report_size = packet_size;
             }
             CmsisDapDevice::V2 {
-                ref mut max_packet_size,
-                ..
+                max_packet_size, ..
             } => {
                 *max_packet_size = packet_size;
             }
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 7a05b002..3b33972f 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -2,7 +2,7 @@
 name = "xtask"
 version.workspace = true
 authors = ["Noah Hüsser <yatekii@yatekii.ch>"]
-edition = "2021"
+edition.workspace = true
 publish = false
 
 [dependencies]


Test patch:
diff --git a/smoke-tester/Cargo.toml b/smoke-tester/Cargo.toml
index 22ec84fd..79ef48c7 100644
--- a/smoke-tester/Cargo.toml
+++ b/smoke-tester/Cargo.toml
@@ -2,7 +2,7 @@
 name = "smoke_tester"
 version.workspace = true
 authors = ["Dominik Boehi <dominik.boehi@gmail.com>"]
-edition = "2021"
+edition.workspace = true
 publish = false