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

Intradoc Self:: links are "not in scope" when used in impl blocks across modules #93205

Closed
MarijnS95 opened this issue Jan 22, 2022 · 4 comments · Fixed by #100348
Closed

Intradoc Self:: links are "not in scope" when used in impl blocks across modules #93205

MarijnS95 opened this issue Jan 22, 2022 · 4 comments · Fixed by #100348
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@MarijnS95
Copy link
Contributor

I tried this code:

/// Autogenerated code goes here
mod generated {
    pub struct MyNewType(pub(crate) u32);
    impl MyNewType {
        pub const FOO: Self = Self(1);
        pub const BAR: Self = Self(2);

        /// Reexport of [`Self::FOO`]
        pub const FOO2: Self = Self::FOO;
        /// Reexport of [`Self::FOO_BAR`]
        pub const FOO_BAR2: Self = Self::FOO_BAR;
    }
}

pub use generated::*;

/// Manual extensions for autogenerated code go here
mod prelude {
    impl super::MyNewType {
        /// Contraction of [`Self::FOO`] | [`Self::BAR`]
        pub const FOO_BAR: Self = Self(Self::FOO.0 | Self::BAR.0);

        /// Contraction of [`Self::FOO`] and [`Self::BAR`], see also [`Self::FOO_BAR`]
        pub fn raw_foo_bar() -> u32 {
            Self::FOO.0 | Self::BAR.0
        }
    }
}

I expected to see this happen: Self:: intradoc links for the impl block residing in mod prelude (where MyNewType is not defined) are valid links.

Instead, this happened: Rustdoc thinks that Self, resolved to MyNewType, is not in scope here:

warning: unresolved link to `MyNewType::FOO`
  --> src/lib.rs:20:30
   |
20 |         /// Contraction of [`Self::FOO`] | [`Self::BAR`]
   |                              ^^^^^^^^^ no item named `MyNewType` in scope
   |
   = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

warning: unresolved link to `MyNewType::BAR`
  --> src/lib.rs:20:46
   |
20 |         /// Contraction of [`Self::FOO`] | [`Self::BAR`]
   |                                              ^^^^^^^^^ no item named `MyNewType` in scope

warning: unresolved link to `MyNewType::FOO`
  --> src/lib.rs:23:30
   |
23 |         /// Contraction of [`Self::FOO`] and [`Self::BAR`], see also [`Self::FOO_BAR`]
   |                              ^^^^^^^^^ no item named `MyNewType` in scope

warning: unresolved link to `MyNewType::BAR`
  --> src/lib.rs:23:48
   |
23 |         /// Contraction of [`Self::FOO`] and [`Self::BAR`], see also [`Self::FOO_BAR`]
   |                                                ^^^^^^^^^ no item named `MyNewType` in scope

warning: unresolved link to `MyNewType::FOO_BAR`
  --> src/lib.rs:23:72
   |
23 |         /// Contraction of [`Self::FOO`] and [`Self::BAR`], see also [`Self::FOO_BAR`]
   |                                                                        ^^^^^^^^^^^^^ no item named `MyNewType` in scope

warning: `doc_experiments` (lib doc) generated 5 warnings

A workaround is to make sure that MyNewType, without super:: prefix, is in scope:

-    impl super::MyNewType
+    use super::MyNewType;
+    impl MyNewType {

In other words, it seems that Self in intradoc links resolve to the name of the item, not the full path?

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (9ad5d82f8 2022-01-18)
binary: rustc
commit-hash: 9ad5d82f822b3cb67637f11be2e65c5662b66ec0
commit-date: 2022-01-18
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
@MarijnS95 MarijnS95 added the C-bug Category: This is a bug. label Jan 22, 2022
@camelid camelid added the A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name label Jan 25, 2022
@camelid camelid self-assigned this Jan 25, 2022
@camelid
Copy link
Member

camelid commented Jan 25, 2022

I'll see if I can look into this. If someone else wants to work on it, feel free to claim it from me!

@camelid camelid added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 25, 2022
@camelid
Copy link
Member

camelid commented Aug 9, 2022

This appears to have since been fixed, probably by #93805.

@camelid camelid closed this as completed Aug 9, 2022
@camelid
Copy link
Member

camelid commented Aug 9, 2022

Actually, it'd probably be good to add a test for this.

@camelid camelid reopened this Aug 9, 2022
@camelid camelid added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 9, 2022
camelid added a commit to camelid/rust that referenced this issue Aug 10, 2022
This issue was most likely fixed by rust-lang#93805.
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 10, 2022
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#100286 (Add support for link-flavor rust-lld for macOS)
 - rust-lang#100317 (Remove logic related to deprecated nvptx-nvidia-cuda (32-bit) target)
 - rust-lang#100339 (Fixes bootstrap panic when running x fmt --check )
 - rust-lang#100348 (Add regression test for rust-lang#93205)
 - rust-lang#100349 (Refactor: remove a type string comparison)
 - rust-lang#100353 (Fix doc links in core::time::Duration::as_secs)
 - rust-lang#100359 (Special-case references to leafs in valtree pretty-printing)
 - rust-lang#100371 (Inline CStr::from_bytes_with_nul_unchecked::rt_impl)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in a6116b9 Aug 10, 2022
@MarijnS95
Copy link
Contributor Author

@camelid Thanks! That looks to already have trickled down into recent stable rust releases, as I can't reproduce it with 1.62.1. Awesome!

MarijnS95 added a commit to ash-rs/ash that referenced this issue Aug 11, 2022
The report at rust-lang/rust#93205 was closed
as it has presumably been fixed in
rust-lang/rust#93805 which has long trickled
down into stable releases, and I cannot reproduce the issue on `1.62.1`
anymore (latest stable as of writing) 🎉

This workaround was originally added in #559.
Ralith pushed a commit to ash-rs/ash that referenced this issue Aug 11, 2022
The report at rust-lang/rust#93205 was closed
as it has presumably been fixed in
rust-lang/rust#93805 which has long trickled
down into stable releases, and I cannot reproduce the issue on `1.62.1`
anymore (latest stable as of writing) 🎉

This workaround was originally added in #559.
MarijnS95 added a commit to ash-rs/ash that referenced this issue Aug 11, 2022
The report at rust-lang/rust#93205 was closed
as it has presumably been fixed in
rust-lang/rust#93805 which has long trickled
down into stable releases, and I cannot reproduce the issue on `1.62.1`
anymore (latest stable as of writing) 🎉

This workaround was originally added in #559.
MarijnS95 added a commit to ash-rs/ash that referenced this issue Aug 12, 2022
The report at rust-lang/rust#93205 was closed
as it has presumably been fixed in
rust-lang/rust#93805 which has long trickled
down into stable releases, and I cannot reproduce the issue on `1.62.1`
anymore (latest stable as of writing) 🎉

This workaround was originally added in #559.
MarijnS95 added a commit to ash-rs/ash that referenced this issue Sep 5, 2022
The report at rust-lang/rust#93205 was closed
as it has presumably been fixed in
rust-lang/rust#93805 which has long trickled
down into stable releases, and I cannot reproduce the issue on `1.62.1`
anymore (latest stable as of writing) 🎉

This workaround was originally added in #559.
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 C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants