diff options
Diffstat (limited to 'vendor/quote/src/spanned.rs')
-rw-r--r-- | vendor/quote/src/spanned.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/vendor/quote/src/spanned.rs b/vendor/quote/src/spanned.rs index f64c8f5df..efc2e8bce 100644 --- a/vendor/quote/src/spanned.rs +++ b/vendor/quote/src/spanned.rs @@ -1,7 +1,9 @@ use crate::ToTokens; +use proc_macro2::extra::DelimSpan; use proc_macro2::{Span, TokenStream}; -pub trait Spanned { +// Not public API other than via the syn crate. Use syn::spanned::Spanned. +pub trait Spanned: private::Sealed { fn __span(&self) -> Span; } @@ -11,6 +13,12 @@ impl Spanned for Span { } } +impl Spanned for DelimSpan { + fn __span(&self) -> Span { + self.join() + } +} + impl<T: ?Sized + ToTokens> Spanned for T { fn __span(&self) -> Span { join_spans(self.into_token_stream()) @@ -41,3 +49,14 @@ fn join_spans(tokens: TokenStream) -> Span { .and_then(|last| first.join(last)) .unwrap_or(first) } + +mod private { + use crate::ToTokens; + use proc_macro2::extra::DelimSpan; + use proc_macro2::Span; + + pub trait Sealed {} + impl Sealed for Span {} + impl Sealed for DelimSpan {} + impl<T: ?Sized + ToTokens> Sealed for T {} +} |