Closed
Description
This might be an issue for other tokens as well, I just ran into it for <
open angle bracket.
The spans for the <
token have incorrect columns. They appear to be one less than what the real value should be.
I've reproduced the issue in a minimal repository on GitHub.
git clone https://github.com/chinedufn/rustc-span-error
cd rustc-span-error
cargo test # You'll see a failing test with the incorrect span column
I'll paste the code below since it's short:
src/lib.rs
#![feature(proc_macro_hygiene)]
use proc_macro_example::example;
fn foo () {
example! {
ABC<
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn foo () {
}
}
proc macro
#![feature(proc_macro_span)]
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
#[proc_macro]
pub fn example (input: TokenStream) -> TokenStream {
let mut tokens = input.into_iter();
// Assert ABC span start and end columns
let abc = tokens.next().unwrap();
assert_eq!(&abc.to_string(), "ABC");
assert_eq!(abc.span().start().column, 0);
assert_eq!(abc.span().end().column, 2);
// Assert `<` span start and end columns.
// This will fail
let bracket = tokens.next().unwrap();
assert_eq!(&bracket.to_string(), "<");
assert_eq!(bracket.span().end().column, 3);
let empty = quote! {
};
empty.into()
}
Metadata
Metadata
Assignees
Labels
No labels