about summary refs log tree commit diff
path: root/src/libsyntax/codemap.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-21 18:41:35 -0700
committerbors <bors@rust-lang.org>2014-04-21 18:41:35 -0700
commit960bf8ce66d4d3563e1a03f2dbd161857ac0f398 (patch)
treee9eefbc907ed99f606d7a99a9fe581862d3c318c /src/libsyntax/codemap.rs
parent4401f88688eec9052f292ce3b3b8cb96da2853f2 (diff)
parentcc5be28b322498f9c7c802cfa825e9f95363243d (diff)
downloadrust-960bf8ce66d4d3563e1a03f2dbd161857ac0f398.tar.gz
rust-960bf8ce66d4d3563e1a03f2dbd161857ac0f398.zip
auto merge of #13435 : edwardw/rust/span, r=brson
When reporting "consider removing this semicolon" hint message, the
offending semicolon may come from macro call site instead of macro
itself. Using the more appropriate span makes the hint more helpful.

Closes #13428.
Diffstat (limited to 'src/libsyntax/codemap.rs')
-rw-r--r--src/libsyntax/codemap.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 760310e81d3..b4730ace56d 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -141,6 +141,17 @@ pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span {
     Span {lo: lo, hi: hi, expn_info: None}
 }
 
+/// Return the span itself if it doesn't come from a macro expansion,
+/// otherwise return the call site span up to the `enclosing_sp` by
+/// following the `expn_info` chain.
+pub fn original_sp(sp: Span, enclosing_sp: Span) -> Span {
+    match (sp.expn_info, enclosing_sp.expn_info) {
+        (None, _) => sp,
+        (Some(expn1), Some(expn2)) if expn1.call_site == expn2.call_site => sp,
+        (Some(expn1), _) => original_sp(expn1.call_site, enclosing_sp),
+    }
+}
+
 /// A source code location used for error reporting
 pub struct Loc {
     /// Information about the original source