Skip to content

Commit 1e0e618

Browse files
committed
Auto merge of #73842 - euclio:doctest-expn, r=GuillaumeGomez
Use outermost invocation span for doctest names Fixes #70090. This PR also allows using aux-build files in rustdoc-ui tests.
2 parents 8b26609 + 6088079 commit 1e0e618

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

src/librustdoc/test.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,12 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
943943
// The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
944944
// anything else, this will combine them for us.
945945
if let Some(doc) = attrs.collapsed_doc_value() {
946-
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
946+
// Use the outermost invocation, so that doctest names come from where the docs were written.
947+
let span = attrs
948+
.span
949+
.map(|span| span.ctxt().outer_expn().expansion_cause().unwrap_or(span))
950+
.unwrap_or(DUMMY_SP);
951+
self.collector.set_position(span);
947952
markdown::find_testable_code(
948953
&doc,
949954
self.collector,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! attrs_on_struct {
3+
( $( #[$attr:meta] )* ) => {
4+
$( #[$attr] )*
5+
pub struct ExpandedStruct;
6+
}
7+
}

src/test/rustdoc-ui/doctest-output.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// edition:2018
2+
// aux-build:extern_macros.rs
13
// compile-flags:--test --test-args=--test-threads=1
24
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
35
// check-pass
@@ -6,10 +8,20 @@
68
//! assert_eq!(1 + 1, 2);
79
//! ```
810
11+
extern crate extern_macros as macros;
12+
13+
use macros::attrs_on_struct;
14+
915
pub mod foo {
1016

1117
/// ```
1218
/// assert_eq!(1 + 1, 2);
1319
/// ```
1420
pub fn bar() {}
1521
}
22+
23+
attrs_on_struct! {
24+
/// ```
25+
/// assert!(true);
26+
/// ```
27+
}
+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
running 2 tests
3-
test $DIR/doctest-output.rs - (line 5) ... ok
4-
test $DIR/doctest-output.rs - foo::bar (line 11) ... ok
2+
running 3 tests
3+
test $DIR/doctest-output.rs - (line 7) ... ok
4+
test $DIR/doctest-output.rs - ExpandedStruct (line 23) ... ok
5+
test $DIR/doctest-output.rs - foo::bar (line 17) ... ok
56

6-
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
7+
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
78

src/tools/compiletest/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl fmt::Display for Debugger {
169169
}
170170

171171
/// Configuration for compiletest
172-
#[derive(Clone)]
172+
#[derive(Debug, Clone)]
173173
pub struct Config {
174174
/// `true` to to overwrite stderr/stdout files instead of complaining about changes in output.
175175
pub bless: bool,

src/tools/compiletest/src/runtest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,8 @@ impl<'test> TestCx<'test> {
18851885
emit_metadata: EmitMetadata,
18861886
allow_unused: AllowUnused,
18871887
) -> Command {
1888-
let is_rustdoc = self.is_rustdoc();
1888+
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
1889+
let is_rustdoc = self.is_rustdoc() && !is_aux;
18891890
let mut rustc = if !is_rustdoc {
18901891
Command::new(&self.config.rustc_path)
18911892
} else {
@@ -3573,6 +3574,7 @@ impl ProcRes {
35733574
}
35743575
}
35753576

3577+
#[derive(Debug)]
35763578
enum TargetLocation {
35773579
ThisFile(PathBuf),
35783580
ThisDirectory(PathBuf),

0 commit comments

Comments
 (0)