From 589c91ad4feaf60ea10916cb388af83e12604722 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 11 Mar 2023 20:56:19 -0800 Subject: [PATCH] Move definition of syn::token::Group out of define_delimiters --- src/token.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/token.rs b/src/token.rs index dfd78d5e3d..efda3e4509 100644 --- a/src/token.rs +++ b/src/token.rs @@ -610,6 +610,80 @@ impl Token for Underscore { #[cfg(feature = "parsing")] impl private::Sealed for Underscore {} +/// None-delimited group +pub struct Group { + pub span: Span, +} + +#[doc(hidden)] +#[allow(non_snake_case)] +pub fn Group>(span: S) -> Group { + Group { + span: span.into_spans(), + } +} + +impl std::default::Default for Group { + fn default() -> Self { + Group { + span: Span::call_site(), + } + } +} + +#[cfg(feature = "clone-impls")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] +impl Copy for Group {} + +#[cfg(feature = "clone-impls")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] +impl Clone for Group { + fn clone(&self) -> Self { + *self + } +} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl Debug for Group { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("Group") + } +} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl cmp::Eq for Group {} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl PartialEq for Group { + fn eq(&self, _other: &Group) -> bool { + true + } +} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl Hash for Group { + fn hash(&self, _state: &mut H) {} +} + +impl Group { + #[cfg(feature = "printing")] + pub fn surround(&self, tokens: &mut TokenStream, f: F) + where + F: FnOnce(&mut TokenStream), + { + let mut inner = TokenStream::new(); + f(&mut inner); + printing::delim(Delimiter::None, self.span, tokens, inner); + } +} + +#[cfg(feature = "parsing")] +impl private::Sealed for Group {} + #[cfg(feature = "parsing")] impl Token for Paren { fn peek(cursor: Cursor) -> bool { @@ -762,7 +836,6 @@ define_delimiters! { Brace pub struct Brace /// `{`…`}` Bracket pub struct Bracket /// `[`…`]` Parenthesis pub struct Paren /// `(`…`)` - None pub struct Group /// None-delimited group } /// A type-macro that expands to the name of the Rust type representation of a