about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-19 08:32:32 +0000
committerbors <bors@rust-lang.org>2022-07-19 08:32:32 +0000
commit4603ac31b0655793a82f110f544dc1c6abc57bb7 (patch)
treea650c962b99c7311cd3cf7360c854ff63f39195c /compiler/rustc_errors/src
parentc3f35504d15e80b4727872c17c8c2f4bbaee58cf (diff)
parente301cd39ad62cda469034539d06819a30ee12305 (diff)
downloadrust-4603ac31b0655793a82f110f544dc1c6abc57bb7.tar.gz
rust-4603ac31b0655793a82f110f544dc1c6abc57bb7.zip
Auto merge of #99451 - Dylan-DPC:rollup-ceghu18, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #97183 (wf-check generators)
 - #98320 (Mention first and last macro in backtrace)
 - #99335 (Use split_once in FromStr docs)
 - #99347 (Use `LocalDefId` in `OpaqueTypeKey`)
 - #99392 (Fix debuginfo tests.)
 - #99404 (Use span_bug for unexpected field projection type)
 - #99410 (Update invalid atomic ordering lint)
 - #99434 (Fix `Skip::next` for non-fused inner iterators)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs24
-rw-r--r--compiler/rustc_errors/src/lib.rs1
2 files changed, 19 insertions, 6 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 85ea8eb3937..61d953cd6f1 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -399,11 +399,11 @@ pub trait Emitter {
     ) {
         // Check for spans in macros, before `fix_multispans_in_extern_macros`
         // has a chance to replace them.
-        let has_macro_spans = iter::once(&*span)
+        let has_macro_spans: Vec<_> = iter::once(&*span)
             .chain(children.iter().map(|child| &child.span))
             .flat_map(|span| span.primary_spans())
             .flat_map(|sp| sp.macro_backtrace())
-            .find_map(|expn_data| {
+            .filter_map(|expn_data| {
                 match expn_data.kind {
                     ExpnKind::Root => None,
 
@@ -413,7 +413,8 @@ pub trait Emitter {
 
                     ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
                 }
-            });
+            })
+            .collect();
 
         if !backtrace {
             self.fix_multispans_in_extern_macros(source_map, span, children);
@@ -422,11 +423,22 @@ pub trait Emitter {
         self.render_multispans_macro_backtrace(span, children, backtrace);
 
         if !backtrace {
-            if let Some((macro_kind, name)) = has_macro_spans {
-                let descr = macro_kind.descr();
+            if let Some((macro_kind, name)) = has_macro_spans.first() {
+                // Mark the actual macro this originates from
+                let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
+                    && last_name != name
+                {
+                    let descr = macro_kind.descr();
+                    format!(
+                        " which comes from the expansion of the {descr} `{last_name}`",
+                    )
+                } else {
+                    "".to_string()
+                };
 
+                let descr = macro_kind.descr();
                 let msg = format!(
-                    "this {level} originates in the {descr} `{name}` \
+                    "this {level} originates in the {descr} `{name}`{and_then} \
                     (in Nightly builds, run with -Z macro-backtrace for more info)",
                 );
 
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index e59a74e380a..b173ac0e916 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -6,6 +6,7 @@
 #![feature(drain_filter)]
 #![feature(backtrace)]
 #![feature(if_let_guard)]
+#![cfg_attr(bootstrap, feature(let_chains))]
 #![feature(let_else)]
 #![feature(never_type)]
 #![feature(adt_const_params)]