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

senseless line / column ? #561

Closed
Dushistov opened this issue Jan 5, 2019 · 2 comments
Closed

senseless line / column ? #561

Dushistov opened this issue Jan 5, 2019 · 2 comments

Comments

@Dushistov
Copy link

I build syn with procmacro2_semver_exempt.
And for such wrong code (a: i32, <) -> i32; it reports span: 1:0 - 1:11, in other words
(a: i32, <), but if print ParseStream I can see that it stops on <,
so there is information about exact wrong token,
thus is it possible somehow report where parser stops in case of parenthesized usage?

use quote::quote;
use syn::{
    parenthesized,
    parse::{Parse, ParseStream},
    punctuated::Punctuated,
    Result, Token,
};

struct Item;
impl Parse for Item {
    fn parse(input: ParseStream) -> Result<Self> {
        let args_parser;
        parenthesized!(args_parser in input);
        let args_in: Result<Punctuated<syn::FnArg, Token![,]>> =
            args_parser.parse_terminated(syn::FnArg::parse);
        println!("state, input {}\nargs_parser {}", input, args_parser);
        let args_in = args_in?;
        unimplemented!();
    }
}

fn main() {
    if let Err(err) = syn::parse_str::<Item>("(a: i32, <) -> i32;") {
        println!(
            "err: {}, at {}:{} - {}:{}",
            err,
            err.span().start().line,
            err.span().start().column,
            err.span().end().line,
            err.span().end().column
        );
    }
}
@dtolnay
Copy link
Owner

dtolnay commented Jan 5, 2019

The error is being triggered on the close parenthesis. The matched set of parentheses carries only a single span covering the set of parentheses so that is where the error is reported.

@dtolnay
Copy link
Owner

dtolnay commented Jan 15, 2019

I fixed this for proc macros in fe89fcc, so that errors can appear on just the opening or just the closing delimiter. When the Group::span_open and Group::span_close methods are stabilized (tracked in rust-lang/rust#54725) we will be able to carry this over to build.rs / main.rs based parsers as well.

@dtolnay dtolnay closed this as completed Jan 15, 2019
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

No branches or pull requests

2 participants