Skip to content

Commit 26c86a6

Browse files
authored
Rollup merge of rust-lang#67359 - eddyb:macro-backtrace-all-the-same, 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
2 parents 442ae7f + 96af578 commit 26c86a6

File tree

291 files changed

+1082
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+1082
-277
lines changed

src/bootstrap/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,13 @@ impl<'a> Builder<'a> {
847847
rustflags.arg("-Zforce-unstable-if-unmarked");
848848
}
849849

850-
rustflags.arg("-Zexternal-macro-backtrace");
850+
// cfg(bootstrap): the flag was renamed from `-Zexternal-macro-backtrace`
851+
// to `-Zmacro-backtrace`, keep only the latter after beta promotion.
852+
if stage == 0 {
853+
rustflags.arg("-Zexternal-macro-backtrace");
854+
} else {
855+
rustflags.arg("-Zmacro-backtrace");
856+
}
851857

852858
let want_rustdoc = self.doc_tests != DocTests::No;
853859

src/librustc_errors/annotate_snippet_emitter_writer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct AnnotateSnippetEmitterWriter {
2323
/// If true, will normalize line numbers with `LL` to prevent noise in UI test diffs.
2424
ui_testing: bool,
2525

26-
external_macro_backtrace: bool,
26+
macro_backtrace: bool,
2727
}
2828

2929
impl Emitter for AnnotateSnippetEmitterWriter {
@@ -32,12 +32,12 @@ impl Emitter for AnnotateSnippetEmitterWriter {
3232
let mut children = diag.children.clone();
3333
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
3434

35-
self.fix_multispans_in_std_macros(
35+
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
3636
&self.source_map,
3737
&mut primary_span,
3838
&mut children,
3939
&diag.level,
40-
self.external_macro_backtrace,
40+
self.macro_backtrace,
4141
);
4242

4343
self.emit_messages_default(
@@ -172,9 +172,9 @@ impl AnnotateSnippetEmitterWriter {
172172
pub fn new(
173173
source_map: Option<Lrc<SourceMap>>,
174174
short_message: bool,
175-
external_macro_backtrace: bool,
175+
macro_backtrace: bool,
176176
) -> Self {
177-
Self { source_map, short_message, ui_testing: false, external_macro_backtrace }
177+
Self { source_map, short_message, ui_testing: false, macro_backtrace }
178178
}
179179

180180
/// Allows to modify `Self` to enable or disable the `ui_testing` flag.

0 commit comments

Comments
 (0)