Skip to content

Commit

Permalink
Merge pull request #1486 from dtolnay/qselfspan
Browse files Browse the repository at this point in the history
Implement Spanned for QSelf
  • Loading branch information
dtolnay authored Jul 15, 2023
2 parents 026a38c + 9e32a34 commit ee59842
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
}
}
3 changes: 3 additions & 0 deletions src/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ mod private {

pub trait Sealed {}
impl<T: ?Sized + ToTokens> Sealed for T {}

#[cfg(any(feature = "full", feature = "derive"))]
impl Sealed for crate::QSelf {}
}

0 comments on commit ee59842

Please sign in to comment.