Skip to content

Unhelpful error when macro such as println! is used outside a function body #21607

Closed
@ExpHP

Description

@ExpHP

Place a macro like panic! or println! outside of a function body:

panic!("outside of a function");
fn main() { }

The error message does not provide the expansion site:

<std macros>:2:1: 2:2 error: macro expansion ignores token `{` and any following
<std macros>:2 {
               ^
error: aborting due to previous error

A similar effect is had in an impl body.

struct Foo;

impl Foo{
  panic!("in impl body");
}

fn main() {}

----------------------
<std macros>:2:1: 2:2 error: expected `fn`, found `{`
<std macros>:2 {
               ^

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