rust-lang / rust-lang/rust

Doctest doesn't print valid assert file line and column location link

Open
#126,251 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-doctests C-enhancement T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

//! Tools for encoding and decoding instructions into and from an intuitive structure.
//! 
//! ERROR HAPPENS ON THIS LINE??: The instruction encoding and decoding format involved an intermediate format. Instructions involve 2 mandatory 
//! driver b.... 

struct SomethingToTakeLines {
// a // Rust says error happend here or so
// b
}

impl Driver {
	/// TODO: Implement test
	/// ```
	/// assert!(false); // Target should be here. 
	/// ```
	pub fn from_encoded(bytes: [u8; 2]) -> Self { ... }
}

I expected to see this happen:
I expected a link to line 1 of the doctest

Instead, this happened:
Line 3 of the entire parent file.

assertion failed: false
thread 'main' panicked at src\processor\src\instruction.rs:3:1:

Meta

rustc --version --verbose:

rustc 1.77.0-nightly (e51e98dde 2023-12-31)
binary: rustc
commit-hash: e51e98dde6a60637b6a71b8105245b629ac3fe77
commit-date: 2023-12-31
host: x86_64-pc-windows-msvc
release: 1.77.0-nightly
LLVM version: 17.0.6

Backtrace

"C:/Users/Rayyan Khan/.cargo/bin/cargo.exe" test --color=always --doc "instruction::from_encoded\ (line\ 69)" --no-fail-fast --manifest-path "C:\Users\Rayyan Khan\Desktop\The Four Elements\Processor\src\processor\Cargo.toml" -- --format=json -Z unstable-options --show-output
Testing started at 11:34 PM ...
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
   Compiling atln-processor v0.1.0 (C:\Users\Rayyan Khan\Desktop\The Four Elements\Processor\src\processor)
warning: unused variable: `memory`
  --> src\processor\src\lib.rs:41:52
   |
41 |     pub fn execute(&mut self, stream: &mut impl Read, memory: &mut Memory) -> Result<(), ExecuteError> {
   |                                                       ^^^^^^ help: if this is intentional, prefix it with an underscore: `_memory`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `atln-processor` (lib) generated 1 warning (run `cargo fix --lib -p atln-processor` to apply 1 suggestion)
    Finished test [unoptimized + debuginfo] target(s) in 1.12s
   Doc-tests atln-processor
Test executable failed (exit code: 101).

stderr:

assertion failed: false
thread 'main' panicked at src\processor\src\instruction.rs:3:1:
assertion failed: false
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\core\src\panicking.rs:72
   2: core::panicking::panic
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\core\src\panicking.rs:144
   3: std::rt::lang_start
   4: std::rt::lang_start
   5: std::rt::lang_start
   6: __ImageBase
   7: std::rt::lang_start
   8: std::rt::lang_start_internal::closure$2
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\rt.rs:148
   9: std::panicking::try::do_call
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\panicking.rs:552
  10: std::panicking::try
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\panicking.rs:516
  11: std::panic::catch_unwind
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\panic.rs:142
  12: std::rt::lang_start_internal
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library\std\src\rt.rs:148
  13: std::rt::lang_start
  14: main
  15: invoke_main
             at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  16: __scrt_common_main_seh
             at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  17: BaseThreadInitThunk
  18: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


error: doctest failed, to rerun pass `--doc`
error: 1 target failed:
    `--doc`

Process finished with exit code 101

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the reported cargo doc-test command for instruction::from_encoded and compare the panic location in src\processor\src\instruction.rs with the doctest's source line. Trace how doctest locations are reported, then verify that the diagnostic links to the assertion's line and column rather than the parent file location.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.