]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/test.rs
Auto merge of #73842 - euclio:doctest-expn, r=GuillaumeGomez
[rust.git] / src / librustdoc / test.rs
index b86a105ff7664b22b0daca867544ad71236896bb..969f5a2eaf143b331fbec8cf21390bc8f8cfa96d 100644 (file)
@@ -943,7 +943,12 @@ fn visit_testable<F: FnOnce(&mut Self)>(
         // The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
         // anything else, this will combine them for us.
         if let Some(doc) = attrs.collapsed_doc_value() {
-            self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
+            // Use the outermost invocation, so that doctest names come from where the docs were written.
+            let span = attrs
+                .span
+                .map(|span| span.ctxt().outer_expn().expansion_cause().unwrap_or(span))
+                .unwrap_or(DUMMY_SP);
+            self.collector.set_position(span);
             markdown::find_testable_code(
                 &doc,
                 self.collector,