Fix intra-doc links for associated items by jyn514 · Pull Request #74489 · rust-lang/rust (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

jyn514

@jyn514 jyn514 added T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.

C-bug

Category: This is a bug.

A-intra-doc-links

Area: Intra-doc links, the ability to link to items in docs by name

labels

Jul 18, 2020

@jyn514 jyn514 added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jul 18, 2020

jyn514 added a commit to jyn514/rust that referenced this pull request

Jul 20, 2020

@jyn514

…solution failures

The version of rust-lang#74489 that warns about ambiguity errors

Manishearth

@jyn514

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Aug 23, 2020

This was referenced

Aug 24, 2020

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request

Sep 12, 2020

@Dylan-DPC

…tebank

Improve suggestions for broken intra-doc links

Depends on rust-lang#74489 and should not be merged before that PR. Merged 🎉 Depends on rust-lang#75916 and should not be merged before. Merged

Fixes rust-lang#75305.

This does a lot of different things 😆.

Places where this is currently buggy:

All outdated

1. When the link has the wrong namespace: Now fixed.

/// [type@S::h]
impl S {
    pub fn h() {}
}

/// [type@T::g]
pub trait T {
    fn g() {}
}
error: unresolved link to `T::g`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:53:6
   |
53 | /// [type@T::g]
   |      ^^^^^^^^^
   |
   = note: this link partially resolves to the trait `T`,
   = note: `T` has no field, variant, or associated item named `g`

error: unresolved link to `S::h`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:48:6
   |
48 | /// [type@S::h]
   |      ^^^^^^^^^
   |
   = note: this link partially resolves to the struct `S`,
   = note: `S` has no field, variant, or associated item named `h`

Instead it should suggest changing the disambiguator, the way it currently does for macros:

error: unresolved link to `S`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:38:6
   |
38 | /// [S!]
   |      ^^ help: to link to the unit struct, use its disambiguator: `value@S`
   |
   = note: this link resolves to the unit struct `S`, which is not in the macro namespace
  1. Associated items for values. It says that the value isn't in scope; instead it should say that values can't have associated items. Fixed.
error: unresolved link to `f::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:14:6
   |
14 | /// [f::A]
   |      ^^^^
   |
   = note: no item named `f` is in scope
   = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

This is mostly fixed, it now says

warning: unresolved link to `f::A`
 --> /home/joshua/test-rustdoc/f.rs:1:6
  |
1 | /// [f::A]
  |      ^^^^
  |
  = note: this link partially resolves to the function `f`
  = note: `f` is a function, not a module

'function, not a module' seems awfully terse when what I actually mean is ':: isn't allowed here', though.

It looks a lot nicer now, it says

error: unresolved link to `f::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:13:6
   |
13 | /// [f::A]
   |      ^^^^
   |
   = note: `f` is a function, not a module or type, and cannot have associated items
  1. I'm also not very happy with the second note for this error:
``` error: unresolved link to `S::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:19:6 | 19 | /// [S::A] | ^^^^ | = note: this link partially resolves to the struct `S`, = note: `S` has no field, variant, or associated item named `A` ```

but I'm not sure how better to word it.

I ended up going with 'no A in S' to match rustc_resolve but that seems terse as well.

This now says

error: unresolved link to `S::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:17:6
   |
17 | /// [S::A]
   |      ^^^^
   |
   = note: the struct `S` has no field or associated item named `A`

which I think looks pretty good :)

  1. This is minor, but it would be nice to say that path wasn't found instead of the full thing:
error: unresolved link to `path::to::nonexistent::module`
 --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:8:6
  |
8 | /// [path::to::nonexistent::module]
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It will now look at most 3 paths up (so it reports path::to as not in scope), but it doesn't work with arbitrarily many paths.

I recommend only reviewing the last few commits - the first 7 are all from rust-lang#74489. Rebased so that only the relevant commits are shown. Let me know if I should squash the history some more.

r? @estebank

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 12, 2020

@bors

…bank

Improve suggestions for broken intra-doc links

Depends on rust-lang#74489 and should not be merged before that PR. Merged 🎉 Depends on rust-lang#75916 and should not be merged before. Merged

Fixes rust-lang#75305.

This does a lot of different things 😆.

Places where this is currently buggy:

All outdated

1. When the link has the wrong namespace: Now fixed.

/// [type@S::h]
impl S {
    pub fn h() {}
}

/// [type@T::g]
pub trait T {
    fn g() {}
}
error: unresolved link to `T::g`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:53:6
   |
53 | /// [type@T::g]
   |      ^^^^^^^^^
   |
   = note: this link partially resolves to the trait `T`,
   = note: `T` has no field, variant, or associated item named `g`

error: unresolved link to `S::h`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:48:6
   |
48 | /// [type@S::h]
   |      ^^^^^^^^^
   |
   = note: this link partially resolves to the struct `S`,
   = note: `S` has no field, variant, or associated item named `h`

Instead it should suggest changing the disambiguator, the way it currently does for macros:

error: unresolved link to `S`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:38:6
   |
38 | /// [S!]
   |      ^^ help: to link to the unit struct, use its disambiguator: `value@S`
   |
   = note: this link resolves to the unit struct `S`, which is not in the macro namespace
  1. Associated items for values. It says that the value isn't in scope; instead it should say that values can't have associated items. Fixed.
error: unresolved link to `f::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:14:6
   |
14 | /// [f::A]
   |      ^^^^
   |
   = note: no item named `f` is in scope
   = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

This is mostly fixed, it now says

warning: unresolved link to `f::A`
 --> /home/joshua/test-rustdoc/f.rs:1:6
  |
1 | /// [f::A]
  |      ^^^^
  |
  = note: this link partially resolves to the function `f`
  = note: `f` is a function, not a module

'function, not a module' seems awfully terse when what I actually mean is ':: isn't allowed here', though.

It looks a lot nicer now, it says

error: unresolved link to `f::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:13:6
   |
13 | /// [f::A]
   |      ^^^^
   |
   = note: `f` is a function, not a module or type, and cannot have associated items
  1. I'm also not very happy with the second note for this error:
``` error: unresolved link to `S::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:19:6 | 19 | /// [S::A] | ^^^^ | = note: this link partially resolves to the struct `S`, = note: `S` has no field, variant, or associated item named `A` ```

but I'm not sure how better to word it.

I ended up going with 'no A in S' to match rustc_resolve but that seems terse as well.

This now says

error: unresolved link to `S::A`
  --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:17:6
   |
17 | /// [S::A]
   |      ^^^^
   |
   = note: the struct `S` has no field or associated item named `A`

which I think looks pretty good :)

  1. This is minor, but it would be nice to say that path wasn't found instead of the full thing:
error: unresolved link to `path::to::nonexistent::module`
 --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:8:6
  |
8 | /// [path::to::nonexistent::module]
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It will now look at most 3 paths up (so it reports path::to as not in scope), but it doesn't work with arbitrarily many paths.

I recommend only reviewing the last few commits - the first 7 are all from rust-lang#74489. Rebased so that only the relevant commits are shown. Let me know if I should squash the history some more.

r? @estebank

This was referenced

Sep 18, 2020

This was referenced

Oct 3, 2020

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request

Feb 25, 2021

@Dylan-DPC

Convert core/num/mod.rs to intra-doc links

Helps with rust-lang#75080. This can't convert the associated constants MAX and MIN until rust-lang#74489 is merged.

r? @poliorcetics

JohnTitor added a commit to JohnTitor/rust that referenced this pull request

Mar 2, 2021

@JohnTitor

wip-sync pushed a commit to NetBSD/pkgsrc-wip that referenced this pull request

Apr 10, 2021

@he32

Pkgsrc changes:

Version 1.51.0 (2021-03-25)

Language

Compiler

* Refer to Rust's [platform support page][forge-platform-support] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

Cargo

Rustdoc

Various improvements to intra-doc links:

Misc

Compatibility Notes

Internal Only

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request

May 26, 2021

@he32

Pkgsrc changes:

Upstream changes:

Version 1.51.0 (2021-03-25)

Language

Compiler

* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

Cargo

Rustdoc

Various improvements to intra-doc links:

Misc

Compatibility Notes

Internal Only