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 bca9906..283fbba 100644 --- a/src/parse_to_tokens.rs +++ b/src/parse_to_tokens.rs @@ -8,12 +8,23 @@ use crate::{ AnyTokenStream, AttributeMacroHandler, DeriveMacroHandler, Emitter, FunctionMacroHandler, ToTokensError, }; + 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); } + pub trait ManyhowTry { type Ok; type Err; @@ -70,6 +81,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; @@ -89,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(); @@ -103,17 +121,11 @@ 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] #[allow(unused)] -fn test_inference() { +fn syn2_test_inference() { use syn2::parse::Parse; if false { @@ -121,9 +133,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 { @@ -138,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(); @@ -152,17 +164,11 @@ 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] #[allow(unused)] -fn test_inference() { +fn syn3_test_inference() { use syn3::parse::Parse; if false { @@ -170,9 +176,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 {