-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[rustdoc] Allow to link to current crate #137935
base: master
Are you sure you want to change the base?
[rustdoc] Allow to link to current crate #137935
Conversation
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.
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.
Hum... Making it non-breaking seems simpler. I'll add it only if there are no other item matching.
.or_else(|| { | ||
if self.cx.tcx.crate_name(LOCAL_CRATE).as_str() == path_str { | ||
Some(Res::from_def_id(self.cx.tcx, CRATE_DEF_ID.to_def_id())) | ||
} else { | ||
None | ||
} | ||
}); |
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.
I'm not sure if this is the right place to put it. This runs in the context of the crate that's being documented, not in the context of the item having its names resolved, which seems like it would behave wrong when cross-crate inlining happens.
Shouldn't the doc_link_resolutions
(in rustc_resolve
) query be updated instead?
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.
Hum, fair enough. Gonna move it there then.
Moved it into |
|
||
//@ has 'bar/index.html' | ||
//@ has - '//*[@class="docblock"]//a[@href="index.html"]' 'bar' | ||
//! [`bar`] |
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.
Test case for [crate@bar]
?
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.
There is no crate
disambiguator. Can be added in a follow-up.
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.
Also, an integration test for cross-crate inlining?
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.
Good point!
5a0eb4f
to
ad8a77a
Compare
Added the test for inlined crate link. |
Can you not use |
There is no |
I meant using: //! [`bar`](crate)
which already works. It would be surprising if you could refer to the current crate using its name in intra-doc links when you can't in code. |
Oh I see. Well it does, but it's also nice to be able to link to the current crate with its name too. |
I'm not convinced that it's a good idea to support linking to the current crate by its name, since Rust can't #![crate_name = "tarte"]
use crate as myself; // works
use tarte as myself; //~ERROR no external crate `tarte` |
@rfcbot fcp close |
Team member @notriddle has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
It's also possible for users to do this crate-wide if they want with |
Part of #137857.
Seems surprising that we cannot link to the current crate, so this PR adds it.
r? @notriddle