file-level doctests have wrong file/line mapping when module has use-level doctest #79764
Open
Description
I have a module in an external file.
When I add doctests to both the pub mod X;
item, and the X.rs
file, the file-level doctest has the wrong filename/line information.
Consider the following example:
--- lib.rs ---
//! crate-level doctest
//!
//! ```
//! // lib.rs line 3
//! assert_eq!(1, 1);
//! ```
pub mod mod_with_file_doctest;
/// mod reference-level doctest
///
/// ```
/// // lib.rs line 12
/// assert_eq!(1, 1);
/// ```
pub mod mod_with_ref_doctest;
/// mod reference-level doctest
///
/// ```
/// // lib.rs line 20
/// assert_eq!(1, 1);
/// ```
pub mod mod_with_both_doctests;
--- mod_with_file_doctest.rs ---
//! mod file-level doctest
//!
//! ```
//! // mod_with_file_doctest.rs line 3
//! assert_eq!(1, 1);
//! ```
--- mod_with_both_doctests.rs ---
//! mod file-level doctest
//!
//! ```
//! // mod_with_both_doctests.rs line 3
//! assert_eq!(1, 1);
//! ```
Running cargo test
, I get the following output:
running 5 tests
test src\lib.rs - mod_with_both_doctests (line 20) ... ok
test src\lib.rs - mod_with_both_doctests (line 26) ... ok
test src\lib.rs - (line 3) ... ok
test src\mod_with_file_doctest.rs - mod_with_file_doctest (line 3) ... ok
test src\lib.rs - mod_with_ref_doctest (line 12) ... ok
The line test src\lib.rs - mod_with_both_doctests (line 26)
should actually be test src\mod_with_file_doctest.rs - mod_with_file_doctest (line 3)
Looks like that the line 26
is somehow relative to the pub mod
line.
I will look into this and try to get a PR together that fixes this.
Metadata
Assignees
Labels
Type
Projects
Status
No status