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.
This commit is contained in:
Edward Wang 2014-04-10 04:42:25 +08:00
parent ce2bab68d6
commit cc5be28b32
5 changed files with 54 additions and 18 deletions

View file

@ -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