-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use real Spans when resolving intra-doc links #78797
Conversation
This comment has been minimized.
This comment has been minimized.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jyn514 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like something is going wrong I didn't expect:
---- [rustdoc] rustdoc/intra-link-cross-crate-crate.rs stdout ----
error: htmldocck failed!
status: exit code: 1
command: "/usr/bin/python2.7" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/intra-link-cross-crate-crate" "/checkout/src/test/rustdoc/intra-link-cross-crate-crate.rs"
stdout:
------------------------------------------
------------------------------------------
stderr:
------------------------------------------
5: @has check failed
`XPATH PATTERN` did not match
// @has outer/fn.f.html '//a[@href="../inner/fn.g.html"]' "crate::g"
I'm not sure exactly what - you'd have to debug it. I normally debug issues something like this:
- Run rustdoc on the file without going through compiletest:
rustdoc +stage1 src/test/rustdoc/intra-link-cross-crate-crate.rs
- See what the differences are between the generated file and the expected. It will be in
doc/
somewhere, in this caseouter
. - If you're not sure what's wrong after seeing the difference, look at the debug output:
RUSTDOC_LOG=rustdoc::passes::collect=debug rustdoc +stage1 src/test/rustdoc/intra-link-cross-crate-crate.rs
. If this gives a warning about logging being disabled, setdebug-logging = true
and rebuild, then run it again.
Okay so the difference here boils down to the following: - <a class="fn" href="fn.f.html" title="outer::f fn">f</a></td><td class="docblock-short"><p>Links to <a href="../inner/fn.g.html" title="crate::g">crate::g</a></p>
+ <a class="fn" href="fn.f.html" title="outer::f fn">f</a></td><td class="docblock-short"><p>Links to [crate::g]</p> As the error says, the link to I'm not sure where to go from here. One question is even if we want to leave the link text as I added some debug statements and found this, not sure how useful it is.
|
@pitaj if you resolve
But you could change that to allow $ and see if [$crate] does anything useful.
|
Also, what's the span of the item? It should have a span in
I don't think we should ever change the link text on re-exports. pub fn g() {}
/// Link to [crate::g]
pub fn f() {}
// outer
pub use inner::g;
pub use inner::f; |
It does have the correct span, at least in the item here. The resolve call also has the correct span, but
|
Can you try resolving |
I haven't tried it on its own, but I did a little more digging, and I found that resolve gets a
But because that resolves to a module, no further resolution is performed in the following block, and rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 432 to 562 in dc06a36
|
@pitaj that match shouldn't be hit at all, it's for associated items. This should be going through rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 381 to 383 in dc06a36
rustc_resolve returned an error.
|
I see. I'll try |
I approached the just- /// Links to [crate]
/// Links to [crate::g]
pub fn f() {}
pub fn g() {} And changed the replacement to also handle a path of just }
- } else if path_str.starts_with("crate::") {
+ } else if path_str.starts_with("crate::") || path_str == "crate" {
// Resolve `crate` relative to the original scope of the item, not the current scope. It does resolve, but the link in
|
@petrochenkov do you know what's going wrong here? |
This comment has been minimized.
This comment has been minimized.
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
|
So what's my next step here? I need to replace all those instances with |
Yes.
I think yes.
No, as you can see |
I've replaced all instances I could find, but I may have done so too naively, as it is still failing in the same way. @rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
@pitaj I think you need to change rust/compiler/rustc_resolve/src/lib.rs Lines 3201 to 3202 in 09c9c9f
|
I replaced those too, and locally it didn't make a difference. I expect the CI run to fail the same way. |
I didn't consider that crate info is currently lost during span decoding from metadata, unless you are decoding a whole macro. Then I guess you'll have to remove |
@petrochenkov that's the hack that broke this in the first place: #78696. Is it possible to load that metadata even for things that aren't macros? |
Yes, and we need to do that eventually, but right now it will break a lot of assumptions in resolve and other places. |
@petrochenkov there are a few cases that hack handles, all of them dealing with cross-crate re-exports: // crate1
//! Link to [crate::f]
pub fn f() {}
// crate2
pub use crate1; Here // crate1
//! Link to [crate::u8]
pub mod u8 {}
// crate2
pub use crate1; Here removing
// Uncomment this and the warning will go away
// use crate::io::Read;
pub mod io {
pub trait Read {
fn read(&mut self);
}
}
pub mod bufreader {
//! [`crate::TcpStream::read`]
use crate::io::Read;
}
pub struct TcpStream;
impl crate::io::Read for TcpStream {
fn read(&mut self) {
}
} Here There are a few paths forward:
Both 2 and 3 make me nervous - I'm ok with them as a temporary workaround, but 3. doesn't actually help very much and 2. make me nervous other things have been missed. I would slightly prefer to wait for 1. but if @pitaj wants to take on 2. I'd be willing to review it. |
Given that there is already a hack that allows that case to work (use super:: instead) I'd rather wait for (1) than implement another hack. I would be interested in trying my hand at (1) if there's mentoring available. |
Fixes #78696
Tested this works locally by modifying
bufreader.rs
like so:@rustbot modify labels: T-doc, A-intra-doc-links
r? @jyn514