Skip to content

Commit af13e55

Browse files
authoredJul 19, 2022
Rollup merge of #98320 - compiler-errors:macro-backtrace, r=estebank
Mention first and last macro in backtrace Slight improvement to diagnostic mentioning what macro an error originates from. Not sure if it's worthwhile.
·
1.88.01.64.0
2 parents 881e1c1 + 01b2379 commit af13e55

File tree

78 files changed

+157
-144
lines changed

Some content is hidden

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

78 files changed

+157
-144
lines changed
 

‎compiler/rustc_errors/src/emitter.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ pub trait Emitter {
399399
) {
400400
// Check for spans in macros, before `fix_multispans_in_extern_macros`
401401
// has a chance to replace them.
402-
let has_macro_spans = iter::once(&*span)
402+
let has_macro_spans: Vec<_> = iter::once(&*span)
403403
.chain(children.iter().map(|child| &child.span))
404404
.flat_map(|span| span.primary_spans())
405405
.flat_map(|sp| sp.macro_backtrace())
406-
.find_map(|expn_data| {
406+
.filter_map(|expn_data| {
407407
match expn_data.kind {
408408
ExpnKind::Root => None,
409409

@@ -413,7 +413,8 @@ pub trait Emitter {
413413

414414
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
415415
}
416-
});
416+
})
417+
.collect();
417418

418419
if !backtrace {
419420
self.fix_multispans_in_extern_macros(source_map, span, children);
@@ -422,11 +423,22 @@ pub trait Emitter {
422423
self.render_multispans_macro_backtrace(span, children, backtrace);
423424

424425
if !backtrace {
425-
if let Some((macro_kind, name)) = has_macro_spans {
426-
let descr = macro_kind.descr();
426+
if let Some((macro_kind, name)) = has_macro_spans.first() {
427+
// Mark the actual macro this originates from
428+
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
429+
&& last_name != name
430+
{
431+
let descr = macro_kind.descr();
432+
format!(
433+
" which comes from the expansion of the {descr} `{last_name}`",
434+
)
435+
} else {
436+
"".to_string()
437+
};
427438

439+
let descr = macro_kind.descr();
428440
let msg = format!(
429-
"this {level} originates in the {descr} `{name}` \
441+
"this {level} originates in the {descr} `{name}`{and_then} \
430442
(in Nightly builds, run with -Z macro-backtrace for more info)",
431443
);
432444

‎compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(drain_filter)]
77
#![feature(backtrace)]
88
#![feature(if_let_guard)]
9+
#![cfg_attr(bootstrap, feature(let_chains))]
910
#![feature(let_else)]
1011
#![feature(never_type)]
1112
#![feature(adt_const_params)]

0 commit comments

Comments
 (0)
Please sign in to comment.