From dd71956b26a984f1a6a98fb0e5e74c50ae9c1ec6 Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 10:22:03 -0700 Subject: [PATCH 1/7] ci: Update the 'recent hardcoded version' to 1.81 This is used for clippy lints. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98eca2d0..45a921a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: # # This is used so that clippy & tests are run on a reliable reference point. # If clippy has any warnings, this will fail the build (we run with --deny warnings) - - 1.72 + - 1.81 # The most recent version of stable rust (automatically updated) # # Sometimes, this is exactly the same as the hardcoded right above. From 98c97c8cdf4bf588d82f4ac24c039c4b618964ea Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 07:53:10 -0700 Subject: [PATCH 2/7] build: Avoid check-cfg lint in 1.81.0 Config names are now validated at compile time: https://blog.rust-lang.org/2024/05/06/check-cfg.html --- CHANGELOG.md | 3 +++ build.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5a70d2..734854ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +* Fix some internal warnings + * Example: Avoid the new [`#[warn(unexpected_cfgs)]`](https://blog.rust-lang.org/2024/05/06/check-cfg.html) lint. + * None of these should affect user crates ### 2.8.0-beta.2 - 2024-01-05 diff --git a/build.rs b/build.rs index d9cfa836..aa3a07b8 100644 --- a/build.rs +++ b/build.rs @@ -20,4 +20,10 @@ fn main() { if !is_emscripten { println!("cargo:rustc-cfg=integer128"); } + + // In Rust 1.80, cfg names are validated at compile time + // See blog: https://blog.rust-lang.org/2024/05/06/check-cfg.html + // + // On prior versions, this directive is ignored. + println!("cargo:rustc-check-cfg=cfg(integer128)"); } From 24a2e998fcd71ffacd492aace9226dd0b2014eae Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 07:54:11 -0700 Subject: [PATCH 3/7] Rename ./cargo/config to .cargo/config.toml This avoids the following warning: ``` warning: `/Users/nicholas/git/slog.org/slog/.cargo/config` is deprecated in favor of `config.toml` note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` ``` Since our MSRV is currently 1.49, we can safely make this change without needing a system link. --- .cargo/{config => config.toml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .cargo/{config => config.toml} (100%) diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml From 5004dc9f2634aafed2040f14d9bd716801201464 Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 07:56:13 -0700 Subject: [PATCH 4/7] test_edition2018: Explicitly specify edition = "2018" Avoids a cargo warning --- crates/test_edition2018/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/test_edition2018/Cargo.toml b/crates/test_edition2018/Cargo.toml index 323814cb..e94e8685 100644 --- a/crates/test_edition2018/Cargo.toml +++ b/crates/test_edition2018/Cargo.toml @@ -2,6 +2,7 @@ name = "test_edition2018" version = "0.0.0" description = "A crate for testing 2018-style macro imports" +edition = "2018" authors = ["Yusuke Sasaki "] publish = false From c0b05f662a5916d21efb9c542ae5cc55fedbeefa Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 08:01:46 -0700 Subject: [PATCH 5/7] Remove unused `extern crate` declarations These declarations are not needed. This avoids the #[deny(unused_extern_crates)] lint, implied by #[deny(rust_2018_idioms)] This error only occurs when the `nested-values` feature is enabled. This error also seems to only occur on new versions (ex. 1.72 is fine). Switch #[deny(rust_2018_idioms)] to #[warn(...)] to avoid unnecessary build failures in the future. --- CHANGELOG.md | 3 +++ src/lib.rs | 7 +------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 734854ae..827db825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * Fix some internal warnings * Example: Avoid the new [`#[warn(unexpected_cfgs)]`](https://blog.rust-lang.org/2024/05/06/check-cfg.html) lint. * None of these should affect user crates +* nested-values: Fix CI failure caused by `#[deny(unused_extern_crates)]` lint + * Switch `#[deny(rust_2018_idioms)]` to `#[warn(...)]` to avoid unnecessary build failures in the future. + * I don't *think* this should affect user code. ### 2.8.0-beta.2 - 2024-01-05 diff --git a/src/lib.rs b/src/lib.rs index e5fd15b2..454a2ce8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,7 +278,7 @@ // {{{ Imports & meta #![warn(missing_docs)] -#![deny(rust_2018_idioms)] +#![warn(rust_2018_idioms)] #![no_std] #[cfg(not(feature = "std"))] @@ -300,11 +300,6 @@ use alloc::string::String; #[cfg(not(feature = "std"))] use alloc::{sync::Arc, vec::Vec}; -#[cfg(feature = "nested-values")] -extern crate erased_serde; -#[cfg(feature = "nested-values")] -extern crate serde; - use core::str::FromStr; use core::{convert, fmt, result}; #[cfg(feature = "std")] From 7554cb964a085b260e2a0232c6297478b53cadfc Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 08:12:47 -0700 Subject: [PATCH 6/7] Unconditionally import from alloc/core Instead of doing this: ``` #[cfg(not(feature = "std"))] use alloc::borrow::Cow; #[cfg(feature = "std")] use std::borrow::Cow; ``` Just unconditionally import from alloc: ``` use alloc::borrow::Cow; ``` Enable #[warn(clippy::std_instead_of_alloc, clippy::std_instead_of_core)] to warn about these imports in the future. Conditionally declare #[no_std] if and only if not(cfg(feature = "std")) This is cleaner and avoids an `extern crate std` declaration, but semantically there should be no difference. --- src/key/dynamic.rs | 25 ------------------------- src/lib.rs | 36 +++++++++++------------------------- src/tests.rs | 6 +++--- 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/src/key/dynamic.rs b/src/key/dynamic.rs index d359d528..273d527e 100644 --- a/src/key/dynamic.rs +++ b/src/key/dynamic.rs @@ -1,37 +1,12 @@ -#[cfg(not(feature = "std"))] use alloc::borrow::Cow; -#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; -#[cfg(not(feature = "std"))] use core::clone::Clone; -#[cfg(not(feature = "std"))] use core::cmp::PartialEq; -#[cfg(not(feature = "std"))] use core::convert::{AsRef, From}; -#[cfg(not(feature = "std"))] use core::fmt; -#[cfg(not(feature = "std"))] use core::hash::{Hash, Hasher}; -#[cfg(not(feature = "std"))] use core::iter::{FromIterator, IntoIterator}; -#[cfg(feature = "std")] -use std::borrow::Cow; -#[cfg(feature = "std")] -use std::cmp::PartialEq; -#[cfg(feature = "std")] -use std::convert::{AsRef, From}; -#[cfg(feature = "std")] -use std::fmt; -#[cfg(feature = "std")] -use std::hash::{Hash, Hasher}; -#[cfg(feature = "std")] -use std::iter::{FromIterator, IntoIterator}; -#[cfg(feature = "std")] -use std::string::String; -#[cfg(feature = "std")] -use std::string::ToString; - /// Opaque Key is a representation of a key. /// /// It is owned, and largely forms a contract for diff --git a/src/lib.rs b/src/lib.rs index 454a2ce8..b18be20e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,41 +279,27 @@ // {{{ Imports & meta #![warn(missing_docs)] #![warn(rust_2018_idioms)] -#![no_std] +#![warn( + // Use `core` and `alloc` instead of `std` wherever possible + clippy::alloc_instead_of_core, + clippy::std_instead_of_core, + clippy::std_instead_of_alloc, +)] +#![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; -#[macro_use] -#[cfg(feature = "std")] -extern crate std; mod key; pub use self::key::Key; -#[cfg(not(feature = "std"))] + use alloc::borrow::{Cow, ToOwned}; -#[cfg(not(feature = "std"))] use alloc::boxed::Box; -#[cfg(not(feature = "std"))] use alloc::rc::Rc; -#[cfg(not(feature = "std"))] use alloc::string::String; -#[cfg(not(feature = "std"))] use alloc::{sync::Arc, vec::Vec}; use core::str::FromStr; use core::{convert, fmt, result}; -#[cfg(feature = "std")] -use std::borrow::{Cow, ToOwned}; -#[cfg(feature = "std")] -use std::boxed::Box; -#[cfg(feature = "std")] -use std::rc::Rc; -#[cfg(feature = "std")] -use std::string::String; -#[cfg(feature = "std")] -use std::sync::Arc; -#[cfg(feature = "std")] -use std::vec::Vec; // }}} // {{{ Macros @@ -2434,7 +2420,7 @@ fn filter_level_to_string_and_from_str_are_compatible() { #[cfg(all(test, feature = "std"))] fn assert_to_string_from_str(expected: T) where - T: std::string::ToString + FromStr + PartialEq + fmt::Debug, + T: alloc::string::ToString + FromStr + PartialEq + fmt::Debug, ::Err: fmt::Debug, { let string = expected.to_string(); @@ -3926,7 +3912,7 @@ pub enum Error { /// `io::Error` (not available in ![no_std] mode) Io(std::io::Error), /// `fmt::Error` - Fmt(std::fmt::Error), + Fmt(core::fmt::Error), /// Other error Other, } @@ -3996,7 +3982,7 @@ impl std::error::Error for Error { #[cfg(feature = "std")] impl core::fmt::Display for Error { - fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match *self { Error::Io(ref e) => e.fmt(fmt), Error::Fmt(ref e) => e.fmt(fmt), diff --git a/src/tests.rs b/src/tests.rs index dce4456e..8d503350 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -34,7 +34,7 @@ mod std_only { &self, record: &Record<'_>, values: &OwnedKVList, - ) -> std::result::Result { + ) -> core::result::Result { struct ErrorSerializer(String); impl Serializer for ErrorSerializer { @@ -66,7 +66,7 @@ mod std_only { } #[derive(Debug)] - struct TestError(&'static str, Option); + struct TestError(&'static str, Option); impl TestError { fn new(message: &'static str) -> Self { @@ -112,7 +112,7 @@ mod std_only { &self, record: &Record<'_>, values: &OwnedKVList, - ) -> std::result::Result { + ) -> core::result::Result { assert_eq!( format!("{}", record.msg()), format!("{:?}", values) From 4e24c23c2255d937ae2ef95412199ddc18f5d365 Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 23 Sep 2024 08:18:09 -0700 Subject: [PATCH 7/7] doc: Fix "lazy continuation" in slog::Logger This is a mistake in markdown syntax, caught by a clippy lint: https://rust-lang.github.io/rust-clippy/rust-1.81.0/index.html#/doc_lazy_continuation --- CHANGELOG.md | 2 ++ src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 827db825..73af3604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +* doc: Fix "lazy continuation" in `slog::Logger` doc + * This mistake was caught by a new lint [`#[warn(clippy::doc_lazy_continuation)]`](https://rust-lang.github.io/rust-clippy/rust-1.81.0/index.html#/doc_lazy_continuation) * Fix some internal warnings * Example: Avoid the new [`#[warn(unexpected_cfgs)]`](https://blog.rust-lang.org/2024/05/06/check-cfg.html) lint. * None of these should affect user crates diff --git a/src/lib.rs b/src/lib.rs index b18be20e..7fe6c404 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1069,7 +1069,7 @@ macro_rules! __slog_builtin { /// In an essence `Logger` instance holds two pieces of information: /// /// * drain - destination where to forward logging `Record`s for -/// processing. +/// processing. /// * context - list of key-value pairs associated with it. /// /// The root `Logger` is created with a `Drain` that will be cloned to every