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

intra-rustdoc-link: Cannot use core in core crate #73445

Open
tesuji opened this issue Jun 17, 2020 · 17 comments
Open

intra-rustdoc-link: Cannot use core in core crate #73445

tesuji opened this issue Jun 17, 2020 · 17 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name D-confusing Diagnostics: Confusing error or lint that should be reworked. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Jun 17, 2020

I tried to document this code in libcore (./x.py doc src/libcore):

impl<T: Deref, E> Result<T, E> {
    /// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
    ///
    /// [`core::ops::Deref`]
    pub fn as_deref(&self) -> Result<&T::Target, &E>;
}

I expected to see the above code build pass.

Instead, this happened: Build failed the following errors:

 Documenting core v0.0.0 (/home/lzutao/fork/rust/compiler/src/libcore)
error: `[core::ops::Deref]` cannot be resolved, ignoring it.
    --> src/libcore/result.rs:1151:68
     |
1151 |     /// Coerces the [`Ok`] variant of the original [`Result`] via [`core::ops::Deref`]
     |                                                                    ^^^^^^^^^^^^^^^^^^ cannot be resolved, ignoring
     |
note: the lint level is defined here
    --> src/libcore/lib.rs:64:9
     |
64   | #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

error: Could not document `core`.

cc #43466
cc @Manishearth @GuillaumeGomez @jyn514

@tesuji
Copy link
Contributor Author

tesuji commented Jun 17, 2020

Note: Document build pass in user crate:

/// Intra link testings
///
/// [`Deref::Target`](core::ops::Deref)
pub struct Foo;

@jyn514
Copy link
Member

jyn514 commented Jun 17, 2020

What happens if you use crate::ops::Deref instead?

@jyn514
Copy link
Member

jyn514 commented Jun 17, 2020

Actually this might be a markdown issue, does [Deref::Target](core::ops::Deref) work in libcore?

@Manishearth
Copy link
Member

@lzutao core::ops::Deref will never work in the core crate, crates do not know their own names typically

@Manishearth
Copy link
Member

@jyn514 no, it's not a markdown issue

@jyn514
Copy link
Member

jyn514 commented Jun 17, 2020

@rustbot modify labels: T-rustdoc A-intra-doc-links D-confusing

@rustbot rustbot added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name D-confusing Diagnostics: Confusing error or lint that should be reworked. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 17, 2020
@jplatte
Copy link
Contributor

jplatte commented Jun 17, 2020

crates do not know their own names typically

Which can be worked around with an extern crate self as foo; in the crate root, in case anybody needs that (I've previously required it to get a proc macro working both inside its "parent crate" and outside of it).

@tesuji tesuji changed the title Cannot use intra-doc-link in core crate intra-rustdoc-link: Cannot use core in core crate Jun 17, 2020
@tesuji
Copy link
Contributor Author

tesuji commented Jun 17, 2020

Oh, using [`crate::path`] works correctly. It is kind of confusing through.

@Manishearth
Copy link
Member

I don't see how: cratename::foo never works in paths within the same crate

@tesuji
Copy link
Contributor Author

tesuji commented Jun 18, 2020

I cannot use std:: doc link prefix also.

 Documenting core v0.0.0 (/home/lzutao/fork/rust/compiler/src/libcore)
error: `[std::ops::Deref]` cannot be resolved, ignoring it.
    --> src/libcore/result.rs:1151:77
     |
1151 |     /// Coerces the [`Ok`] variant of the original [`Result`] via [`Deref`](std::ops::Deref)
     |                                                                             ^^^^^^^^^^^^^^^ cannot be resolved, ignoring
     |

@Manishearth

cratename::foo never works in paths within the same crate

You have a point. But for me what makes this confusing is that in doctest
I have to import items by crate name. But in doc link I don't have to.

@jyn514
Copy link
Member

jyn514 commented Jun 18, 2020

doctests are separate crates that have the original as a dependency. This is the reason you can't have doctests for private functions even if they're pub(crate).

@tesuji
Copy link
Contributor Author

tesuji commented Jun 18, 2020

Yes, that's understandable. But a note or help message in case resolve links fail could help.

@Manishearth
Copy link
Member

@lzutao well, yes, core does not have a std in it's dependencies

@Manishearth
Copy link
Member

Doctests are separate crates and this distinction comes up quite often anyway so I'm not sure if it needs to be fixed in intra doc links, I'd also be surprised if folks didn't know it as well.

@jyn514
Copy link
Member

jyn514 commented Dec 21, 2020

I still want to fix this; now that #73473 is fixed, it's blocked on #75176 (comment). I think this has value and is possible to implement so I'm re-opening - just because it doesn't work by default doesn't mean it has to never work.

@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

Update: this no longer ICEs, it just gives an error about duplicate macros:

error[E0773]: attempted to define built-in macro more than once
    --> /home/joshua/rust/library/core/src/macros/mod.rs:1201:5
     |
1201 | /     macro_rules! cfg {
1202 | |         ($($cfg:tt)*) => {
1203 | |             /* compiler built-in */
1204 | |         };
1205 | |     }
     | |_____^
     |
note: previously defined here
    --> /home/joshua/rust/library/core/src/macros/mod.rs:1201:5
     |
1201 | /     macro_rules! cfg {
1202 | |         ($($cfg:tt)*) => {
1203 | |             /* compiler built-in */
1204 | |         };
1205 | |     }
     | |_____^

error: Compilation failed, aborting rustdoc

Marking this as blocked on #83761.

@jyn514 jyn514 added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Apr 30, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

Oh I take it back - that's the error for std, core works just fine now :) might have been fixed by #83738. Making a PR shortly.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 5, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 5, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 5, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 6, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 6, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 6, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 6, 2021
Allow using `core::` in intra-doc links within core itself

I came up with this idea ages ago, but rustdoc used to ICE on it. Now it doesn't.

Helps with rust-lang#73445. Doesn't fix it completely since `extern crate self as std;` in std still gives strange errors.
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 D-confusing Diagnostics: Confusing error or lint that should be reworked. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. 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

5 participants