rustdoc: use the correct span for doctests
This commit is contained in:
parent
749f80ab05
commit
65e432db60
@ -122,23 +122,14 @@ fn visit_testable<F: FnOnce(&mut Self)>(
|
||||
// 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)),
|
||||
);
|
||||
}
|
||||
|
||||
|
7
tests/rustdoc-ui/doctest/doctest-output-include-fail.md
Normal file
7
tests/rustdoc-ui/doctest/doctest-output-include-fail.md
Normal file
@ -0,0 +1,7 @@
|
||||
With a code sample, that has an error:
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
let x = 234 // no semicolon here! oh no!
|
||||
}
|
||||
```
|
7
tests/rustdoc-ui/doctest/doctest-output-include-fail.rs
Normal file
7
tests/rustdoc-ui/doctest/doctest-output-include-fail.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ compile-flags:--test --test-args=--test-threads=1
|
||||
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
|
||||
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
|
||||
//@ failure-status: 101
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/130470
|
||||
#![doc = include_str!("doctest-output-include-fail.md")]
|
24
tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout
Normal file
24
tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
running 1 test
|
||||
test $DIR/doctest-output-include-fail.md - (line 3) ... FAILED
|
||||
|
||||
failures:
|
||||
|
||||
---- $DIR/doctest-output-include-fail.md - (line 3) stdout ----
|
||||
error: expected `;`, found `}`
|
||||
--> $DIR/doctest-output-include-fail.md:5:16
|
||||
|
|
||||
LL | let x = 234 // no semicolon here! oh no!
|
||||
| ^ help: add `;` here
|
||||
LL | }
|
||||
| - unexpected token
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
Couldn't compile the test.
|
||||
|
||||
failures:
|
||||
$DIR/doctest-output-include-fail.md - (line 3)
|
||||
|
||||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
running 3 tests
|
||||
test $DIR/doctest-output.rs - (line 8) ... ok
|
||||
test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok
|
||||
test $DIR/doctest-output.rs - ExpandedStruct (line 25) ... ok
|
||||
test $DIR/doctest-output.rs - foo::bar (line 18) ... ok
|
||||
|
||||
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
||||
|
Loading…
Reference in New Issue
Block a user