Skip to content
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: Structured suggestion for intra-doc links based on current crate name #84721

Open
joshtriplett opened this issue Apr 29, 2021 · 6 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Apr 29, 2021

Within a crate xyz, the link [`xyz::path::some_item`] gives an error. This would be challenging to fix in the rustdoc resolver. However, we could provide a rustfix-applicable structured suggestion on the error, suggesting [`xyz::path::some_item`][`crate::path::some_item`].

@joshtriplett joshtriplett added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Apr 29, 2021
@jyn514 jyn514 added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Apr 29, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

Oh, I was proposing that rustdoc suggest extern crate self as xyz; in the crate root, which means you only have to do it once instead of for each link. But suggesting [crate:: also works.

@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

Note that rustfix currently doesn't work for rustdoc: rust-lang/cargo#13025

@joshtriplett
Copy link
Member Author

@jyn514 Suggesting the extern crate solution seems potentially workable, though it's unfortunate to suggest the use of extern crate when it's otherwise unneeded in Rust 2018.

Perhaps use crate as xyz;? (Or use crate::self as xyz; if use crate doesn't work?)

@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

Perhaps use crate as xyz;?

Oh nice, I didn't expect that to work. Yes, that sounds better :)

//! [playground::f]
use crate as playground;

pub fn f() {}

@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

Oh wait, that only works for the top-level, it doesn't affect submodules:

use crate as playground;

mod inner {
    //! [playground::inner::f] //~ ERROR no item named `playground` in scope
    pub fn f() {}
}

So I do think the extern crate self approach works better here.

@camelid
Copy link
Member

camelid commented Apr 30, 2021

Oh wait, that only works for the top-level, it doesn't affect submodules:

use crate as playground;

mod inner {
    //! [playground::inner::f] //~ ERROR no item named `playground` in scope
    pub fn f() {}
}

So I do think the extern crate self approach works better here.

Yeah, stuff in the parent module (like uses) doesn't usually show up in child modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants