about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-09-20 06:43:39 +0200
committerGitHub <noreply@github.com>2024-09-20 06:43:39 +0200
commitee4afa39a27ff2636f5ee62754dab089ced3569b (patch)
tree66d23fa44cd55911d09b92130f4090aa9e40719d /src
parentee2bec0af741eacb63ee77286939f6fc2db24ce3 (diff)
parent65e432db60bde00f15991a7cbdfffbdca2d4038b (diff)
Rollup merge of #130582 - notriddle:notriddle/doctest-span, r=GuillaumeGomez
rustdoc: use the correct span for doctests

Fixes #130470
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/doctest/rust.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs
index 5c0898f28fc..71a0e3d72de 100644
--- a/src/librustdoc/doctest/rust.rs
+++ b/src/librustdoc/doctest/rust.rs
@@ -122,23 +122,14 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
         // anything else, this will combine them for us.
         let attrs = Attributes::from_ast(ast_attrs);
         if let Some(doc) = attrs.opt_doc_value() {
-            // Use the outermost invocation, so that doctest names come from where the docs were written.
-            let span = 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);
+            let span = span_of_fragments(&attrs.doc_strings).unwrap_or(sp);
             self.collector.position = span;
             markdown::find_testable_code(
                 &doc,
                 &mut self.collector,
                 self.codes,
                 self.enable_per_target_ignores,
-                Some(&crate::html::markdown::ExtraInfo::new(
-                    self.tcx,
-                    def_id,
-                    span_of_fragments(&attrs.doc_strings).unwrap_or(sp),
-                )),
+                Some(&crate::html::markdown::ExtraInfo::new(self.tcx, def_id, span)),
             );
         }