about summary refs log tree commit diff
path: root/src/librustdoc/doctest/rust.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/doctest/rust.rs')
-rw-r--r--src/librustdoc/doctest/rust.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs
index a9ab02e29cd..27d0be133fe 100644
--- a/src/librustdoc/doctest/rust.rs
+++ b/src/librustdoc/doctest/rust.rs
@@ -113,7 +113,19 @@ impl<'tcx> HirCollector<'tcx> {
         let attrs = Attributes::from_ast(ast_attrs);
         if let Some(doc) = attrs.opt_doc_value() {
             let span = span_of_fragments(&attrs.doc_strings).unwrap_or(sp);
-            self.collector.position = span;
+            self.collector.position = if span.edition().at_least_rust_2024() {
+                span
+            } else {
+                // this span affects filesystem path resolution,
+                // so we need to keep it the same as it was previously
+                ast_attrs
+                    .iter()
+                    .find(|attr| attr.doc_str().is_some())
+                    .map(|attr| {
+                        attr.span.ctxt().outer_expn().expansion_cause().unwrap_or(attr.span)
+                    })
+                    .unwrap_or(DUMMY_SP)
+            };
             markdown::find_testable_code(
                 &doc,
                 &mut self.collector,