summary refs log tree commit diff
path: root/src/libsyntax/codemap.rs
diff options
context:
space:
mode:
authorEdward Wang <edward.yu.wang@gmail.com>2014-04-10 04:42:25 +0800
committerEdward Wang <edward.yu.wang@gmail.com>2014-04-18 22:01:11 +0800
commitcc5be28b322498f9c7c802cfa825e9f95363243d (patch)
tree8d3407c594bafa58711ae8caf143b7e6b1b11d30 /src/libsyntax/codemap.rs
parentce2bab68d69ee04e17c0165dbdb7b583d5a7c991 (diff)
downloadrust-cc5be28b322498f9c7c802cfa825e9f95363243d.tar.gz
rust-cc5be28b322498f9c7c802cfa825e9f95363243d.zip
Use more precise span when reporting semicolon hint
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 b174dffdfec..3c890189ed9 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