From 42e0442caaff4e15b7c1787ea19dbfc2583aede7 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Wed, 26 Aug 2026 09:09:54 +0200 Subject: [PATCH 1/3] fix: only implement ManyhowToTokens for quote::ToTokens once --- src/parse_to_tokens.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/parse_to_tokens.rs b/src/parse_to_tokens.rs index bca9906..469ca87 100644 --- a/src/parse_to_tokens.rs +++ b/src/parse_to_tokens.rs @@ -8,12 +8,15 @@ use crate::{ AnyTokenStream, AttributeMacroHandler, DeriveMacroHandler, Emitter, FunctionMacroHandler, ToTokensError, }; + pub trait ManyhowParse { fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result; } + pub trait ManyhowToTokens { fn manyhow_to_tokens(&self, input: T, tokens: &mut TokenStream); } + pub trait ManyhowTry { type Ok; type Err; @@ -70,6 +73,13 @@ impl ManyhowToTokens for WhatType { } } +#[cfg(any(feature = "syn2", feature = "syn3"))] +impl ManyhowToTokens for &WhatType { + fn manyhow_to_tokens(&self, input: T, tokens: &mut TokenStream) { + input.to_tokens(tokens); + } +} + impl ManyhowTry> for WhatType> { type Err = E; type Ok = T; @@ -103,12 +113,6 @@ impl ManyhowParse for &WhatType { }) } } -#[cfg(all(feature = "syn2", not(doc)))] -impl ManyhowToTokens for &WhatType { - fn manyhow_to_tokens(&self, input: T, tokens: &mut TokenStream) { - input.to_tokens(tokens); - } -} #[cfg(all(feature = "syn2", not(doc)))] #[test] @@ -152,12 +156,6 @@ impl ManyhowParse for &WhatType { }) } } -#[cfg(feature = "syn3")] -impl ManyhowToTokens for &WhatType { - fn manyhow_to_tokens(&self, input: T, tokens: &mut TokenStream) { - input.to_tokens(tokens); - } -} #[cfg(feature = "syn3")] #[test] From bb80796c2448125caa55d7ddb72c8968e8e9b2fc Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Wed, 26 Aug 2026 09:10:20 +0200 Subject: [PATCH 2/3] fix: test actual inference `syn2::Ident` and `syn3::Ident` are both re-exports of `proc_macro2::Ident`, so testing whether type inference works correctly with them does not make a lot of sense: both blanket impls cover that type. --- src/parse_to_tokens.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/parse_to_tokens.rs b/src/parse_to_tokens.rs index 469ca87..9f9e931 100644 --- a/src/parse_to_tokens.rs +++ b/src/parse_to_tokens.rs @@ -125,9 +125,9 @@ fn test_inference() { let ts: proc_macro::TokenStream = wt.manyhow_parse(quote::quote!(test), false).unwrap(); let wt = &WhatType::new(); if false { - let wt: Result = wt.identify(); + let wt: Result = wt.identify(); } - let ts: syn2::Ident = wt.manyhow_parse(quote::quote!(test), false).unwrap(); + let ts: syn2::LitInt = wt.manyhow_parse(quote::quote!(test), false).unwrap(); struct Parsable; impl Parse for Parsable { @@ -168,9 +168,9 @@ fn test_inference() { let ts: proc_macro::TokenStream = wt.manyhow_parse(quote::quote!(test), false).unwrap(); let wt = &WhatType::new(); if false { - let wt: Result = wt.identify(); + let wt: Result = wt.identify(); } - let ts: syn3::Ident = wt.manyhow_parse(quote::quote!(test), false).unwrap(); + let ts: syn3::LitInt = wt.manyhow_parse(quote::quote!(test), false).unwrap(); struct Parsable; impl Parse for Parsable { From b658a826090f4200ecd5609e3d455bd0cfb65cbc Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Wed, 26 Aug 2026 09:20:25 +0200 Subject: [PATCH 3/3] compile & test syn2 and syn3 simultaneously --- .github/workflows/test.yaml | 6 +++--- src/lib.rs | 3 ++- src/parse_to_tokens.rs | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ef5c08a..6f67d96 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -38,10 +38,10 @@ jobs: with: crate: cargo-hack - name: Build - run: cargo hack build --feature-powerset --mutually-exclusive-features=syn2,syn3 ${{ matrix.cargo_flags }} + run: cargo hack build --all-features ${{ matrix.cargo_flags }} - name: Test - run: cargo hack test --feature-powerset --mutually-exclusive-features=syn2,syn3 --all-targets --no-fail-fast --workspace + run: cargo hack test --all-features --all-targets --no-fail-fast --workspace - name: Doc Test run: cargo test --features=darling --doc --no-fail-fast --workspace - name: Build Docs - run: cargo doc --all-features --workspace + run: cargo doc --all-features --workspace diff --git a/src/lib.rs b/src/lib.rs index bcdfe5c..3473927 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -276,7 +276,8 @@ macro_rules! __macro_handler { $crate::__macro_handler! {! $name; $($(#attr=$attr)? $n: $input),+; $impl; $crate::__private::Dummy::None} }; (! $name:ident; $($(#attr=$attr:tt)? $n:ident: $input:expr),+; $impl:expr $(; $dummy:expr)?) => {{ - use $crate::__private::{ManyhowParse, ManyhowToTokens, ManyhowTry}; + #[allow(unused_imports)] + use $crate::__private::{ManyhowParse, ManyhowParseSyn2, ManyhowParseSyn3, ManyhowToTokens, ManyhowTry}; let implementation = $impl; $(let $n = &$crate::__private::WhatType::new();)+ if false { diff --git a/src/parse_to_tokens.rs b/src/parse_to_tokens.rs index 9f9e931..283fbba 100644 --- a/src/parse_to_tokens.rs +++ b/src/parse_to_tokens.rs @@ -13,6 +13,14 @@ pub trait ManyhowParse { fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result; } +pub trait ManyhowParseSyn2 { + fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result; +} + +pub trait ManyhowParseSyn3 { + fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result; +} + pub trait ManyhowToTokens { fn manyhow_to_tokens(&self, input: T, tokens: &mut TokenStream); } @@ -99,7 +107,7 @@ impl ManyhowTry for &WhatType { } #[cfg(all(feature = "syn2", not(doc)))] -impl ManyhowParse for &WhatType { +impl ManyhowParseSyn2 for &WhatType { fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result { let input = input.into(); let empty = input.is_empty(); @@ -117,7 +125,7 @@ impl ManyhowParse for &WhatType { #[cfg(all(feature = "syn2", not(doc)))] #[test] #[allow(unused)] -fn test_inference() { +fn syn2_test_inference() { use syn2::parse::Parse; if false { @@ -142,7 +150,7 @@ fn test_inference() { } #[cfg(feature = "syn3")] -impl ManyhowParse for &WhatType { +impl ManyhowParseSyn3 for &WhatType { fn manyhow_parse(&self, input: impl AnyTokenStream, attr: bool) -> Result { let input = input.into(); let empty = input.is_empty(); @@ -160,7 +168,7 @@ impl ManyhowParse for &WhatType { #[cfg(feature = "syn3")] #[test] #[allow(unused)] -fn test_inference() { +fn syn3_test_inference() { use syn3::parse::Parse; if false {