mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Add proc_macro::Span::{before, after}.
This commit is contained in:
parent
cc9610bf5a
commit
d5aec64c12
@ -738,6 +738,12 @@ impl server::Span for Rustc<'_> {
|
|||||||
let loc = self.sess.source_map().lookup_char_pos(span.hi());
|
let loc = self.sess.source_map().lookup_char_pos(span.hi());
|
||||||
LineColumn { line: loc.line, column: loc.col.to_usize() }
|
LineColumn { line: loc.line, column: loc.col.to_usize() }
|
||||||
}
|
}
|
||||||
|
fn before(&mut self, span: Self::Span) -> Self::Span {
|
||||||
|
span.shrink_to_lo()
|
||||||
|
}
|
||||||
|
fn after(&mut self, span: Self::Span) -> Self::Span {
|
||||||
|
span.shrink_to_hi()
|
||||||
|
}
|
||||||
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
|
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
|
||||||
let self_loc = self.sess.source_map().lookup_char_pos(first.lo());
|
let self_loc = self.sess.source_map().lookup_char_pos(first.lo());
|
||||||
let other_loc = self.sess.source_map().lookup_char_pos(second.lo());
|
let other_loc = self.sess.source_map().lookup_char_pos(second.lo());
|
||||||
|
@ -160,6 +160,8 @@ macro_rules! with_api {
|
|||||||
fn source($self: $S::Span) -> $S::Span;
|
fn source($self: $S::Span) -> $S::Span;
|
||||||
fn start($self: $S::Span) -> LineColumn;
|
fn start($self: $S::Span) -> LineColumn;
|
||||||
fn end($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 join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
|
||||||
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
|
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
|
||||||
fn source_text($self: $S::Span) -> Option<String>;
|
fn source_text($self: $S::Span) -> Option<String>;
|
||||||
|
@ -358,6 +358,18 @@ impl Span {
|
|||||||
self.0.end()
|
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`.
|
/// Creates a new span encompassing `self` and `other`.
|
||||||
///
|
///
|
||||||
/// Returns `None` if `self` and `other` are from different files.
|
/// Returns `None` if `self` and `other` are from different files.
|
||||||
|
Loading…
Reference in New Issue
Block a user