1
Fork 0

Add proc_macro::Span::{before, after}.

This commit is contained in:
Mara Bos 2021-06-09 14:37:10 +02:00
parent cc9610bf5a
commit d5aec64c12
3 changed files with 20 additions and 0 deletions

View file

@ -160,6 +160,8 @@ macro_rules! with_api {
fn source($self: $S::Span) -> $S::Span;
fn start($self: $S::Span) -> LineColumn;
fn end($self: $S::Span) -> LineColumn;
fn before($self: $S::Span) -> $S::Span;
fn after($self: $S::Span) -> $S::Span;
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
fn source_text($self: $S::Span) -> Option<String>;

View file

@ -358,6 +358,18 @@ impl Span {
self.0.end()
}
/// Creates an empty span pointing to directly before this span.
#[unstable(feature = "proc_macro_span_shrink", issue = "none")]
pub fn before(&self) -> Span {
Span(self.0.before())
}
/// Creates an empty span pointing to directly after this span.
#[unstable(feature = "proc_macro_span_shrink", issue = "none")]
pub fn after(&self) -> Span {
Span(self.0.after())
}
/// Creates a new span encompassing `self` and `other`.
///
/// Returns `None` if `self` and `other` are from different files.