Skip to content

Add span to lex errors #283

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

Merged
merged 8 commits into from
Apr 1, 2021
Merged

Add span to lex errors #283

merged 8 commits into from
Apr 1, 2021

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Apr 1, 2021

Closes #178.

This PR adds impl LexError { pub fn span(&self) -> Span }. While libproc_macro's LexError does not have such a method, having this is far more important for proc-macro2 than for libproc_macro, because proc macro input is already lexed by rustc and receives good rustc-generated diagnostics on lex errors, while main.rs / build.rs-based parser do not get that.


Before

  error: lex error
    ┌─ src/main.rs:1:1

  1 │ //! this file contains a lex error... where?
    │ ^ lex error

After

  error: lex error
     ┌─ src/main.rs:46:12

  46 │ fn main() {)
     │            ^ lex error

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 this pull request may close these issues.

LexError no span information
1 participant