Skip to content
New issue

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

Wrong span when parse TypeTuple with more than two elements #959

Closed
imlk0 opened this issue Jan 22, 2021 · 1 comment · Fixed by #960
Closed

Wrong span when parse TypeTuple with more than two elements #959

imlk0 opened this issue Jan 22, 2021 · 1 comment · Fixed by #960

Comments

@imlk0
Copy link

imlk0 commented Jan 22, 2021

when parsing the string text:

    let text = r#"
        (usize, usize, usize, usize, usize, usize)
    "#;

the result of to_token_stream():

    let tuple: TypeTuple = syn::parse_str(text).unwrap();
    let ts = tuple.to_token_stream();

and TokenStream::from_str(text)

    let ts: TokenStream = TokenStream::from_str(text).unwrap();

are not the same.

Specifically, except for the first comma, the results of.span() on the remaining commas are the same.
All results of span.start() and span.end() are LineColumn { line: 1, column: 0 }

This may cause misunderstandings to those who think that .to_token_stream() is equivalent to TokenStream::from_str(text)

playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5161bd64cbd54d283bcf04b47cec8343

@dtolnay
Copy link
Owner

dtolnay commented Jan 23, 2021

Thanks, I've published a fix in 1.0.59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants