From 8fd9353de00306d2115eecc4e79be9798cd2bd33 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Sun, 6 Dec 2020 21:00:50 +0100 Subject: [PATCH] Use the correct file/line for doctests from split mod comment When adding two separate doc comments to a `mod`, one item-level doc for the `mod` statement, and one file-level doc for the module file, doctests that are defined in the module file get the wrong filename/line assigned to them. --- src/test/rustdoc-ui/issue-79764/a/another_mod.rs | 4 ++++ .../issue-79764/a/compiletest-ignore-dir | 0 src/test/rustdoc-ui/issue-79764/a/mod.rs | 10 ++++++++++ src/test/rustdoc-ui/issue-79764/mod.rs | 14 ++++++++++++++ src/test/rustdoc-ui/issue-79764/mod.stdout | 9 +++++++++ 5 files changed, 37 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-79764/a/another_mod.rs create mode 100644 src/test/rustdoc-ui/issue-79764/a/compiletest-ignore-dir create mode 100644 src/test/rustdoc-ui/issue-79764/a/mod.rs create mode 100644 src/test/rustdoc-ui/issue-79764/mod.rs create mode 100644 src/test/rustdoc-ui/issue-79764/mod.stdout diff --git a/src/test/rustdoc-ui/issue-79764/a/another_mod.rs b/src/test/rustdoc-ui/issue-79764/a/another_mod.rs new file mode 100644 index 0000000000000..a41150798826e --- /dev/null +++ b/src/test/rustdoc-ui/issue-79764/a/another_mod.rs @@ -0,0 +1,4 @@ +//! ``` +//! // ^ a/another_mod.rs line 1 +//! assert_eq!(1, 1); +//! ``` diff --git a/src/test/rustdoc-ui/issue-79764/a/compiletest-ignore-dir b/src/test/rustdoc-ui/issue-79764/a/compiletest-ignore-dir new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/test/rustdoc-ui/issue-79764/a/mod.rs b/src/test/rustdoc-ui/issue-79764/a/mod.rs new file mode 100644 index 0000000000000..f8541dec7c8d6 --- /dev/null +++ b/src/test/rustdoc-ui/issue-79764/a/mod.rs @@ -0,0 +1,10 @@ +//! ``` +//! // ^ a/mod.rs line 1 +//! assert_eq!(1, 1); +//! ``` + +/// ``` +/// // ^ a/mod.rs line 6 +/// assert_eq!(1, 1); +/// ``` +pub mod another_mod; diff --git a/src/test/rustdoc-ui/issue-79764/mod.rs b/src/test/rustdoc-ui/issue-79764/mod.rs new file mode 100644 index 0000000000000..6e161d4c0c19c --- /dev/null +++ b/src/test/rustdoc-ui/issue-79764/mod.rs @@ -0,0 +1,14 @@ +// check-pass +// compile-flags:--test +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" + +// The literal `mod` in the doctest comments makes rustdoc emit a bogus +// `extern crate mod;` line which would break the doctests. +#![doc(test(no_crate_inject))] + +/// ``` +/// // ^ mod.rs line 10 +/// assert_eq!(1, 1); +/// ``` +pub mod a; diff --git a/src/test/rustdoc-ui/issue-79764/mod.stdout b/src/test/rustdoc-ui/issue-79764/mod.stdout new file mode 100644 index 0000000000000..b9f5bd22fc300 --- /dev/null +++ b/src/test/rustdoc-ui/issue-79764/mod.stdout @@ -0,0 +1,9 @@ + +running 4 tests +test $DIR/issue-79764/mod.rs - a (line 14) ... ok +test $DIR/issue-79764/mod.rs - a (line 10) ... ok +test $DIR/issue-79764/a/mod.rs - a::another_mod (line 6) ... ok +test $DIR/issue-79764/a/mod.rs - a::another_mod (line 10) ... ok + +test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME +