Skip to content

Wrong span in proc macro for part of joint op #47226

Closed
@dtolnay

Description

@dtolnay

I have the following proc macro called from the following crate. It is intended to display an error pointing to the first > of a >> joint op. Instead the error points to the whole >> pair of tokens.

#![feature(proc_macro)]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn antoyo(input: TokenStream) -> TokenStream {
    let mut iter = input.into_iter();
    let tt = iter.next().unwrap();
    tt.span.error("first angle bracket").emit();
    assert!(iter.next().is_some());
    assert!(iter.next().is_none());
    TokenStream::empty()
}
#![feature(proc_macro)]

extern crate mac;

mac::antoyo!(>>);

fn main() {}
error: first angle bracket
 --> src/main.rs:5:14
  |
5 | mac::antoyo!(>>);
  |              ^^

This makes it impossible to show correct error messages on something like Option<Option<String>> for example where you want the span to point out the inner Option<String>, as reported in dtolnay/syn#296.

Mentioning @antoyo who noticed this.
Mentioning @jseyfried @abonander who are involved with this code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-1-2Area: Declarative macros 1.2A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions