diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/syn-1.0.109/src/gen_helper.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn-1.0.109/src/gen_helper.rs')
-rw-r--r-- | vendor/syn-1.0.109/src/gen_helper.rs | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/vendor/syn-1.0.109/src/gen_helper.rs b/vendor/syn-1.0.109/src/gen_helper.rs new file mode 100644 index 000000000..b2796126a --- /dev/null +++ b/vendor/syn-1.0.109/src/gen_helper.rs @@ -0,0 +1,154 @@ +#[cfg(feature = "fold")] +pub mod fold { + use crate::fold::Fold; + use crate::punctuated::{Pair, Punctuated}; + use proc_macro2::Span; + + pub trait FoldHelper { + type Item; + fn lift<F>(self, f: F) -> Self + where + F: FnMut(Self::Item) -> Self::Item; + } + + impl<T> FoldHelper for Vec<T> { + type Item = T; + fn lift<F>(self, f: F) -> Self + where + F: FnMut(Self::Item) -> Self::Item, + { + self.into_iter().map(f).collect() + } + } + + impl<T, U> FoldHelper for Punctuated<T, U> { + type Item = T; + fn lift<F>(self, mut f: F) -> Self + where + F: FnMut(Self::Item) -> Self::Item, + { + self.into_pairs() + .map(Pair::into_tuple) + .map(|(t, u)| Pair::new(f(t), u)) + .collect() + } + } + + pub fn tokens_helper<F: Fold + ?Sized, S: Spans>(folder: &mut F, spans: &S) -> S { + spans.fold(folder) + } + + pub trait Spans { + fn fold<F: Fold + ?Sized>(&self, folder: &mut F) -> Self; + } + + impl Spans for Span { + fn fold<F: Fold + ?Sized>(&self, folder: &mut F) -> Self { + folder.fold_span(*self) + } + } + + impl Spans for [Span; 1] { + fn fold<F: Fold + ?Sized>(&self, folder: &mut F) -> Self { + [folder.fold_span(self[0])] + } + } + + impl Spans for [Span; 2] { + fn fold<F: Fold + ?Sized>(&self, folder: &mut F) -> Self { + [folder.fold_span(self[0]), folder.fold_span(self[1])] + } + } + + impl Spans for [Span; 3] { + fn fold<F: Fold + ?Sized>(&self, folder: &mut F) -> Self { + [ + folder.fold_span(self[0]), + folder.fold_span(self[1]), + folder.fold_span(self[2]), + ] + } + } +} + +#[cfg(feature = "visit")] +pub mod visit { + use crate::visit::Visit; + use proc_macro2::Span; + + pub fn tokens_helper<'ast, V: Visit<'ast> + ?Sized, S: Spans>(visitor: &mut V, spans: &S) { + spans.visit(visitor); + } + + pub trait Spans { + fn visit<'ast, V: Visit<'ast> + ?Sized>(&self, visitor: &mut V); + } + + impl Spans for Span { + fn visit<'ast, V: Visit<'ast> + ?Sized>(&self, visitor: &mut V) { + visitor.visit_span(self); + } + } + + impl Spans for [Span; 1] { + fn visit<'ast, V: Visit<'ast> + ?Sized>(&self, visitor: &mut V) { + visitor.visit_span(&self[0]); + } + } + + impl Spans for [Span; 2] { + fn visit<'ast, V: Visit<'ast> + ?Sized>(&self, visitor: &mut V) { + visitor.visit_span(&self[0]); + visitor.visit_span(&self[1]); + } + } + + impl Spans for [Span; 3] { + fn visit<'ast, V: Visit<'ast> + ?Sized>(&self, visitor: &mut V) { + visitor.visit_span(&self[0]); + visitor.visit_span(&self[1]); + visitor.visit_span(&self[2]); + } + } +} + +#[cfg(feature = "visit-mut")] +pub mod visit_mut { + use crate::visit_mut::VisitMut; + use proc_macro2::Span; + + pub fn tokens_helper<V: VisitMut + ?Sized, S: Spans>(visitor: &mut V, spans: &mut S) { + spans.visit_mut(visitor); + } + + pub trait Spans { + fn visit_mut<V: VisitMut + ?Sized>(&mut self, visitor: &mut V); + } + + impl Spans for Span { + fn visit_mut<V: VisitMut + ?Sized>(&mut self, visitor: &mut V) { + visitor.visit_span_mut(self); + } + } + + impl Spans for [Span; 1] { + fn visit_mut<V: VisitMut + ?Sized>(&mut self, visitor: &mut V) { + visitor.visit_span_mut(&mut self[0]); + } + } + + impl Spans for [Span; 2] { + fn visit_mut<V: VisitMut + ?Sized>(&mut self, visitor: &mut V) { + visitor.visit_span_mut(&mut self[0]); + visitor.visit_span_mut(&mut self[1]); + } + } + + impl Spans for [Span; 3] { + fn visit_mut<V: VisitMut + ?Sized>(&mut self, visitor: &mut V) { + visitor.visit_span_mut(&mut self[0]); + visitor.visit_span_mut(&mut self[1]); + visitor.visit_span_mut(&mut self[2]); + } + } +} |