summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src/punctuated.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/syn/src/punctuated.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/src/punctuated.rs')
-rw-r--r--vendor/syn/src/punctuated.rs112
1 files changed, 58 insertions, 54 deletions
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<T, P> {
impl<T, P> Punctuated<T, P> {
/// 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<T, P> Punctuated<T, P> {
}
}
- /// 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<T, P> Punctuated<T, P> {
}
/// 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<T, P> Punctuated<T, P> {
///
/// # 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<T, P> Punctuated<T, P> {
///
/// 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<Self>
@@ -281,9 +267,6 @@ impl<T, P> Punctuated<T, P> {
/// 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<T, P> Punctuated<T, P> {
/// 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<Self>
@@ -339,9 +319,6 @@ impl<T, P> Punctuated<T, P> {
/// 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<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P> {
fn from_iter<I: IntoIterator<Item = Pair<T, P>>>(i: I) -> Self {
let mut ret = Punctuated::new();
- ret.extend(i);
+ do_extend(&mut ret, i.into_iter());
ret
}
}
-impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P> {
+impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P>
+where
+ P: Default,
+{
fn extend<I: IntoIterator<Item = Pair<T, P>>>(&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<T, P, I>(punctuated: &mut Punctuated<T, P>, i: I)
+where
+ I: Iterator<Item = Pair<T, P>>,
+{
+ 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<NoDrop<dyn IterTrait<'a, T, Item = &'a T> + 'a>>,
+ inner: Box<NoDrop<dyn IterTrait<'a, T> + 'a>>,
}
-trait IterTrait<'a, T: 'a>:
- DoubleEndedIterator<Item = &'a T> + ExactSizeIterator<Item = &'a T>
-{
- fn clone_box(&self) -> Box<NoDrop<dyn IterTrait<'a, T, Item = &'a T> + 'a>>;
+trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> + DoubleEndedIterator + ExactSizeIterator {
+ fn clone_box(&self) -> Box<NoDrop<dyn IterTrait<'a, T> + 'a>>;
}
struct PrivateIter<'a, T: 'a, P: 'a> {
@@ -827,7 +807,7 @@ where
+ TrivialDrop
+ 'a,
{
- fn clone_box(&self) -> Box<NoDrop<dyn IterTrait<'a, T, Item = &'a T> + 'a>> {
+ fn clone_box(&self) -> Box<NoDrop<dyn IterTrait<'a, T> + 'a>> {
Box::new(NoDrop::new(self.clone()))
}
}
@@ -1010,6 +990,21 @@ impl<T, P> Pair<T, P> {
#[cfg(feature = "clone-impls")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
+impl<T, P> Pair<&T, &P> {
+ pub fn cloned(self) -> Pair<T, P>
+ 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<T, P> Clone for Pair<T, P>
where
T: Clone,
@@ -1023,6 +1018,15 @@ where
}
}
+#[cfg(feature = "clone-impls")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
+impl<T, P> Copy for Pair<T, P>
+where
+ T: Copy,
+ P: Copy,
+{
+}
+
impl<T, P> Index<usize> for Punctuated<T, P> {
type Output = T;