From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/syn/src/punctuated.rs | 112 ++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 54 deletions(-) (limited to 'vendor/syn/src/punctuated.rs') diff --git a/vendor/syn/src/punctuated.rs b/vendor/syn/src/punctuated.rs index b7d0185e8..7880eb29c 100644 --- a/vendor/syn/src/punctuated.rs +++ b/vendor/syn/src/punctuated.rs @@ -26,7 +26,6 @@ use std::fmt::{self, Debug}; use std::hash::{Hash, Hasher}; #[cfg(any(feature = "full", feature = "derive"))] use std::iter; -use std::iter::FromIterator; use std::ops::{Index, IndexMut}; use std::option; use std::slice; @@ -38,8 +37,8 @@ use crate::parse::{Parse, ParseStream, Result}; #[cfg(feature = "parsing")] use crate::token::Token; -/// A punctuated sequence of syntax tree nodes of type `T` separated by -/// punctuation of type `P`. +/// **A punctuated sequence of syntax tree nodes of type `T` separated by +/// punctuation of type `P`.** /// /// Refer to the [module documentation] for details about punctuated sequences. /// @@ -51,7 +50,6 @@ pub struct Punctuated { impl Punctuated { /// Creates an empty punctuated sequence. - #[cfg(not(syn_no_const_vec_new))] pub const fn new() -> Self { Punctuated { inner: Vec::new(), @@ -59,15 +57,6 @@ impl Punctuated { } } - /// Creates an empty punctuated sequence. - #[cfg(syn_no_const_vec_new)] - pub fn new() -> Self { - Punctuated { - inner: Vec::new(), - last: None, - } - } - /// Determines whether this punctuated sequence is empty, meaning it /// contains no syntax tree nodes or punctuation. pub fn is_empty(&self) -> bool { @@ -151,7 +140,7 @@ impl Punctuated { } /// Appends a syntax tree node onto the end of this punctuated sequence. The - /// sequence must previously have a trailing punctuation. + /// sequence must already have a trailing punctuation, or be empty. /// /// Use [`push`] instead if the punctuated sequence may or may not already /// have trailing punctuation. @@ -160,8 +149,8 @@ impl Punctuated { /// /// # Panics /// - /// Panics if the sequence does not already have a trailing punctuation when - /// this method is called. + /// Panics if the sequence is nonempty and does not already have a trailing + /// punctuation. pub fn push_value(&mut self, value: T) { assert!( self.empty_or_trailing(), @@ -260,9 +249,6 @@ impl Punctuated { /// /// Parsing continues until the end of this parse stream. The entire content /// of this parse stream must consist of `T` and `P`. - /// - /// *This function is available only if Syn is built with the `"parsing"` - /// feature.* #[cfg(feature = "parsing")] #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_terminated(input: ParseStream) -> Result @@ -281,9 +267,6 @@ impl Punctuated { /// to be parsed. /// /// [`parse_terminated`]: Punctuated::parse_terminated - /// - /// *This function is available only if Syn is built with the `"parsing"` - /// feature.* #[cfg(feature = "parsing")] #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_terminated_with( @@ -318,9 +301,6 @@ impl Punctuated { /// the stream. This method returns upon parsing a `T` and observing that it /// is not followed by a `P`, even if there are remaining tokens in the /// stream. - /// - /// *This function is available only if Syn is built with the `"parsing"` - /// feature.* #[cfg(feature = "parsing")] #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_separated_nonempty(input: ParseStream) -> Result @@ -339,9 +319,6 @@ impl Punctuated { /// the entire content of this stream. /// /// [`parse_separated_nonempty`]: Punctuated::parse_separated_nonempty - /// - /// *This function is available only if Syn is built with the `"parsing"` - /// feature.* #[cfg(feature = "parsing")] #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_separated_nonempty_with( @@ -459,29 +436,37 @@ where impl FromIterator> for Punctuated { fn from_iter>>(i: I) -> Self { let mut ret = Punctuated::new(); - ret.extend(i); + do_extend(&mut ret, i.into_iter()); ret } } -impl Extend> for Punctuated { +impl Extend> for Punctuated +where + P: Default, +{ fn extend>>(&mut self, i: I) { - assert!( - self.empty_or_trailing(), - "Punctuated::extend: Punctuated is not empty or does not have a trailing punctuation", - ); + if !self.empty_or_trailing() { + self.push_punct(P::default()); + } + do_extend(self, i.into_iter()); + } +} - let mut nomore = false; - for pair in i { - if nomore { - panic!("Punctuated extended with items after a Pair::End"); - } - match pair { - Pair::Punctuated(a, b) => self.inner.push((a, b)), - Pair::End(a) => { - self.last = Some(Box::new(a)); - nomore = true; - } +fn do_extend(punctuated: &mut Punctuated, i: I) +where + I: Iterator>, +{ + let mut nomore = false; + for pair in i { + if nomore { + panic!("Punctuated extended with items after a Pair::End"); + } + match pair { + Pair::Punctuated(a, b) => punctuated.inner.push((a, b)), + Pair::End(a) => { + punctuated.last = Some(Box::new(a)); + nomore = true; } } } @@ -719,16 +704,11 @@ where /// /// [module documentation]: self pub struct Iter<'a, T: 'a> { - // The `Item = &'a T` needs to be specified to support rustc 1.31 and older. - // On modern compilers we would be able to write just IterTrait<'a, T> where - // Item can be inferred unambiguously from the supertrait. - inner: Box + 'a>>, + inner: Box + 'a>>, } -trait IterTrait<'a, T: 'a>: - DoubleEndedIterator + ExactSizeIterator -{ - fn clone_box(&self) -> Box + 'a>>; +trait IterTrait<'a, T: 'a>: Iterator + DoubleEndedIterator + ExactSizeIterator { + fn clone_box(&self) -> Box + 'a>>; } struct PrivateIter<'a, T: 'a, P: 'a> { @@ -827,7 +807,7 @@ where + TrivialDrop + 'a, { - fn clone_box(&self) -> Box + 'a>> { + fn clone_box(&self) -> Box + 'a>> { Box::new(NoDrop::new(self.clone())) } } @@ -1008,6 +988,21 @@ impl Pair { } } +#[cfg(feature = "clone-impls")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] +impl Pair<&T, &P> { + pub fn cloned(self) -> Pair + where + T: Clone, + P: Clone, + { + match self { + Pair::Punctuated(t, p) => Pair::Punctuated(t.clone(), p.clone()), + Pair::End(t) => Pair::End(t.clone()), + } + } +} + #[cfg(feature = "clone-impls")] #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] impl Clone for Pair @@ -1023,6 +1018,15 @@ where } } +#[cfg(feature = "clone-impls")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] +impl Copy for Pair +where + T: Copy, + P: Copy, +{ +} + impl Index for Punctuated { type Output = T; -- cgit v1.2.3