2019-01-17 17:17:16 +03:00
|
|
|
#[cfg(feature = "fold")]
|
2019-11-17 07:21:53 +03:00
|
|
|
use crate::fold::{FoldWith, VisitWith};
|
|
|
|
pub use crate::syntax_pos::{
|
2019-02-27 11:44:11 +03:00
|
|
|
hygiene, BytePos, CharPos, ExpnInfo, FileName, Globals, Loc, LocWithOpt, Mark, MultiSpan,
|
2019-02-27 12:31:30 +03:00
|
|
|
SourceFile, SourceFileAndBytePos, SourceFileAndLine, Span, SpanData, SpanLinesError,
|
2019-04-13 14:55:38 +03:00
|
|
|
SyntaxContext, CM, DUMMY_SP, GLOBALS, NO_EXPANSION,
|
2018-06-02 12:01:00 +03:00
|
|
|
};
|
2019-11-17 12:36:47 +03:00
|
|
|
use std::{borrow::Cow, sync::Arc};
|
2018-01-21 11:47:37 +03:00
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
///
|
|
|
|
/// # Derive
|
|
|
|
/// This trait can be derived with `#[derive(Spanned)]`.
|
|
|
|
pub trait Spanned {
|
|
|
|
/// Get span of `self`.
|
|
|
|
fn span(&self) -> Span;
|
2018-01-27 09:14:53 +03:00
|
|
|
}
|
|
|
|
|
2019-11-17 12:36:47 +03:00
|
|
|
impl<'a, T> Spanned for Cow<'a, T>
|
|
|
|
where
|
|
|
|
T: Spanned + Clone,
|
|
|
|
{
|
|
|
|
#[inline(always)]
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
(**self).span()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 08:41:59 +03:00
|
|
|
impl Spanned for Span {
|
|
|
|
#[inline(always)]
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Spanned for BytePos {
|
|
|
|
/// Creates a new single-byte span.
|
|
|
|
#[inline(always)]
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
Span::new(*self, *self, Default::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 07:17:05 +03:00
|
|
|
impl<S> Spanned for Option<S>
|
|
|
|
where
|
|
|
|
S: Spanned,
|
|
|
|
{
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
match *self {
|
|
|
|
Some(ref s) => s.span(),
|
|
|
|
None => DUMMY_SP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-17 12:36:47 +03:00
|
|
|
impl<S> Spanned for Arc<S>
|
|
|
|
where
|
|
|
|
S: ?Sized + Spanned,
|
|
|
|
{
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
<S as Spanned>::span(&*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
impl<S> Spanned for Box<S>
|
2018-01-27 09:14:53 +03:00
|
|
|
where
|
2018-03-03 13:00:57 +03:00
|
|
|
S: ?Sized + Spanned,
|
2018-01-27 09:14:53 +03:00
|
|
|
{
|
2018-03-03 13:00:57 +03:00
|
|
|
fn span(&self) -> Span {
|
|
|
|
<S as Spanned>::span(&*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 08:12:17 +03:00
|
|
|
impl<'a, S> Spanned for &'a S
|
2018-03-03 13:00:57 +03:00
|
|
|
where
|
|
|
|
S: ?Sized + Spanned,
|
|
|
|
{
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
<S as Spanned>::span(&*self)
|
2018-01-27 09:14:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 05:57:27 +03:00
|
|
|
impl<A, B> Spanned for ::either::Either<A, B>
|
|
|
|
where
|
|
|
|
A: Spanned,
|
|
|
|
B: Spanned,
|
|
|
|
{
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
match *self {
|
|
|
|
::either::Either::Left(ref n) => n.span(),
|
|
|
|
::either::Either::Right(ref n) => n.span(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:17:16 +03:00
|
|
|
#[cfg(feature = "fold")]
|
2018-01-27 09:14:53 +03:00
|
|
|
impl<F> FoldWith<F> for Span {
|
|
|
|
/// No op as span does not have any child.
|
|
|
|
fn fold_children(self, _: &mut F) -> Span {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2018-11-19 07:02:55 +03:00
|
|
|
|
2019-01-17 17:17:16 +03:00
|
|
|
#[cfg(feature = "fold")]
|
2018-11-19 07:02:55 +03:00
|
|
|
impl<F> VisitWith<F> for Span {
|
|
|
|
/// No op as span does not have any child.
|
|
|
|
fn visit_children(&self, _: &mut F) {}
|
|
|
|
}
|