diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
commit | a0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch) | |
tree | fc451898ccaf445814e26b46664d78702178101d /vendor/time-macros/src | |
parent | Adding debian version 1.71.1+dfsg1-2. (diff) | |
download | rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time-macros/src')
-rw-r--r-- | vendor/time-macros/src/format_description/ast.rs | 42 | ||||
-rw-r--r-- | vendor/time-macros/src/lib.rs | 50 | ||||
-rw-r--r-- | vendor/time-macros/src/offset.rs | 5 | ||||
-rw-r--r-- | vendor/time-macros/src/quote.rs | 1 | ||||
-rw-r--r-- | vendor/time-macros/src/serde_format_description.rs | 25 | ||||
-rw-r--r-- | vendor/time-macros/src/shim.rs | 117 | ||||
-rw-r--r-- | vendor/time-macros/src/time.rs | 9 |
7 files changed, 73 insertions, 176 deletions
diff --git a/vendor/time-macros/src/format_description/ast.rs b/vendor/time-macros/src/format_description/ast.rs index 497c8965d..f33c6d433 100644 --- a/vendor/time-macros/src/format_description/ast.rs +++ b/vendor/time-macros/src/format_description/ast.rs @@ -127,24 +127,24 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons ) -> Result<Item<'a>, Error> { let leading_whitespace = tokens.next_if_whitespace(); - guard!(let Some(name) = tokens.next_if_not_whitespace() else { + let Some(name) = tokens.next_if_not_whitespace() else { let span = match leading_whitespace { Some(Spanned { value: _, span }) => span, None => opening_bracket.to(opening_bracket), }; return Err(span.error("expected component name")); - }); + }; if *name == b"optional" { - guard!(let Some(whitespace) = tokens.next_if_whitespace() else { + let Some(whitespace) = tokens.next_if_whitespace() else { return Err(name.span.error("expected whitespace after `optional`")); - }); + }; let nested = parse_nested::<_, VERSION>(whitespace.span.end, tokens)?; - guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else { + let Some(closing_bracket) = tokens.next_if_closing_bracket() else { return Err(opening_bracket.error("unclosed bracket")); - }); + }; return Ok(Item::Optional { opening_bracket, @@ -157,18 +157,18 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons } if *name == b"first" { - guard!(let Some(whitespace) = tokens.next_if_whitespace() else { + let Some(whitespace) = tokens.next_if_whitespace() else { return Err(name.span.error("expected whitespace after `first`")); - }); + }; let mut nested_format_descriptions = Vec::new(); while let Ok(description) = parse_nested::<_, VERSION>(whitespace.span.end, tokens) { nested_format_descriptions.push(description); } - guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else { + let Some(closing_bracket) = tokens.next_if_closing_bracket() else { return Err(opening_bracket.error("unclosed bracket")); - }); + }; return Ok(Item::First { opening_bracket, @@ -182,7 +182,7 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons let mut modifiers = Vec::new(); let trailing_whitespace = loop { - guard!(let Some(whitespace) = tokens.next_if_whitespace() else { break None }); + let Some(whitespace) = tokens.next_if_whitespace() else { break None }; if let Some(location) = tokens.next_if_opening_bracket() { return Err(location @@ -190,13 +190,13 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons .error("modifier must be of the form `key:value`")); } - guard!(let Some(Spanned { value, span }) = tokens.next_if_not_whitespace() else { + let Some(Spanned { value, span }) = tokens.next_if_not_whitespace() else { break Some(whitespace); - }); + }; - guard!(let Some(colon_index) = value.iter().position(|&b| b == b':') else { + let Some(colon_index) = value.iter().position(|&b| b == b':') else { return Err(span.error("modifier must be of the form `key:value`")); - }); + }; let key = &value[..colon_index]; let value = &value[colon_index + 1..]; @@ -215,9 +215,9 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons }); }; - guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else { + let Some(closing_bracket) = tokens.next_if_closing_bracket() else { return Err(opening_bracket.error("unclosed bracket")); - }); + }; Ok(Item::Component { _opening_bracket: unused(opening_bracket), @@ -233,13 +233,13 @@ fn parse_nested<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, const V last_location: Location, tokens: &mut lexer::Lexed<I>, ) -> Result<NestedFormatDescription<'a>, Error> { - guard!(let Some(opening_bracket) = tokens.next_if_opening_bracket() else { + let Some(opening_bracket) = tokens.next_if_opening_bracket() else { return Err(last_location.error("expected opening bracket")); - }); + }; let items = parse_inner::<_, true, VERSION>(tokens).collect::<Result<_, _>>()?; - guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else { + let Some(closing_bracket) = tokens.next_if_closing_bracket() else { return Err(opening_bracket.error("unclosed bracket")); - }); + }; let trailing_whitespace = tokens.next_if_whitespace(); Ok(NestedFormatDescription { diff --git a/vendor/time-macros/src/lib.rs b/vendor/time-macros/src/lib.rs index 84ad25113..ce62ac5be 100644 --- a/vendor/time-macros/src/lib.rs +++ b/vendor/time-macros/src/lib.rs @@ -42,9 +42,6 @@ macro_rules! bug { #[macro_use] mod quote; -#[cfg(any(feature = "formatting", feature = "parsing"))] -#[macro_use] -mod shim; mod date; mod datetime; @@ -231,36 +228,41 @@ pub fn serde_format_description(input: TokenStream) -> TokenStream { // We now have two options. The user can either provide a format description as a string or // they can provide a path to a format description. If the latter, all remaining tokens are // assumed to be part of the path. - let (format, raw_format_string) = match tokens.peek() { + let (format, format_description_display) = match tokens.peek() { // string literal Some(TokenTree::Literal(_)) => { let (span, format_string) = helpers::get_string_literal(tokens)?; let items = format_description::parse_with_version(version, &format_string, span)?; let items: TokenStream = items.into_iter().map(|item| quote! { #S(item), }).collect(); - let items = quote! { &[#S(items)] }; + let items = quote! { + const ITEMS: &[::time::format_description::FormatItem<'_>] = &[#S(items)]; + ITEMS + }; + (items, String::from_utf8_lossy(&format_string).into_owned()) + } + // path + Some(_) => { + let tokens = tokens.collect::<TokenStream>(); + let tokens_string = tokens.to_string(); ( - items, - Some(String::from_utf8_lossy(&format_string).into_owned()), + 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, ) } - // path - Some(_) => ( - 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.collect::<TokenStream>()) as FORMAT; - } - __path_hack::FORMAT - }}, - None, - ), None => return Err(Error::UnexpectedEndOfInput), }; @@ -268,7 +270,7 @@ pub fn serde_format_description(input: TokenStream) -> TokenStream { mod_name, formattable, format, - raw_format_string, + format_description_display, )) })() .unwrap_or_else(|err: Error| err.to_compile_error_standalone()) diff --git a/vendor/time-macros/src/offset.rs b/vendor/time-macros/src/offset.rs index c2099073f..62d7a223d 100644 --- a/vendor/time-macros/src/offset.rs +++ b/vendor/time-macros/src/offset.rs @@ -1,6 +1,7 @@ use std::iter::Peekable; use proc_macro::{token_stream, Span, TokenTree}; +use time_core::convert::*; use crate::helpers::{consume_any_ident, consume_number, consume_punct}; use crate::to_tokens::ToTokenTree; @@ -58,14 +59,14 @@ pub(crate) fn parse(chars: &mut Peekable<token_stream::IntoIter>) -> Result<Offs span_start: Some(hours_span), span_end: Some(hours_span), }) - } else if minutes >= 60 { + } else if minutes >= Minute.per(Hour) as _ { Err(Error::InvalidComponent { name: "minute", value: minutes.to_string(), span_start: Some(minutes_span), span_end: Some(minutes_span), }) - } else if seconds >= 60 { + } else if seconds >= Second.per(Minute) as _ { Err(Error::InvalidComponent { name: "second", value: seconds.to_string(), diff --git a/vendor/time-macros/src/quote.rs b/vendor/time-macros/src/quote.rs index 295abe115..4d3dcbca0 100644 --- a/vendor/time-macros/src/quote.rs +++ b/vendor/time-macros/src/quote.rs @@ -67,6 +67,7 @@ macro_rules! quote_inner { ($ts:ident ! $($tail:tt)*) => { sym!($ts '!'); quote_inner!($ts $($tail)*); }; ($ts:ident | $($tail:tt)*) => { sym!($ts '|'); quote_inner!($ts $($tail)*); }; ($ts:ident * $($tail:tt)*) => { sym!($ts '*'); quote_inner!($ts $($tail)*); }; + ($ts:ident + $($tail:tt)*) => { sym!($ts '+'); quote_inner!($ts $($tail)*); }; // Identifier ($ts:ident $i:ident $($tail:tt)*) => { diff --git a/vendor/time-macros/src/serde_format_description.rs b/vendor/time-macros/src/serde_format_description.rs index c09a4e9e2..1d2f2e2c1 100644 --- a/vendor/time-macros/src/serde_format_description.rs +++ b/vendor/time-macros/src/serde_format_description.rs @@ -4,12 +4,10 @@ pub(crate) fn build( mod_name: Ident, ty: TokenTree, format: TokenStream, - raw_format_string: Option<String>, + format_description_display: String, ) -> TokenStream { let ty_s = &*ty.to_string(); - let format_description_display = raw_format_string.unwrap_or_else(|| format.to_string()); - let visitor = if cfg!(feature = "parsing") { quote! { struct Visitor; @@ -34,7 +32,7 @@ pub(crate) fn build( self, value: &str ) -> Result<__TimeSerdeType, E> { - __TimeSerdeType::parse(value, &DESCRIPTION).map_err(E::custom) + __TimeSerdeType::parse(value, &description()).map_err(E::custom) } } @@ -81,7 +79,7 @@ pub(crate) fn build( ) -> Result<S::Ok, S::Error> { use ::serde::Serialize; datetime - .format(&DESCRIPTION) + .format(&description()) .map_err(::time::error::Format::into_invalid_serde_value::<S>)? .serialize(serializer) } @@ -110,7 +108,7 @@ pub(crate) fn build( serializer: S, ) -> Result<S::Ok, S::Error> { use ::serde::Serialize; - option.map(|datetime| datetime.format(&DESCRIPTION)) + option.map(|datetime| datetime.format(&description())) .transpose() .map_err(::time::error::Format::into_invalid_serde_value::<S>)? .serialize(serializer) @@ -141,18 +139,29 @@ pub(crate) fn build( quote!() }; + let fd_traits = match (cfg!(feature = "formatting"), cfg!(feature = "parsing")) { + (false, false) => { + bug!("serde_format_description::build called without formatting or parsing enabled") + } + (false, true) => quote! { ::time::parsing::Parsable }, + (true, false) => quote! { ::time::formatting::Formattable }, + (true, true) => quote! { ::time::formatting::Formattable + ::time::parsing::Parsable }, + }; + quote! { mod #(mod_name) { use ::time::#(ty) as __TimeSerdeType; - const DESCRIPTION: &[::time::format_description::FormatItem<'_>] = #S(format); + const fn description() -> impl #S(fd_traits) { + #S(format) + } #S(visitor) #S(serialize_primary) #S(deserialize_primary) pub(super) mod option { - use super::{DESCRIPTION, __TimeSerdeType}; + use super::{description, __TimeSerdeType}; #S(deserialize_option_imports) #S(serialize_option) diff --git a/vendor/time-macros/src/shim.rs b/vendor/time-macros/src/shim.rs deleted file mode 100644 index f31e5d501..000000000 --- a/vendor/time-macros/src/shim.rs +++ /dev/null @@ -1,117 +0,0 @@ -#![allow(unused_macros)] - -// The following code is copyright 2016 Alex Burka. Available under the MIT OR Apache-2.0 license. -// Some adaptations have been made to the original code. - -pub(crate) enum LetElseBodyMustDiverge {} - -#[allow(clippy::missing_docs_in_private_items)] -macro_rules! __guard_output { - ((($($imms:ident)*) ($($muts:ident)*)), - [($($pattern:tt)*) ($rhs:expr) ($diverge:expr)]) => { - __guard_impl!(@as_stmt - let ($($imms,)* $(mut $muts,)*) = { - #[allow(unused_mut)] - match $rhs { - $($pattern)* => { - ($($imms,)* $($muts,)*) - }, - _ => { - let _: $crate::shim::LetElseBodyMustDiverge = $diverge; - }, - } - } - ) - }; -} - -macro_rules! __guard_impl { - (@as_stmt $s:stmt) => { $s }; - (@collect () -> $($rest:tt)*) => { - __guard_output!($($rest)*) - }; - (@collect (($($inside:tt)*) $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($inside)* $($tail)*) -> $idents, $thru) - }; - (@collect ({$($inside:tt)*} $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($inside)* $($tail)*) -> $idents, $thru) - }; - (@collect ([$($inside:tt)*] $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($inside)* $($tail)*) -> $idents, $thru) - }; - (@collect (, $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (.. $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (@ $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (_ $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (& $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (:: <$($generic:tt),*> $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (:: $pathend:ident $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect (| $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect () -> $idents, $thru) - }; - (@collect ($id:ident: $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect ($pathcomp:ident :: $pathend:ident $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> $idents, $thru) - }; - (@collect ($id:ident ($($inside:tt)*) $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($inside)* $($tail)*) -> $idents, $thru) - }; - (@collect ($id:ident {$($inside:tt)*} $($tail:tt)*) -> $idents:tt, $thru:tt) => { - __guard_impl!(@collect ($($inside)* $($tail)*) -> $idents, $thru) - }; - (@collect (ref mut $id:ident $($tail:tt)*) -> (($($imms:ident)*) $muts:tt), $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> (($($imms)* $id) $muts), $thru) - }; - (@collect (ref $id:ident $($tail:tt)*) -> (($($imms:ident)*) $muts:tt), $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> (($($imms)* $id) $muts), $thru) - }; - (@collect (mut $id:ident $($tail:tt)*) -> ($imms:tt ($($muts:ident)*)), $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> ($imms ($($muts)* $id)), $thru) - }; - (@collect ($id:ident $($tail:tt)*) -> (($($imms:ident)*) $muts:tt), $thru:tt) => { - __guard_impl!(@collect ($($tail)*) -> (($($imms)* $id) $muts), $thru) - }; - (@split (else { $($diverge:tt)* } = $($tail:tt)*) -> ($pat:tt)) => { - __guard_impl!(@collect $pat -> (() ()), [$pat ($($tail)*) ({ $($diverge)* })]) - }; - (@split (= $($tail:tt)*) -> ($pat:tt)) => { - __guard_impl!(@split expr ($($tail)*) -> ($pat ())) - }; - (@split ($head:tt $($tail:tt)*) -> (($($pat:tt)*))) => { - __guard_impl!(@split ($($tail)*) -> (($($pat)* $head))) - }; - (@split expr (else { $($tail:tt)* }) -> ($pat:tt $expr:tt)) => { - __guard_impl!(@collect $pat -> (() ()), [$pat $expr ({ $($tail)* })]) - }; - (@split expr (else { $($body:tt)* } $($tail:tt)*) -> ($pat:tt ($($expr:tt)*))) => { - __guard_impl!(@split expr ($($tail)*) -> ($pat ($($expr)* else { $($body)* }))) - }; - (@split expr ($head:tt $($tail:tt)*) -> ($pat:tt ($($expr:tt)*))) => { - __guard_impl!(@split expr ($($tail)*) -> ($pat ($($expr)* $head))) - }; - (let $($tail:tt)*) => { - __guard_impl!(@split ($($tail)*) -> (())) - }; -} - -macro_rules! guard { - ($($input:tt)*) => { - __guard_impl!($($input)*) - }; -} diff --git a/vendor/time-macros/src/time.rs b/vendor/time-macros/src/time.rs index 719e2051f..96314de1f 100644 --- a/vendor/time-macros/src/time.rs +++ b/vendor/time-macros/src/time.rs @@ -1,6 +1,7 @@ use std::iter::Peekable; use proc_macro::{token_stream, Span, TokenTree}; +use time_core::convert::*; use crate::helpers::{consume_any_ident, consume_number, consume_punct}; use crate::to_tokens::ToTokenTree; @@ -72,21 +73,21 @@ pub(crate) fn parse(chars: &mut Peekable<token_stream::IntoIter>) -> Result<Time (hour, Period::Pm) => hour + 12, }; - if hour >= 24 { + if hour >= Hour.per(Day) { Err(Error::InvalidComponent { name: "hour", value: hour.to_string(), span_start: Some(hour_span), span_end: Some(period_span.unwrap_or(hour_span)), }) - } else if minute >= 60 { + } else if minute >= Minute.per(Hour) { Err(Error::InvalidComponent { name: "minute", value: minute.to_string(), span_start: Some(minute_span), span_end: Some(minute_span), }) - } else if second >= 60. { + } else if second >= Second.per(Minute) as _ { Err(Error::InvalidComponent { name: "second", value: second.to_string(), @@ -98,7 +99,7 @@ pub(crate) fn parse(chars: &mut Peekable<token_stream::IntoIter>) -> Result<Time hour, minute, second: second.trunc() as _, - nanosecond: (second.fract() * 1_000_000_000.).round() as _, + nanosecond: (second.fract() * Nanosecond.per(Second) as f64).round() as _, }) } } |