From 835a2cbbedb51f335ee7b690ed14ed3724cec91e Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 21 Dec 2023 16:16:59 -0300 Subject: [PATCH 1/3] Add `quiet-serde`feature --- macros/Cargo.toml | 1 + ts-rs/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 71555a29d..8336b34ee 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/Aleph-Alpha/ts-rs" [features] serde-compat = ["termcolor"] +quiet-serde = [] [lib] proc-macro = true diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index af1fc1b63..8686916c5 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -24,6 +24,7 @@ default = ["serde-compat"] indexmap-impl = ["indexmap"] ordered-float-impl = ["ordered-float"] heapless-impl = ["heapless"] +quiet-serde = ["ts-rs-macros/quiet-serde"] [dev-dependencies] serde = { version = "1.0", features = ["derive"] } From 9563d5dfe7838f357674e346d735f5e46e29e3db Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 21 Dec 2023 16:17:52 -0300 Subject: [PATCH 2/3] Prevent warnings from `parse_serde_attrs` when using `quiet-serde` feature --- macros/src/utils.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/macros/src/utils.rs b/macros/src/utils.rs index 3b6f1fe48..fbcf062ef 100644 --- a/macros/src/utils.rs +++ b/macros/src/utils.rs @@ -99,7 +99,10 @@ pub fn parse_serde_attrs<'a, A: TryFrom<&'a Attribute, Error = Error>>( .flat_map(|attr| match A::try_from(attr) { Ok(attr) => Some(attr), Err(_) => { + #[cfg(not(feature = "quiet-serde"))] use quote::ToTokens; + + #[cfg(not(feature = "quiet-serde"))] warning::print_warning( "failed to parse serde attribute", format!("{}", attr.to_token_stream()), From 71783fdfa73502222f4c88e15cacfbeff6270259 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 21 Dec 2023 16:19:07 -0300 Subject: [PATCH 3/3] Allow `print_warning` to be unused as the `#![deny(unused)]` attribute in lib.rs was causing a compile error when using `quiet_serde` --- macros/src/utils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/macros/src/utils.rs b/macros/src/utils.rs index fbcf062ef..96946bf08 100644 --- a/macros/src/utils.rs +++ b/macros/src/utils.rs @@ -124,6 +124,7 @@ mod warning { // Sadly, it is impossible to raise a warning in a proc macro. // This function prints a message which looks like a compiler warning. + #[allow(unused)] pub fn print_warning( title: impl Display, content: impl Display,