We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
<
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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() }
The text was updated successfully, but these errors were encountered:
I think the compiler is correct here. In your standalone repo, the assertion that is failing is the following one (not the one you commented):
assert_eq!(abc.span().end().column, 2);
because the end of ABC is in column 3.
A B C < ↑ ↑ ↑ ↑ ↑ 0 1 2 3 4
ABC goes from 0 to 3, < goes from 3 to 4.
ABC
In dtolnay/proc-macro2#166 (comment):
T a g < / ↑ ↑ ↑ ↑ ↑ ↑ ↑ 33 34 35 36 37 38 39
Tag goes from 33 to 36, < goes from 37 to 38.
Tag
FYI @alexcrichton
Sorry, something went wrong.
Ahhh sorry I misunderstood how columns worked. Thanks so much!
No branches or pull requests
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.
I'll paste the code below since it's short:
src/lib.rs
proc macro
The text was updated successfully, but these errors were encountered: