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

Macro diagnostics tweaks #55292

Merged
merged 3 commits into from Oct 26, 2018

Conversation

Projects
None yet
5 participants
@estebank
Contributor

estebank commented Oct 23, 2018

Fix #30128, fix #10951 by adding an appropriate span to the diagnostic.
Fix #26288 by suggesting adding semicolon to macro call.

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Oct 23, 2018

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

| |
| caused by the macro expansion here
|
= note: the usage of `foo!` is likely invalid in expression context

This comment has been minimized.

@estebank

estebank Oct 23, 2018

Contributor

@dtolnay can you take a look and verify wether this suggestion is reasonable (it won't be wrong more often than not)?

This comment has been minimized.

@estebank

estebank Oct 23, 2018

Contributor

This is one case where it'd be the wrong approach:

fn main() {
    macro_rules! a {
        ($e:expr) => { $e; 2}
    }
    a!(true);
}
error: macro expansion ignores token `2` and any following
 --> file.rs:3:28
  |
3 |         ($e:expr) => { $e; 2}
  |                            ^
4 |     }
5 |     a!(true)
  |     --------- help: you might be missing a semicolon here: `;`
  |     |
  |     caused by the macro expansion here
  |
  = note: the usage of `a!` is likely invalid in expression context

but the suggestion actually gets the code to compile...

This comment has been minimized.

@dtolnay

dtolnay Oct 23, 2018

Member

I think this suggestion will be helpful. 👍

LL | let i = m!();
| ^^^^
| ----- help: you might be missing a semicolon here: `;`

This comment has been minimized.

@pnkfelix

pnkfelix Oct 24, 2018

Member

Can we not peek ahead to the source text immediately following the span and see if there's a semicolon as the next character before making such an obviously inapplicable help message?

This comment has been minimized.

@estebank

estebank Oct 24, 2018

Contributor

We're actually checking that, which makes me intrigued at why this isn't being picked up. My guess is that if spans were completely hygienic this suggestion would appear on line 13, after typeof. This seems to be the only edge-case caught by our tests (before I added the linked check, many other incorrect suggestions were being emitted). Given that, would you mind if we merge as is and add extra logic in a later PR?

This comment has been minimized.

@pnkfelix

pnkfelix Oct 24, 2018

Member

Sounds good

@pnkfelix

This comment has been minimized.

Member

pnkfelix commented Oct 24, 2018

This seems fine. I would like an answer to my Q about peeking at the next character rather than blindly stating that a semicolon might be missing when it clearly is present in the source.

@pnkfelix

This comment has been minimized.

Member

pnkfelix commented Oct 24, 2018

@bors r+

@bors

This comment has been minimized.

Contributor

bors commented Oct 24, 2018

📌 Commit ad144ac has been approved by pnkfelix

@estebank

This comment has been minimized.

Contributor

estebank commented Oct 24, 2018

@bors r=pnkfelix

@pnkfelix went ahead and fixed it.

@bors

This comment has been minimized.

Contributor

bors commented Oct 24, 2018

📌 Commit f8818cb has been approved by pnkfelix

@estebank

This comment has been minimized.

Contributor

estebank commented Oct 26, 2018

@bors rollup

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55292 - estebank:macro-eof, r=pnkfelix
Macro diagnostics tweaks

Fix rust-lang#30128, fix rust-lang#10951 by adding an appropriate span to the diagnostic.
Fix rust-lang#26288 by suggesting adding semicolon to macro call.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55371 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests

Successful merges:

 - #53996 ([CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded])
 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55363 (Bump cargo-vendor version to 0.1.17)

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55371 - kennytm:rollup, r=kennytm
Rollup of 15 pull requests

Successful merges:

 - #53996 ([CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded])
 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55292 - estebank:macro-eof, r=pnkfelix
Macro diagnostics tweaks

Fix rust-lang#30128, fix rust-lang#10951 by adding an appropriate span to the diagnostic.
Fix rust-lang#26288 by suggesting adding semicolon to macro call.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
Rollup of 19 pull requests

Successful merges:

 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55302 (Extend the impl_stable_hash_for! macro for miri.)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55363 (Bump cargo-vendor version to 0.1.17)
 - #55370 (Update mailmap for estebank)
 - #55375 (Typo fixes in configure_cmake comments)
 - #55378 (rustbuild: use configured linker to build boostrap)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
Rollup of 19 pull requests

Successful merges:

 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55302 (Extend the impl_stable_hash_for! macro for miri.)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55370 (Update mailmap for estebank)
 - #55375 (Typo fixes in configure_cmake comments)
 - #55378 (rustbuild: use configured linker to build boostrap)
 - #55379 (validity: assert that unions are non-empty)

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55292 - estebank:macro-eof, r=pnkfelix
Macro diagnostics tweaks

Fix rust-lang#30128, fix rust-lang#10951 by adding an appropriate span to the diagnostic.
Fix rust-lang#26288 by suggesting adding semicolon to macro call.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
Rollup of 21 pull requests

Successful merges:

 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55264 (Compile the libstd we distribute with -Ccodegen-unit=1)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55302 (Extend the impl_stable_hash_for! macro for miri.)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55370 (Update mailmap for estebank)
 - #55375 (Typo fixes in configure_cmake comments)
 - #55378 (rustbuild: use configured linker to build boostrap)
 - #55379 (validity: assert that unions are non-empty)
 - #55383 (Use `SmallVec` for the queue in `coerce_unsized`.)
 - #55391 (bootstrap: clean up a few clippy findings)

@bors bors merged commit f8818cb into rust-lang:master Oct 26, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment