From 9e32a34bbd081b0e453e7515b322047ca48d1e61 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 14 Jul 2023 22:17:17 -0700 Subject: [PATCH] Implement Spanned for QSelf --- src/path.rs | 21 +++++++++++++++++++++ src/spanned.rs | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/path.rs b/src/path.rs index f8b3cc9dff..2d57b71383 100644 --- a/src/path.rs +++ b/src/path.rs @@ -648,6 +648,10 @@ pub(crate) mod parsing { pub(crate) mod printing { use super::*; use crate::print::TokensOrDefault; + #[cfg(feature = "parsing")] + use crate::spanned::Spanned; + #[cfg(feature = "parsing")] + use proc_macro2::Span; use proc_macro2::TokenStream; use quote::ToTokens; use std::cmp; @@ -836,4 +840,21 @@ pub(crate) mod printing { segment.to_tokens(tokens); } } + + #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(all(feature = "parsing", feature = "printing"))))] + impl Spanned for QSelf { + fn span(&self) -> Span { + struct QSelfDelimiters<'a>(&'a QSelf); + + impl<'a> ToTokens for QSelfDelimiters<'a> { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.0.lt_token.to_tokens(tokens); + self.0.gt_token.to_tokens(tokens); + } + } + + QSelfDelimiters(self).span() + } + } } diff --git a/src/spanned.rs b/src/spanned.rs index 7e101d264c..98aa0aa1e7 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -112,4 +112,7 @@ mod private { pub trait Sealed {} impl Sealed for T {} + + #[cfg(any(feature = "full", feature = "derive"))] + impl Sealed for crate::QSelf {} }