Repository: LiveSplit/livesplit-core
Pull request #416 (2021-03-25 16:40:23)

Switch to Cargo's new feature resolver
Rust 1.51 just came out and with it cargo's new feature resolver. We had to work around the old feature resolver and all those hacks can now be removed.

Additionally there's some other small fixes (some of which Rust 1.51 enabled as well).


Patch:
diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml
deleted file mode 100644
index e79f268..0000000
--- a/.github/workflows/bench.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-name: Benchmarking
-
-on:
-  push:
-    branches: [ master ]
-  pull_request:
-    branches: [ master ]
-
-env:
-  CARGO_TERM_COLOR: always
-
-jobs:
-  build:
-    name: Run benchmarks
-    runs-on: ubuntu-latest
-    env:
-      CRITERION_TOKEN: ${{ secrets.CRITERION_TOKEN }}
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-
-      - name: Run benchmarks
-        run: |
-          # run benchmarks and save baseline to "criterion.dev.temp"
-          cargo bench --all-features -- --verbose --noplot --save-baseline criterion.dev.temp
-
-      # # set the path to the file to upload to criterion.dev
-      # echo "CRITERION_FILE_PATH=$(find ./target/criterion/ -name raw.csv)" >> $GITHUB_ENV
-
-      # - name: Upload benchmarks
-      #   run: |
-      #     # upload the file
-      #     curl -F 'raw.csv=@${{ env.CRITERION_FILE_PATH }}' \
-      #     'https://api.criterion.dev/v1/${{ github.repository }}/measurements?token=${{ secrets.CRITERION_TOKEN }}&commit=${{ github.sha }}'
diff --git a/.github/workflows/rust.yml b/.github/workflows/build.yml
similarity index 95%
rename from .github/workflows/rust.yml
rename to .github/workflows/build.yml
index 1de57fe..0d38edb 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/build.yml
@@ -1,4 +1,4 @@
-name: Rust
+name: Build
 
 on:
   pull_request:
@@ -664,6 +664,7 @@ jobs:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
   clippy:
+    name: Check clippy lints
     runs-on: ubuntu-latest
     steps:
       - name: Checkout Commit
@@ -678,6 +679,7 @@ jobs:
         run: cargo clippy --all-features
 
   format:
+    name: Check formatting
     runs-on: ubuntu-latest
     steps:
       - name: Checkout Commit
@@ -691,7 +693,34 @@ jobs:
       - name: Run cargo fmt
         run: cargo fmt -- --check || true
 
+  bench:
+    name: Run benchmarks
+    runs-on: ubuntu-latest
+    env:
+      CRITERION_TOKEN: ${{ secrets.CRITERION_TOKEN }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Install Rust
+        uses: hecrj/setup-rust-action@v1
+
+      - name: Run benchmarks
+        run: |
+          # run benchmarks and save baseline to "criterion.dev.temp"
+          cargo bench --all-features -- --verbose --noplot --save-baseline criterion.dev.temp
+
+      # # set the path to the file to upload to criterion.dev
+      # echo "CRITERION_FILE_PATH=$(find ./target/criterion/ -name raw.csv)" >> $GITHUB_ENV
+
+      # - name: Upload benchmarks
+      #   run: |
+      #     # upload the file
+      #     curl -F 'raw.csv=@${{ env.CRITERION_FILE_PATH }}' \
+      #     'https://api.criterion.dev/v1/${{ github.repository }}/measurements?token=${{ secrets.CRITERION_TOKEN }}&commit=${{ github.sha }}'
+
   docs:
+    name: Generate documentation
     if: startsWith(github.ref, 'refs/tags/')
     runs-on: ubuntu-latest
     steps:
diff --git a/.github/workflows/build_static.sh b/.github/workflows/build_static.sh
index 3e35ebf..fd36993 100644
--- a/.github/workflows/build_static.sh
+++ b/.github/workflows/build_static.sh
@@ -11,7 +11,7 @@ main() {
     fi
 
     if [ "$NO_STD" = "true" ]; then
-        (cd crates/no-std-test && cargo build --target $TARGET $FEATURES)
+        cargo build --target $TARGET --no-default-features $FEATURES
         return
     fi
 
diff --git a/Cargo.toml b/Cargo.toml
index 2640862..ece2d56 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,13 +19,13 @@ include = [
     "/README.md"
 ]
 edition = "2018"
+resolver = "2"
 
 [package.metadata.docs.rs]
 all-features = true
 
 [workspace]
 members = ["capi", "capi/bind_gen", "capi/staticlib", "capi/cdylib", "crates/*"]
-exclude = ["crates/no-std-test"]
 
 [dependencies]
 # core
diff --git a/README.md b/README.md
index 658a854..c42cf35 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # <img src="https://raw.githubusercontent.com/LiveSplit/LiveSplit/master/LiveSplit/Resources/Icon.png" alt="LiveSplit" height="42" width="45" align="top"/> livesplit-core
 
-[![Build Status](https://github.com/LiveSplit/livesplit-core/workflows/Rust/badge.svg)](https://github.com/LiveSplit/livesplit-core/actions)
+[![Build Status](https://github.com/LiveSplit/livesplit-core/workflows/Build/badge.svg)](https://github.com/LiveSplit/livesplit-core/actions)
 [![crates.io](https://img.shields.io/crates/v/livesplit-core.svg)](https://crates.io/crates/livesplit-core)
 [![npm](https://img.shields.io/npm/v/livesplit-core.svg)](https://www.npmjs.com/package/livesplit-core)
 [![docs.rs](https://docs.rs/livesplit-core/badge.svg)](https://docs.rs/livesplit-core/)
diff --git a/crates/livesplit-hotkey/src/wasm_web/mod.rs b/crates/livesplit-hotkey/src/wasm_web/mod.rs
index 4926042..e33e817 100644
--- a/crates/livesplit-hotkey/src/wasm_web/mod.rs
+++ b/crates/livesplit-hotkey/src/wasm_web/mod.rs
@@ -1,11 +1,11 @@
 mod key_code;
 pub use self::key_code::KeyCode;
 
-use wasm_bindgen::prelude::*;
-use wasm_bindgen::JsCast;
+use wasm_bindgen::{prelude::*, JsCast};
 use web_sys::{window, Gamepad, GamepadButton, KeyboardEvent};
 
 use std::{
+    array,
     cell::Cell,
     collections::hash_map::{Entry, HashMap},
     sync::{Arc, Mutex},
@@ -106,7 +106,7 @@ impl Hook {
                         for ((button, code), state) in gamepad
                             .buttons()
                             .iter()
-                            .zip(GAMEPAD_BUTTONS.iter().copied())
+                            .zip(array::IntoIter::new(GAMEPAD_BUTTONS))
                             .zip(states.iter_mut())
                         {
                             if let Ok(button) = button.dyn_into::<GamepadButton>() {
diff --git a/src/rendering/font/mod.rs b/src/rendering/font/mod.rs
index 80a9527..c677a18 100644
--- a/src/rendering/font/mod.rs
+++ b/src/rendering/font/mod.rs
@@ -30,7 +30,7 @@ pub struct Font<'fd> {
     scale_factor: f32,
     #[cfg(feature = "font-loading")]
     /// Safety: This can never be mutated. This also needs to be dropped last.
-    buf: Option<Box<[u8]>>,
+    _buf: Option<Box<[u8]>>,
 }
 
 impl<'fd> Font<'fd> {
@@ -66,7 +66,7 @@ impl<'fd> Font<'fd> {
             let slice: *const [u8] = &*buf;
             let mut font =
                 Font::from_slice(&*slice, font_index, font.style, font.weight, font.stretch)?;
-            font.buf = Some(buf);
+            font._buf = Some(buf);
             Some(font)
         }
     }
@@ -110,7 +110,7 @@ impl<'fd> Font<'fd> {
             color_tables: ColorTables::new(&face),
             face,
             #[cfg(feature = "font-loading")]
-            buf: None,
+            _buf: None,
         })
     }
 
diff --git a/src/run/editor/state.rs b/src/run/editor/state.rs
index 674ee53..822a3ab 100644
--- a/src/run/editor/state.rs
+++ b/src/run/editor/state.rs
@@ -1,10 +1,11 @@
 use super::{Editor, SegmentRow, TimingMethod};
-use crate::comparison::personal_best;
-use crate::platform::prelude::*;
-use crate::run::RunMetadata;
-use crate::settings::{CachedImageId, ImageData};
-use crate::timing::formatter::none_wrapper::EmptyWrapper;
-use crate::timing::formatter::{Accuracy, Short, TimeFormatter};
+use crate::{
+    comparison::personal_best,
+    platform::prelude::*,
+    run::RunMetadata,
+    settings::{CachedImageId, ImageData},
+    timing::formatter::{none_wrapper::EmptyWrapper, Accuracy, Short, TimeFormatter},
+};
 use serde::{Deserialize, Serialize};
 
 /// Represents the current state of the Run Editor in order to visualize it
@@ -120,8 +121,8 @@ impl Editor {
         let comparison_names = self
             .custom_comparisons()
             .iter()
+            .filter(|&n| n != personal_best::NAME)
             .cloned()
-            .filter(|n| n != personal_best::NAME)
             .collect::<Vec<_>>();
 
         let buttons = Buttons {
diff --git a/src/run/parser/splits_io.rs b/src/run/parser/splits_io.rs
index da09fb3..26d50d8 100644
--- a/src/run/parser/splits_io.rs
+++ b/src/run/parser/splits_io.rs
@@ -3,8 +3,7 @@
 use crate::{Run, Segment as LiveSplitSegment, Time, TimeSpan};
 use core::result::Result as StdResult;
 use serde::{Deserialize, Serialize};
-use serde_json::de::from_reader;
-use serde_json::Error as JsonError;
+use serde_json::{de::from_reader, Error as JsonError};
 use snafu::ResultExt;
 use std::io::Read;
 
@@ -23,8 +22,8 @@ pub enum Error {
 pub type Result<T> = StdResult<T, Error>;
 
 /// Duration holds a realtime duration and a gametime duration.
-#[serde(rename = "duration")]
 #[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
+#[serde(rename = "duration")]
 struct Duration {
     /// Gametime (Milliseconds) is a duration of milliseconds in game-world time.
     #[serde(rename = "gametimeMS")]
@@ -35,8 +34,8 @@ struct Duration {
 }
 /// Run Time represents a moment inside a run, and indicates the duration of the run so far at that
 /// moment. It holds a realtime run duration so far and a gametime run duration so far.
-#[serde(rename = "runTime")]
 #[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
+#[serde(rename = "runTime")]
 struct RunTime {
     /// Gametime (Milliseconds) is a duration a run so far in milliseconds.
     #[serde(rename = "gametimeMS")]


Test patch:
diff --git a/crates/no-std-test/Cargo.toml b/crates/no-std-test/Cargo.toml
deleted file mode 100644
index 7b16a8a..0000000
--- a/crates/no-std-test/Cargo.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-[package]
-name = "no-std-test"
-version = "0.1.0"
-authors = ["Christopher Serr <christopher.serr@gmail.com>"]
-edition = "2018"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[workspace]
-
-[dependencies]
-livesplit-core = { path = "../..", default-features = false }
-
-[features]
-doesnt-have-atomics = ["livesplit-core/doesnt-have-atomics"]
diff --git a/crates/no-std-test/README.md b/crates/no-std-test/README.md
deleted file mode 100644
index 5482e37..0000000
--- a/crates/no-std-test/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# no_std Testing
-
-In order to test the build for a no_std target, we can't use the same workspace
-as the main one as that one includes std-only dev-dependencies that leak their
-features into the no_std main dependencies. This is a cargo bug. This crate is
-therefore only a temporary workaround.
diff --git a/crates/no-std-test/src/lib.rs b/crates/no-std-test/src/lib.rs
deleted file mode 100644
index 0c9ac1a..0000000
--- a/crates/no-std-test/src/lib.rs
+++ /dev/null
@@ -1,1 +0,0 @@
-#![no_std]