-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Doctest doesn't print valid assert file line and column location link #126251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems low priority. I value this feature though, so I'm willing to contribute to fixing this my self. But Id like pointers in knowing where to find the code relating to printing out file links. Like which repository. |
uh, rust-lang/rust? |
aiui doctests are actually extracted into a new file by librustdoc and then compiled, with no awareness of what their line/column was in the original file and thus no ability to offset them. you would have to probably poke at https://github.com/rust-lang/rust/blob/aec67e238d366c4c41373b272f19dd79ff5ec0f0/src/librustdoc/doctest.rs at minimum to address this. ( initially also said https://github.com/rust-lang/rust/blob/aec67e238d366c4c41373b272f19dd79ff5ec0f0/compiler/rustc_builtin_macros/src/source_util.rs but I think that's a red herring, now that I've reviewed the relevant |
By offset I meant I could probably first figure out what line the doctest itself is in the source file, then take that line number and add to what ever the current runner outputs. Seems simple enough? Or are there other things I need to worry about. My IDE seems to be able to figure out where a doctest lies (RustRover) assuming it is using some rust compiler API. |
The output is from the |
The runner doesn't know anything, it is only repeating this from the binary: rust/library/core/src/panic/panic_info.rs Lines 119 to 128 in ebcb862
It gets the location from here: rust/library/core/src/panic/location.rs Lines 88 to 90 in ebcb862
This is generated by compiler magic, about... here? rust/compiler/rustc_middle/src/ty/context.rs Line 1623 in ebcb862
But I believe the interesting code that actually determines the spans to output is here: rust/compiler/rustc_middle/src/mir/mod.rs Line 761 in ebcb862
Ideally we'd somehow convince rustdoc to use the original source spans while compiling this. |
oh, goofier solution: during extraction, insert sufficient newlines. |
That seems be a good idea |
Might not work if the test is sufficiently close to the top of the file, I think. |
I tried this code:
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.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: