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

Rename -Zexternal-macro-backtrace to -Zmacro-backtrace and clean up implementation. #67359

Merged
merged 6 commits into from
Feb 7, 2020

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Dec 16, 2019

This is my attempt at dealing with #66364 (comment), although I'm not sure it's the least disruptive one.

The behavior of -Zexternal-macro-backtrace was already to enable full macro backtraces for all macros, the only part of it that was specific to cross-crate macros was showing this when not used:

note: this error originates in a macro outside of the current crate
  (in Nightly builds, run with -Z external-macro-backtrace for more info)

After this PR:

  • the flag is renamed to -Zmacro-backtrace
    • do we need to have a deprecation period? cc @rust-lang/compiler
  • the message informing you about the flag is always shown when an expansion of a bang macro/attribute/derive is involved, not just cross-crate ones
    • this accounts for most of the changes in tests
    • we could perhaps only show it for the bang macro case? feels odd for derives
  • fix_multispans_in_std_macros is split into fix_multispans_in_extern_macros and render_multispans_macro_backtrace
    • this roughly reverts the non-behavioral parts of Use spans for -Z external-macro-backtrace #46605, which combined the two functionalities
    • not sure where the old std_macros name came from, perhaps the <std macros> synthetic "file"? even then, odd that std specifically was mentioned
  • render_multispan_macro_backtrace, by default (i.e. without -Zmacro-backtrace), hides the in this macro invocation label specifically to avoid redundancy in the diagnostic
    • that is, showing the macro use site is only useful when the diagnostic is inside the macro definition and the user can't otherwise tell which use site it applies to, not when the diagnostic is at/inside the use site already (which would make the label redundant)
    • before, it was only checking for the situation in which a cross-crate macro definition span would be replaced with the invocation span, which both made the connection to redundancy unobvious, and didn't help with other redundancy (e.g. when the diagnostic was pointing to an argument inside the macro invocation)
    • this accounts for the remaining test changes, which I've first noticed in Cleanup rmeta::MacroDef #66364 (comment) but only later understood as part of this PR (hence the "redundancy" descriptions)

This PR is not needed for #66364, but it would help, as after this PR there's only one .span_to_filename(...).is_macros() check (i.e. for <... macros> synthetic "files") left in rustc_errors, and it's much more self-contained.

r? @petrochenkov

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 20, 2019
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 28, 2019
@petrochenkov
Copy link
Contributor

Meta: some mix between functional and formatting changes here, perhaps it will look better if rebased on master where everything is rustfmt-ed.

src/librustc_errors/emitter.rs Show resolved Hide resolved
src/librustc_errors/emitter.rs Show resolved Hide resolved
src/librustc_errors/emitter.rs Show resolved Hide resolved
src/librustc_errors/emitter.rs Outdated Show resolved Hide resolved
src/librustc_errors/emitter.rs Outdated Show resolved Hide resolved
src/librustc_errors/emitter.rs Outdated Show resolved Hide resolved
src/librustc_errors/emitter.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 29, 2019
@hdhoang
Copy link
Contributor

hdhoang commented Jan 9, 2020

ping from triage, @eddyb can you rebase and apply reviewers' comment, thanks!

@nikomatsakis
Copy link
Contributor

On this topic:

the flag is renamed to -Zmacro-backtrace
do we need to have a deprecation period? cc @rust-lang/compiler

I think this flag is used by folks? It seems like at minimum we should announce the change in a PSA on Inside Rust. A deprecation period would be polite, but it's probably not required.

I guess we don't really document -Z flags in the rustc book, so we don't have to update that (though I sometimes think that is not the best policy).

@eddyb eddyb force-pushed the macro-backtrace-all-the-same branch from bcf92e8 to 4722c83 Compare January 15, 2020 14:14
@rust-highfive

This comment has been minimized.

@eddyb eddyb force-pushed the macro-backtrace-all-the-same branch from 4722c83 to 8261365 Compare January 15, 2020 15:51
@rust-highfive

This comment has been minimized.

@eddyb eddyb force-pushed the macro-backtrace-all-the-same branch from 8261365 to 000e1bf Compare January 16, 2020 15:21
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2020
@petrochenkov
Copy link
Contributor

Blocked on #68407.

@petrochenkov petrochenkov added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 22, 2020
bors added a commit that referenced this pull request Jan 26, 2020
rustc_span: return an impl Iterator instead of a Vec from macro_backtrace.

Having `Span::macro_backtrace` produce an `impl Iterator<Item = ExpnData>` allows #67359 to use it instead of rolling its own similar functionality.

The move from `MacroBacktrace` to `ExpnData` (which the first two commits are prerequisites for) both eliminates unnecessary allocations, and is strictly more flexible (exposes more information).

r? @petrochenkov
@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 6, 2020
@eddyb eddyb force-pushed the macro-backtrace-all-the-same branch from a1676c7 to 96af578 Compare February 6, 2020 19:47
@eddyb
Copy link
Member Author

eddyb commented Feb 6, 2020

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Feb 6, 2020

📌 Commit 96af578 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 6, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 6, 2020
… r=petrochenkov

Rename -Zexternal-macro-backtrace to -Zmacro-backtrace and clean up implementation.

This is my attempt at dealing with rust-lang#66364 (comment), although I'm not sure it's the least disruptive one.

The behavior of `-Zexternal-macro-backtrace` was already to enable full macro backtraces for *all* macros, the only part of it that was specific to cross-crate macros was showing this when *not used*:
```
note: this error originates in a macro outside of the current crate
  (in Nightly builds, run with -Z external-macro-backtrace for more info)
```

After this PR:
* the flag is renamed to `-Zmacro-backtrace`
  * do we need to have a deprecation period? cc @rust-lang/compiler
* the message informing you about the flag is always shown when an expansion of a bang macro/attribute/derive is involved, not just cross-crate ones
  * this accounts for most of the changes in tests
  * we could perhaps only show it for the bang macro case? feels odd for derives
* `fix_multispans_in_std_macros` is split into `fix_multispans_in_extern_macros` and `render_multispans_macro_backtrace`
  * this roughly reverts the non-behavioral parts of rust-lang#46605, which combined the two functionalities
  * not sure where the old `std_macros` name came from, perhaps the `<std macros>` synthetic "file"? even then, odd that `std` specifically was mentioned
* `render_multispan_macro_backtrace`, by default (i.e. without `-Zmacro-backtrace`), hides the `in this macro invocation` label specifically to avoid redundancy in the diagnostic
  * that is, showing the macro use site is only useful when the diagnostic is inside the macro definition and the user can't otherwise tell which use site it applies to, not when the diagnostic is at/inside the use site already (which would make the label redundant)
  * before, it was only checking for the situation in which a cross-crate macro *definition* span would be replaced with the invocation span, which both made the connection to redundancy unobvious, and didn't help with other redundancy (e.g. when the diagnostic was pointing to an argument inside the macro invocation)
  * this accounts for the remaining test changes, which I've first noticed in rust-lang#66364 (comment) but only later understood as part of this PR (hence the "redundancy" descriptions)

This PR is not needed for rust-lang#66364, but it would help, as after this PR there's only one `.span_to_filename(...).is_macros()` check (i.e. for `<... macros>` synthetic "files") left in `rustc_errors`, and it's much more self-contained.

r? @petrochenkov
bors added a commit that referenced this pull request Feb 7, 2020
Rollup of 6 pull requests

Successful merges:

 - #67359 (Rename -Zexternal-macro-backtrace to -Zmacro-backtrace and clean up implementation.)
 - #68524 (Generator Resume Arguments)
 - #68791 (implement proper linkchecker hardening)
 - #68886 (Mark fn map_or() as eagerly evaluated.)
 - #68888 (error code examples: replace some more ignore with compile_fail)
 - #68894 (Update E0565 examples)

Failed merges:

r? @ghost
@bors
Copy link
Contributor

bors commented Feb 7, 2020

☔ The latest upstream changes (presumably #68907) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 7, 2020
@bors bors merged commit 96af578 into rust-lang:master Feb 7, 2020
tesuji added a commit to tesuji/rust-clippy that referenced this pull request Feb 7, 2020
bors added a commit to rust-lang/rust-clippy that referenced this pull request Feb 7, 2020
@eddyb eddyb deleted the macro-backtrace-all-the-same branch February 7, 2020 05:01
bors added a commit to rust-lang/rust-clippy that referenced this pull request Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants