From bfe5638fa0c840fce1eb5668d258e7169ece18e1 Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 15:16:22 -0700 Subject: [PATCH 1/8] Run rustfmt on tests --- lib.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib.rs b/lib.rs index 2f7fb28..899c960 100644 --- a/lib.rs +++ b/lib.rs @@ -806,7 +806,6 @@ impl Drop for Async { // }}} - #[cfg(test)] mod test { use super::*; @@ -815,17 +814,22 @@ mod test { #[test] fn integration_test() { let (mock_drain, mock_drain_rx) = MockDrain::new(); - let async_drain = AsyncBuilder::new(mock_drain) - .build(); - let slog = slog::Logger::root(async_drain.fuse(), o!("field1" => "value1")); + let async_drain = AsyncBuilder::new(mock_drain).build(); + let slog = + slog::Logger::root(async_drain.fuse(), o!("field1" => "value1")); info!(slog, "Message 1"; "field2" => "value2"); warn!(slog, "Message 2"; "field3" => "value3"); - assert_eq!(mock_drain_rx.recv().unwrap(), r#"INFO Message 1: [("field1", "value1"), ("field2", "value2")]"#); - assert_eq!(mock_drain_rx.recv().unwrap(), r#"WARN Message 2: [("field1", "value1"), ("field3", "value3")]"#); + assert_eq!( + mock_drain_rx.recv().unwrap(), + r#"INFO Message 1: [("field1", "value1"), ("field2", "value2")]"# + ); + assert_eq!( + mock_drain_rx.recv().unwrap(), + r#"WARN Message 2: [("field1", "value1"), ("field3", "value3")]"# + ); } - /// Test-helper drain #[derive(Debug)] struct MockDrain { @@ -843,7 +847,11 @@ mod test { type Ok = (); type Err = slog::Never; - fn log(&self, record: &Record, logger_kv: &OwnedKVList) -> Result { + fn log( + &self, + record: &Record, + logger_kv: &OwnedKVList, + ) -> Result { let mut serializer = MockSerializer::default(); logger_kv.serialize(record, &mut serializer).unwrap(); record.kv().serialize(record, &mut serializer).unwrap(); @@ -861,7 +869,11 @@ mod test { } impl slog::Serializer for MockSerializer { - fn emit_arguments(&mut self, key: Key, val: &fmt::Arguments) -> Result<(), slog::Error> { + fn emit_arguments( + &mut self, + key: Key, + val: &fmt::Arguments, + ) -> Result<(), slog::Error> { self.kvs.push((key.to_string(), val.to_string())); Ok(()) } From 9e702831742d70e15f938844c661d135edffd5f2 Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 14:43:32 -0700 Subject: [PATCH 2/8] Bump MSRV to 1.61 The CI was failing before this change, because crossbeam-channel already requires 1.60 Many other crates (serde-derive, log, syn v2.0) already require 1.61. --- .github/workflows/test.yml | 8 ++++---- CHANGELOG.md | 2 +- Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74a795d..465d806 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,12 +27,12 @@ jobs: strategy: fail-fast: false # Even if one job fails we still want to see the other ones matrix: - # 1.59 is MSRV - rust: [1.59, stable, nightly] + # 1.61 is MSRV + rust: [1.61, stable, nightly] # NOTE: Features to test must be specified manually. They are applied to all versions separately. # - # This has the advantage of being more flexibile and thorough - # This has the disadvantage of being more vebrose + # This has the advantage of being more flexible and thorough + # This has the disadvantage of being more verbose # # Specific feature combos can be overridden per-version with 'include' and 'ecclude' features: ["", "nested-values", "dynamic-keys", "nested-values dynamic-keys"] diff --git a/CHANGELOG.md b/CHANGELOG.md index 6144ed5..29187b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -* Define minimum supported rust version. +* Bump MSRV to 1.61 (first time officially defined) * Setup Github Actions. * Fixup some minor typos in CHANGELOG.md, including an incorrect release date for 2.8.0. diff --git a/Cargo.toml b/Cargo.toml index c7600c8..220882c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ documentation = "https://docs.rs/slog-async" homepage = "https://github.com/slog-rs/slog" repository = "https://github.com/slog-rs/async" readme = "README.md" -rust-version = "1.59.0" +rust-version = "1.61" [features] nested-values = ["slog/nested-values"] From bfaf34f144cf164a06a5e14b9ab16f219efb170b Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 14:48:56 -0700 Subject: [PATCH 3/8] Unconditionally support i128 on all versions See slog-rs/slog#48e4651 --- CHANGELOG.md | 1 + build.rs | 53 ---------------------------------------------------- lib.rs | 2 -- 3 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 build.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 29187b4..410e7ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] * Bump MSRV to 1.61 (first time officially defined) +* Unconditionally support 128-bit integers. * Setup Github Actions. * Fixup some minor typos in CHANGELOG.md, including an incorrect release date for 2.8.0. diff --git a/build.rs b/build.rs deleted file mode 100644 index 9b5afdd..0000000 --- a/build.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::env; -use std::process::Command; -use std::str::{self, FromStr}; - -// This build script is adapted from serde. -// See https://github.com/serde-rs/serde/blob/9c39115f827170f7adbdfa4115f5916c5979393c/serde/build.rs -fn main() { - let minor = match rustc_minor_version() { - Some(minor) => minor, - None => return, - }; - - let target = env::var("TARGET").unwrap(); - let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten"; - - // 128-bit integers stabilized in Rust 1.26: - // https://blog.rust-lang.org/2018/05/10/Rust-1.26.html - // - // Disabled on Emscripten targets as Emscripten doesn't - // currently support integers larger than 64 bits. - if minor >= 26 && !emscripten { - println!("cargo:rustc-cfg=integer128"); - } -} - -fn rustc_minor_version() -> Option { - let rustc = match env::var_os("RUSTC") { - Some(rustc) => rustc, - None => return None, - }; - - let output = match Command::new(rustc).arg("--version").output() { - Ok(output) => output, - Err(_) => return None, - }; - - let version = match str::from_utf8(&output.stdout) { - Ok(version) => version, - Err(_) => return None, - }; - - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - - let next = match pieces.next() { - Some(next) => next, - None => return None, - }; - - u32::from_str(next).ok() -} diff --git a/lib.rs b/lib.rs index 899c960..fa6d24f 100644 --- a/lib.rs +++ b/lib.rs @@ -147,12 +147,10 @@ impl Serializer for ToSendSerializer { take(&mut self.kv, |kv| Box::new((kv, SingleKV(key, val)))); Ok(()) } - #[cfg(integer128)] fn emit_u128(&mut self, key: Key, val: u128) -> slog::Result { take(&mut self.kv, |kv| Box::new((kv, SingleKV(key, val)))); Ok(()) } - #[cfg(integer128)] fn emit_i128(&mut self, key: Key, val: i128) -> slog::Result { take(&mut self.kv, |kv| Box::new((kv, SingleKV(key, val)))); Ok(()) From 4c924343152420d68727d7cd9bb46b97147d4170 Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 15:00:58 -0700 Subject: [PATCH 4/8] Update to Rust 2018 and fix clippy lints --- CHANGELOG.md | 2 ++ Cargo.toml | 1 + lib.rs | 35 +++++++++++++++++++---------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 410e7ac..dddd377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +* Update to Rust 2018. Does not affect compatibility with crates still using Rust 2015. * Bump MSRV to 1.61 (first time officially defined) * Unconditionally support 128-bit integers. +* Fix all clippy warnings * Setup Github Actions. * Fixup some minor typos in CHANGELOG.md, including an incorrect release date for 2.8.0. diff --git a/Cargo.toml b/Cargo.toml index 220882c..4ef613c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ homepage = "https://github.com/slog-rs/slog" repository = "https://github.com/slog-rs/async" readme = "README.md" rust-version = "1.61" +edition = "2021" [features] nested-values = ["slog/nested-values"] diff --git a/lib.rs b/lib.rs index fa6d24f..7ab8552 100644 --- a/lib.rs +++ b/lib.rs @@ -49,19 +49,24 @@ // {{{ Imports & meta #![warn(missing_docs)] - -#[macro_use] -extern crate slog; -extern crate crossbeam_channel; -extern crate take_mut; -extern crate thread_local; +#![warn( + rust_2018_idioms, + rust_2018_compatibility, + rust_2021_compatibility, + future_incompatible +)] +#![allow( + // covered by mismatched_lifetime_syntaxes + elided_lifetimes_in_paths, +)] use crossbeam_channel::Sender; +use slog::Drain; +use slog::{b, o, record}; use slog::{BorrowedKV, Level, Record, RecordStatic, SingleKV, KV}; use slog::{Key, OwnedKVList, Serializer}; -use slog::Drain; use std::fmt; use std::sync; use std::{io, thread}; @@ -182,7 +187,7 @@ impl Serializer for ToSendSerializer { fn emit_serde( &mut self, key: Key, - value: &slog::SerdeValue, + value: &dyn slog::SerdeValue, ) -> slog::Result { let val = value.to_sendable(); take(&mut self.kv, |kv| Box::new((kv, SingleKV(key, val)))); @@ -441,7 +446,7 @@ impl AsyncCore { ) -> Result< &crossbeam_channel::Sender, std::sync::PoisonError< - sync::MutexGuard>, + sync::MutexGuard<'_, crossbeam_channel::Sender>, >, > { self.tl_sender.get_or_try(|| Ok(self.ref_sender.clone())) @@ -506,7 +511,7 @@ impl AsyncRecord { /// Writes the record to a `Drain`. pub fn log_to(self, drain: &D) -> Result { let rs = RecordStatic { - location: &*self.location, + location: &self.location, level: self.level, tag: &self.tag, }; @@ -524,7 +529,7 @@ impl AsyncRecord { /// Deconstruct this `AsyncRecord` into a record and `OwnedKVList`. pub fn as_record_values(&self, mut f: impl FnMut(&Record, &OwnedKVList)) { let rs = RecordStatic { - location: &*self.location, + location: &self.location, level: self.level, tag: &self.tag, }; @@ -580,6 +585,7 @@ impl Drop for AsyncCore { /// /// More variants may be added in the future, without considering it a breaking change. #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[non_exhaustive] pub enum OverflowStrategy { /// The message gets dropped and a message with number of dropped is produced once there's /// space. @@ -593,8 +599,6 @@ pub enum OverflowStrategy { Drop, /// The caller is blocked until there's enough space. Block, - #[doc(hidden)] - DoNotMatchAgainstThisAndReadTheDocs, } /// `Async` builder @@ -636,9 +640,6 @@ where OverflowStrategy::Block => (true, false), OverflowStrategy::Drop => (false, false), OverflowStrategy::DropAndReport => (false, true), - OverflowStrategy::DoNotMatchAgainstThisAndReadTheDocs => { - panic!("Invalid variant") - } }; AsyncBuilder { core: self.core.blocking(block), @@ -737,6 +738,7 @@ impl Async { /// The wrapped drain must handle all results (`Drain`) /// since there's no way to return it back. See `slog::DrainExt::fuse()` and /// `slog::DrainExt::ignore_res()` for typical error handling strategies. + #[allow(clippy::new_ret_no_self)] // would break compat pub fn new + Send + 'static>( drain: D, ) -> AsyncBuilder { @@ -807,6 +809,7 @@ impl Drop for Async { #[cfg(test)] mod test { use super::*; + use slog::{info, warn}; use std::sync::mpsc; #[test] From b3b50ff3740f848da589d758a4c0127cb1d3a67d Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 15:02:02 -0700 Subject: [PATCH 5/8] ci: Add clippy task, forbidding warnings See also slog-rs/slog#4060ea9 --- .github/workflows/clippy.yml | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/clippy.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..f255071 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,42 @@ +# We use `actions-rs` for most of our actions +on: [push, pull_request] +name: Clippy + +env: + CARGO_TERM_COLOR: always + # has a history of occasional bugs (especially on old versions) + # + # the ci is free so we might as well use it ;) + CARGO_INCREMENTAL: 0 + + +jobs: + clippy: + # Only run on PRs if the source branch is on someone else's repo + if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: + # in hardcoded versions, warnings will fail the build + - 1.89 + # in auto-updated versions, warnings will not fail the build + - stable + - nightly + + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + components: clippy + - name: Clippy + run: | + cargo clippy --all --all-targets --verbose --all-features -- -D warnings + # When using hardcoded/pinned versions, warnings are forbidden. + # + # On automatically updated versions of rust (both stable & nightly) we allow clippy to fail. + # This is because automatic updates can introduce new lints or change existing lints. + continue-on-error: ${{ !contains(matrix.rust, '1.') }} From 7bcbfef0c306ba2a395f32e9ccd4ba8028f345c4 Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 14:47:05 -0700 Subject: [PATCH 6/8] ci: Add rustfmt workflow Based on slog CI config --- .github/workflows/rustfmt.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/rustfmt.yml diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100644 index 0000000..3971261 --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -0,0 +1,24 @@ +# The file is the workflow for rustfmt +# +# It runs `cargo fmt --check` +# +# It will fail if there are formatting problems. +on: [push, pull_request] +name: rustfmt + +env: + CARGO_TERM_COLOR: always + +jobs: + rustfmt: + # Only run on PRs if the source branch is on someone else's repo + if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - shell: bash + run: | + cargo fmt -- --check From f43d7fc9da12fdda347dabec749be3181957de8c Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 14:48:07 -0700 Subject: [PATCH 7/8] ci: Add spellcheck task Based on slog-rs/slog#6b98d9e --- .github/workflows/spellcheck.yml | 20 ++++++++++++++++++++ .typos.toml | 13 +++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .github/workflows/spellcheck.yml create mode 100644 .typos.toml diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml new file mode 100644 index 0000000..601565c --- /dev/null +++ b/.github/workflows/spellcheck.yml @@ -0,0 +1,20 @@ +# Checks spelling with typos +# This has very few false positives, only checking for known misspellings (similar to codespell). +# This action is based on https://github.com/crate-ci/typos/blob/master/docs/github-action.md +name: Check Spelling +on: [push, pull_request] + +env: + CLICOLOR: 1 + +permissions: + contents: read + +jobs: + typos: + name: Check spelling with typos + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run typos (pinned version) + uses: crate-ci/typos@v1.35.1 diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..818bbcd --- /dev/null +++ b/.typos.toml @@ -0,0 +1,13 @@ +[default] +extend-ignore-re = [ + # support spellchecker directives (ideally this would be builtin) + "(?Rm)^.*(#|//)\\s*spellchecker:ignore$", + "(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on", +] + +[files] +ignore-hidden = false +extend-exclude = [ + ".git", # needed because we set 'ignore-hidden' +] + From 30fa9c65aa6725eb922d19f5074ee9691943d97b Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 9 Aug 2025 15:21:39 -0700 Subject: [PATCH 8/8] ci: Cache crates.io index Massively speeds up builds on Rust 1.61 Based on slog-rs/slog#74b944d --- .github/workflows/test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 465d806..38ff84d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,16 @@ jobs: with: toolchain: ${{ matrix.rust }} override: true + - name: Cache Cargo Registry + id: cache-index + uses: actions/cache@v4 + with: + path: + # Before the sparse index, updating the registry took forever + ~/.cargo/registry/index/ + key: ${{ runner.os }}-cargo-${{ matrix.rust }} + restore-keys: | + ${{ runner.os }}-cargo- - name: Check # A failing `cargo check` always ends the build run: |