Skip to content

error message for macro in wrong context is missing context #34421

@durka

Description

@durka

This is a regression from stable to beta and nightly.

This code is wrong (missing semicolons):

macro_rules! make_item { ($a:ident) => { struct $a; } } fn a() { make_item!(A) } fn b() { make_item!(B) }

Stable prints:

<anon>:2:21: 2:27 error: expected identifier, found keyword `struct` <anon>:2 ($a:ident) => { struct $a; } ^~~~~~ <anon>:5:21: 5:22 error: macro expansion ignores token `A` and any following <anon>:5 fn a() { make_item!(A) } ^ <anon>:5:10: 5:23 note: caused by the macro expansion here; the usage of `make_item!` is likely invalid in expression context <anon>:5 fn a() { make_item!(A) } ^~~~~~~~~~~~~ <anon>:2:21: 2:27 error: expected identifier, found keyword `struct` <anon>:2 ($a:ident) => { struct $a; } ^~~~~~ <anon>:6:21: 6:22 error: macro expansion ignores token `B` and any following <anon>:6 fn b() { make_item!(B) } ^ <anon>:6:10: 6:23 note: caused by the macro expansion here; the usage of `make_item!` is likely invalid in expression context <anon>:6 fn b() { make_item!(B) } ^~~~~~~~~~~~~ error: aborting due to 4 previous errors 

Beta and nightly both print:

error: expected expression, found keyword `struct` --> <anon>:2:21 |> 2 |> ($a:ident) => { struct $a; } |> ^^^^^^ 

Notice that not only is all the useful information gone, but the compiler aborts after the first error instead of finding the rest. It does not matter whether RUST_NEW_ERROR_FORMAT is on or off.

cc @nikomatsakis @jonathandturner

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions