Skip to content

Bad spans in macro error message #52866

Closed
@RalfJung

Description

@RalfJung

This code

#![crate_type = "lib"]

macro_rules! expensive_static {
    ($name: ident : $T: ty = $e : expr) =>
        (pub static $name : Vec<$T> = vec![$e])
}

expensive_static!(Y : &'static str = "hello");

produces the following error:

error: expected one of `.`, `;`, `?`, or an operator, found `<eof>`
 --> src/lib.rs:5:43
  |
5 |         (pub static $name : Vec<$T> = vec![$e])
  |                                           ^^^^ expected one of `.`, `;`, `?`, or an operator here

So I thought something was wrong with the arguments to the vec! macro. But really the problem is that I forgot the ; after that macro. Thankfully someone on IRC knew, I would never have figured that out...

Can the error message be improved?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions