From af88321fc14a95b3613ec11a7f665db3c468c944 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 1 Oct 2023 21:15:00 +0200 Subject: refactor: remove impossible unwrap in injectable macro This unwrap couldn't possibly be Err and can be removed by creating method call expressions by hand --- macros/src/util/syn_path.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'macros/src/util/syn_path.rs') diff --git a/macros/src/util/syn_path.rs b/macros/src/util/syn_path.rs index 88182cc..26e2597 100644 --- a/macros/src/util/syn_path.rs +++ b/macros/src/util/syn_path.rs @@ -32,3 +32,29 @@ impl SynPathExt for syn::Path ) } } + +macro_rules! syn_path { + ($first_segment: ident $(::$segment: ident)*) => { + ::syn::Path { + leading_colon: None, + segments: ::syn::punctuated::Punctuated::from_iter([ + $crate::util::syn_path::syn_path_segment!($first_segment), + $($crate::util::syn_path::syn_path_segment!($segment),)* + ]) + } + }; +} + +macro_rules! syn_path_segment { + ($segment: ident) => { + ::syn::PathSegment { + ident: ::proc_macro2::Ident::new( + stringify!($segment), + ::proc_macro2::Span::call_site(), + ), + arguments: ::syn::PathArguments::None, + } + }; +} + +pub(crate) use {syn_path, syn_path_segment}; -- cgit v1.2.3-18-g5258