Skip to content

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

Closed
@durka

Description

@durka
Contributor

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

Activity

jseyfried

jseyfried commented on Jun 23, 2016

@jseyfried
Contributor

cc me

Mark-Simulacrum

Mark-Simulacrum commented on May 6, 2017

@Mark-Simulacrum
Member

So this fell through the cracks, and was a stable to nightly/beta regression. It still is a regression, in a way, but only of diagnostics. @jseyfried Could you take a look?

added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 8, 2017
nikomatsakis

nikomatsakis commented on May 8, 2017

@nikomatsakis
Contributor

Nominating for prioritization.

nikomatsakis

nikomatsakis commented on May 11, 2017

@nikomatsakis
Contributor

So this part of the (previous) stable message:

macro expansion ignores token A and any following

feels like a bug to me anyhow.

This part:

caused by the macro expansion here; the usage of make_item! is likely invalid in expression context

is sort of good. It'd be nice to preserve a backtrace, at least. And ideally we'd suggest adding a ;.

nikomatsakis

nikomatsakis commented on May 11, 2017

@nikomatsakis
Contributor

Given how much time has past, we're going to call this P-medium for now. However, @jseyfried will try to write up some mentoring instructions (or maybe fix it). He has a plan. =)

triage: P-medium

self-assigned this
on May 11, 2017
jseyfried

jseyfried commented on May 15, 2017

@jseyfried
Contributor

I think the best path forward here is to try parsing an expression macro expansion as a statement before emitting an error. If the macro expansion parses as a statement successfully, we can emit a more helpful error suggesting that the user add a semicolon to the macro invocation.

added
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.
on May 15, 2017

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @durka@nikomatsakis@oli-obk@Centril@Freyskeyd

    Issue actions

      error message for macro in wrong context is missing context · Issue #34421 · rust-lang/rust