Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
durka opened this Issue Jun 23, 2016 · 7 comments

Comments

Projects
None yet
6 participants
@durka
Copy link
Contributor

durka commented Jun 23, 2016

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

@jseyfried

This comment has been minimized.

Copy link
Contributor

jseyfried commented Jun 23, 2016

cc me

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented May 6, 2017

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?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 8, 2017

Nominating for prioritization.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 11, 2017

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

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 11, 2017

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

@rust-highfive rust-highfive added P-medium and removed I-nominated labels May 11, 2017

@jseyfried jseyfried self-assigned this May 11, 2017

@jseyfried

This comment has been minimized.

Copy link
Contributor

jseyfried commented May 15, 2017

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.

@Freyskeyd

This comment has been minimized.

Copy link
Contributor

Freyskeyd commented Nov 6, 2017

I'm interested in this but I need informations to understand what to do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.