Skip to content

Poor parser error message when item category missing (assumes input is a macro) #40006

Closed
@pnkfelix

Description

Consider this code (playpen):

struct S;
impl S { pub hello_method(&self) { println!("Hello"); } }
fn main() { S.hello_method(); }

It yields this error today:

rustc 1.17.0-nightly (a17e5e294 2017-02-20)
error: can't qualify macro invocation with `pub`
 --> <anon>:2:10
  |
2 | impl S { pub hello_method(&self) { println!("Hello"); } }
  |          ^^^
  |
  = help: try adjusting the macro to put `pub` inside the invocation

error: expected one of `!` or `::`, found `(`
 --> <anon>:2:26
  |
2 | impl S { pub hello_method(&self) { println!("Hello"); } }
  |                          ^

error: aborting due to previous error

In this case, the actual error is that the user left out the keyword after the visibility to indicate which kind of item they are trying to define here.

Our parser should be able to do a better job here. At the very least, if there is no trailing !, then instead of assuming that the input was a macro invocation, it should instead assume it was some item definition that is missing its keyword.

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The parsing of Rust source code to an ASTT-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