diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-07-19 21:54:01 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-07-20 21:27:22 -0700 |
| commit | e99d309c5695a2b5ad1ab44c06fd32ec506cebaa (patch) | |
| tree | 3f19403fe2ff9c67b2abb6f33c5730cf62abbed7 /src/libsyntax_pos/lib.rs | |
| parent | cc800531cc79b76b37a1e0f1f58f807ea7aee68b (diff) | |
| download | rust-e99d309c5695a2b5ad1ab44c06fd32ec506cebaa.tar.gz rust-e99d309c5695a2b5ad1ab44c06fd32ec506cebaa.zip | |
Use the macro structure spans instead of the invocation
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index a7c247689cc..49684acb4a2 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -100,6 +100,7 @@ impl Span { if self.source_equal(&DUMMY_SP) { other } else { self } } + /// Return true if `self` fully encloses `other`. pub fn contains(self, other: Span) -> bool { self.lo <= other.lo && other.hi <= self.hi } @@ -184,15 +185,32 @@ impl Span { result } + pub fn empty_ctxt(&self) -> bool { + self.ctxt == SyntaxContext::empty() + } + + /// Return a `Span` that would enclose both `self` and `end`. pub fn to(self, end: Span) -> Span { + let lo = if self.lo < end.lo { + self.lo + } else { + end.lo + }; + let hi = if self.hi > end.hi { + self.hi + } else { + end.hi + }; // FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480) - if self.ctxt == SyntaxContext::empty() { - Span { lo: self.lo, ..end } + let ctxt = if self.ctxt == SyntaxContext::empty() { + end.ctxt } else { - Span { hi: end.hi, ..self } - } + self.ctxt + }; + Span {lo, hi, ctxt} } + /// Return a `Span` between the end of `self` to the beginning of `end`. pub fn between(self, end: Span) -> Span { Span { lo: self.hi, @@ -205,6 +223,7 @@ impl Span { } } + /// Return a `Span` between the beginning of `self` to the beginning of `end`. pub fn until(self, end: Span) -> Span { Span { lo: self.lo, @@ -852,6 +871,7 @@ pub struct FileLines { thread_local!(pub static SPAN_DEBUG: Cell<fn(Span, &mut fmt::Formatter) -> fmt::Result> = Cell::new(default_span_debug)); +#[derive(Debug)] pub struct MacroBacktrace { /// span where macro was applied to generate this code pub call_site: Span, |
