Use Group::span_open and span_close in error spans
Macro 1:
input.parse::<Ident>()?;
Before:
error: expected identifier
--> src/main.rs:3:4
|
3 | m!([a]);
| ^^^
After:
error: expected identifier
--> src/main.rs:3:4
|
3 | m!([a]);
| ^
Macro 2:
let content;
bracketed!(content in input);
content.parse::<Ident>()?;
content.parse::<Ident>()?;
Before:
error: unexpected end of input, expected identifier
--> src/main.rs:3:4
|
3 | m!([a]);
| ^^^
After:
error: unexpected end of input, expected identifier
--> src/main.rs:3:6
|
3 | m!([a]);
| ^
diff --git a/src/buffer.rs b/src/buffer.rs
index 1d0ffe0..8c32645 100644
--- a/src/buffer.rs
+++ b/src/buffer.rs
@@ -17,6 +17,7 @@
use std::marker::PhantomData;
use std::ptr;
+use private;
use Lifetime;
/// Internal type which is used instead of `TokenTree` to represent a token tree
@@ -345,3 +346,21 @@
}
}
}
+
+impl private {
+ #[cfg(procmacro2_semver_exempt)]
+ pub fn open_span_of_group(cursor: Cursor) -> Span {
+ match *cursor.entry() {
+ Entry::Group(ref group, _) => group.span_open(),
+ _ => cursor.span(),
+ }
+ }
+
+ #[cfg(procmacro2_semver_exempt)]
+ pub fn close_span_of_group(cursor: Cursor) -> Span {
+ match *cursor.entry() {
+ Entry::Group(ref group, _) => group.span_close(),
+ _ => cursor.span(),
+ }
+ }
+}