diff --git a/tests/serde/macros.rs b/tests/serde/macros.rs index 6a02344f4..b58a51311 100644 --- a/tests/serde/macros.rs +++ b/tests/serde/macros.rs @@ -14,6 +14,11 @@ use time::{serde, Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; const ISO_FORMAT: Iso8601<{ iso8601::Config::DEFAULT.encode() }> = Iso8601::<{ iso8601::Config::DEFAULT.encode() }>; time::serde::format_description!(my_format, OffsetDateTime, ISO_FORMAT); +time::serde::format_description!( + my_format2, + OffsetDateTime, + Iso8601::<{ iso8601::Config::DEFAULT.encode() }> +); serde::format_description!( offset_dt_format, @@ -37,6 +42,11 @@ serde::format_description!( const TIME_FORMAT_ALT: &[BorrowedFormatItem<'_>] = time::macros::format_description!("[hour]:[minute]"); serde::format_description!(time_format_alt, Time, TIME_FORMAT_ALT); +serde::format_description!( + time_format_alt2, + Time, + time::macros::format_description!("[hour]:[minute]") +); #[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] struct TestCustomFormat { diff --git a/time-macros/src/lib.rs b/time-macros/src/lib.rs index 65e24d7d3..d97b44060 100644 --- a/time-macros/src/lib.rs +++ b/time-macros/src/lib.rs @@ -223,22 +223,7 @@ pub fn serde_format_description(input: TokenStream) -> TokenStream { Some(_) => { let tokens = tokens.collect::(); let tokens_string = tokens.to_string(); - ( - quote! {{ - // We can't just do `super::path` because the path could be an absolute - // path. In that case, we'd be generating `super::::path`, which is invalid. - // Even if we took that into account, it's not possible to know if it's an - // external crate, which would just require emitting `path` directly. By - // taking this approach, we can leave it to the compiler to do the actual - // resolution. - mod __path_hack { - pub(super) use super::super::*; - pub(super) use #S(tokens) as FORMAT; - } - __path_hack::FORMAT - }}, - tokens_string, - ) + (tokens, tokens_string) } None => return Err(Error::UnexpectedEndOfInput), }; diff --git a/time-macros/src/serde_format_description.rs b/time-macros/src/serde_format_description.rs index 34b99f679..93b727f97 100644 --- a/time-macros/src/serde_format_description.rs +++ b/time-macros/src/serde_format_description.rs @@ -150,6 +150,8 @@ pub(crate) fn build( quote! { mod #(mod_name) { + use super::*; + // TODO Remove the prefix, forcing the user to import the type themself. use ::time::#(ty) as __TimeSerdeType; const fn description() -> impl #S(fd_traits) {