From a1d8b5fb8b4e8999ea4f77e073e6748aee984310 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 19 Dec 2023 15:18:22 +0100 Subject: [PATCH] Fix triggering `str_to_string` lint (#4) * play nice with str_to_string lint * add test against clippy lint --- Cargo.toml | 3 +++ src/lib.rs | 2 +- tests/test.rs | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/test.rs diff --git a/Cargo.toml b/Cargo.toml index b0d60f1..49efe27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,6 @@ exclude = ["modoc.config", "release.toml"] [badges] maintenance = { status = "passively-maintained" } + +[lints.clippy] +str_to_string = "deny" diff --git a/src/lib.rs b/src/lib.rs index 860a4f0..fcdae51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -201,7 +201,7 @@ macro_rules! cfg_aliases { "CARGO_CFG_{}", &stringify!($cfgname).to_uppercase().replace("-", "_") ) - ).unwrap_or("".to_string()).split(",").find(|x| x == &$cfgvalue).is_some() + ).unwrap_or("".to_owned()).split(",").find(|x| x == &$cfgvalue).is_some() }; // Emitting `any(clause1,clause2,...)`: convert to `$crate::cfg_aliases!(clause1) && $crate::cfg_aliases!(clause2) && ...` diff --git a/tests/test.rs b/tests/test.rs new file mode 100644 index 0000000..7af4ca5 --- /dev/null +++ b/tests/test.rs @@ -0,0 +1,20 @@ +use cfg_aliases::cfg_aliases; + +#[test] +fn basic_setup() { + // Same as in the docs. + // Note that tests build this already, but unfortunately this doesn't catch clippy lints! + // See https://github.com/rust-lang/rust/issues/56232 + cfg_aliases! { + // Platforms + wasm: { target_arch = "wasm32" }, + android: { target_os = "android" }, + macos: { target_os = "macos" }, + linux: { target_os = "linux" }, + // Backends + surfman: { all(unix, feature = "surfman", not(wasm)) }, + glutin: { all(feature = "glutin", not(wasm)) }, + wgl: { all(windows, feature = "wgl", not(wasm)) }, + dummy: { not(any(wasm, glutin, wgl, surfman)) }, + }; +}