Repository: probe-rs/probe-rs
Pull request #2319 (2024-03-25 20:01:01)

Update CI to rustc v1.77.0, fix clippy warnings
cargo-dist complains when the version is set in `Cargo.toml`, so this changes it to set the version in `rust-toolchain.toml`.

If we do that, then it seems unnecessary to specify the version again in the other workflows as well.


Patch:
diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml
deleted file mode 100644
index 2e048d80..00000000
--- a/.github/actions/setup/action.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-name: Install toolchain
-description: Install toolchain
-inputs:
-  targets:
-    description: "The targets to install"
-    required: false
-  components:
-    description: "The components to install"
-    required: false
-runs:
-  using: "composite"
-  steps:
-    - name: Install toolchain
-      uses: dtolnay/rust-toolchain@1.76.0
-      with:
-        targets: ${{ inputs.targets }}
-        components: ${{ inputs.components }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 909f3782..b0e40ab2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -38,8 +38,6 @@ jobs:
         # Only install on Ubuntu
         if: (matrix.os == 'ubuntu-latest') || (matrix.os == 'ubuntu-20.04')
 
-      - uses: ./.github/actions/setup
-
       - name: Cache Dependencies
         uses: Swatinem/rust-cache@v2.7.3
 
@@ -76,9 +74,8 @@ jobs:
         # Only install on Ubuntu
         if: matrix.os == 'ubuntu-latest'
 
-      - uses: ./.github/actions/setup
-        with:
-          targets: thumbv7m-none-eabi
+      - name: "Install thumbv7m-none-eabi target for tests"
+        run: rustup target add thumbv7m-none-eabi
       
       - name: Cache Dependencies
         uses: Swatinem/rust-cache@v2.7.3
@@ -93,10 +90,6 @@ jobs:
       - name: Checkout sources
         uses: actions/checkout@v4
 
-      - uses: ./.github/actions/setup
-        with:
-          components: rustfmt
-
       - name: Run cargo fmt
         run: cargo fmt --all -- --check
 
@@ -112,10 +105,6 @@ jobs:
           sudo apt update
           sudo apt install -y libudev-dev
 
-      - uses: ./.github/actions/setup
-        with:
-          components: clippy
-
       - name: Cache Dependencies
         uses: Swatinem/rust-cache@v2.7.3
 
@@ -140,8 +129,6 @@ jobs:
           sudo apt update
           sudo apt install -y libudev-dev
 
-      - uses: ./.github/actions/setup
-
       - name: Cache Dependencies
         uses: Swatinem/rust-cache@v2.7.3
 
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 74d1d55d..d02d1b2c 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -58,8 +58,6 @@ jobs:
       - uses: actions/checkout@v4
         with:
           submodules: recursive
-      - name: Install Rust
-        run: rustup update "1.74.0" --no-self-update && rustup default "1.74.0"
       - name: Install cargo-dist
         # we specify bash to get pipefail; it guards against the `curl` command
         # failing. otherwise `sh` won't catch that `curl` returned non-0
@@ -110,8 +108,6 @@ jobs:
       - uses: actions/checkout@v4
         with:
           submodules: recursive
-      - name: Install Rust
-        run: rustup update "1.74.0" --no-self-update && rustup default "1.74.0"
       - uses: swatinem/rust-cache@v2
       - name: Install cargo-dist
         run: ${{ matrix.install_dist }}
@@ -164,8 +160,6 @@ jobs:
       - uses: actions/checkout@v4
         with:
           submodules: recursive
-      - name: Install Rust
-        run: rustup update "1.74.0" --no-self-update && rustup default "1.74.0"
       - name: Install cargo-dist
         shell: bash
         run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
@@ -212,8 +206,6 @@ jobs:
       - uses: actions/checkout@v4
         with:
           submodules: recursive
-      - name: Install Rust
-        run: rustup update "1.74.0" --no-self-update && rustup default "1.74.0"
       - name: Install cargo-dist
         run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
       # Fetch artifacts from scratch-storage
diff --git a/Cargo.toml b/Cargo.toml
index 35a18412..6ca86b14 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,8 +37,6 @@ tag-name = "v{{version}}"
 [workspace.metadata.dist]
 # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
 cargo-dist-version = "0.11.1"
-# The preferred Rust toolchain to use in CI (rustup toolchain syntax)
-rust-toolchain-version = "1.74.0"
 # CI backends to support
 ci = ["github"]
 # Target platforms to build apps for (Rust target-triple syntax)
diff --git a/probe-rs/src/rtt.rs b/probe-rs/src/rtt.rs
index ec67ce93..35749fd0 100644
--- a/probe-rs/src/rtt.rs
+++ b/probe-rs/src/rtt.rs
@@ -283,9 +283,7 @@ impl Rtt {
                     core.read(range.start, mem.as_mut()).ok()?;
                 }
 
-                let Some(offset) = kmp::kmp_find(&Self::RTT_ID, mem.as_slice()) else {
-                    return None;
-                };
+                let offset = kmp::kmp_find(&Self::RTT_ID, mem.as_slice())?;
 
                 let target_ptr = range.start + (offset as u64);
                 let Ok(target_ptr) = target_ptr.try_into() else {
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 00000000..163f7eb9
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,4 @@
+[toolchain]
+channel = "1.77.0"
+
+components = ["rustfmt", "clippy"]


Test patch:
diff --git a/.github/workflows/smoketest.yml b/.github/workflows/smoketest.yml
index 6c9743c0..f9f436e0 100644
--- a/.github/workflows/smoketest.yml
+++ b/.github/workflows/smoketest.yml
@@ -19,10 +19,8 @@ jobs:
       - name: Checkout sources
         uses: actions/checkout@v4
 
-      - uses: ./.github/actions/setup
-        with:
-          targets:
-            aarch64-unknown-linux-gnu
+      - name: Install target for cross-compilation
+        run: rustup target add aarch64-unknown-linux-gnu
 
       - name: Install cross 
         uses: taiki-e/install-action@v2.29.3