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

Refactor and fix intra-doc link diagnostics, and fix links to primitives #76955

Merged
merged 3 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,30 @@ pub enum PrimTy {
Char,
}

impl PrimTy {
pub fn name_str(self) -> &'static str {
match self {
PrimTy::Int(i) => i.name_str(),
PrimTy::Uint(u) => u.name_str(),
PrimTy::Float(f) => f.name_str(),
PrimTy::Str => "str",
PrimTy::Bool => "bool",
PrimTy::Char => "char",
}
}

pub fn name(self) -> Symbol {
match self {
PrimTy::Int(i) => i.name(),
PrimTy::Uint(u) => u.name(),
PrimTy::Float(f) => f.name(),
PrimTy::Str => sym::str,
PrimTy::Bool => sym::bool,
PrimTy::Char => sym::char,
}
}
}

#[derive(Debug, HashStable_Generic)]
pub struct BareFnTy<'hir> {
pub unsafety: Unsafety,
Expand Down
435 changes: 204 additions & 231 deletions src/librustdoc/passes/collect_intra_doc_links.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: unresolved link to `v2`
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
|
LL | /// [v2]
| ^^ no item named `v2` in `deny_intra_link_resolution_failure`
| ^^ the module `deny_intra_link_resolution_failure` contains no item named `v2`
|
note: the lint level is defined here
--> $DIR/deny-intra-link-resolution-failure.rs:1:9
Expand Down
27 changes: 22 additions & 5 deletions src/test/rustdoc-ui/intra-link-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@

/// [path::to::nonexistent::module]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`

/// [path::to::nonexistent::macro!]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`

/// [type@path::to::nonexistent::type]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`

/// [std::io::not::here]
//~^ ERROR unresolved link
//~| NOTE the module `io` has no inner item
//~| NOTE `io` contains no item named `not`

/// [type@std::io::not::here]
//~^ ERROR unresolved link
//~| NOTE `io` contains no item named `not`

/// [std::io::Error::x]
//~^ ERROR unresolved link
Expand All @@ -32,6 +36,10 @@
//~^ ERROR unresolved link
//~| NOTE `f` is a function, not a module

/// [f::A!]
//~^ ERROR unresolved link
//~| NOTE `f` is a function, not a module

/// [S::A]
//~^ ERROR unresolved link
//~| NOTE struct `S` has no field or associated item
Expand All @@ -46,7 +54,16 @@

/// [u8::not_found]
//~^ ERROR unresolved link
//~| NOTE the builtin type `u8` does not have an associated item named `not_found`
//~| NOTE the builtin type `u8` has no associated item named `not_found`

/// [std::primitive::u8::not_found]
//~^ ERROR unresolved link
//~| NOTE the builtin type `u8` has no associated item named `not_found`

/// [type@Vec::into_iter]
//~^ ERROR unresolved link
//~| HELP to link to the associated function, add parentheses
//~| NOTE this link resolves to the associated function `into_iter`

/// [S!]
//~^ ERROR unresolved link
Expand Down
63 changes: 45 additions & 18 deletions src/test/rustdoc-ui/intra-link-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: unresolved link to `path::to::nonexistent::module`
--> $DIR/intra-link-errors.rs:7:6
|
LL | /// [path::to::nonexistent::module]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`
|
note: the lint level is defined here
--> $DIR/intra-link-errors.rs:1:9
Expand All @@ -14,64 +14,91 @@ error: unresolved link to `path::to::nonexistent::macro`
--> $DIR/intra-link-errors.rs:11:6
|
LL | /// [path::to::nonexistent::macro!]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`

error: unresolved link to `path::to::nonexistent::type`
--> $DIR/intra-link-errors.rs:15:6
|
LL | /// [type@path::to::nonexistent::type]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`

error: unresolved link to `std::io::not::here`
--> $DIR/intra-link-errors.rs:19:6
|
LL | /// [std::io::not::here]
| ^^^^^^^^^^^^^^^^^^ the module `io` has no inner item named `not`
| ^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`

error: unresolved link to `std::io::Error::x`
error: unresolved link to `std::io::not::here`
--> $DIR/intra-link-errors.rs:23:6
|
LL | /// [type@std::io::not::here]
| ^^^^^^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`

error: unresolved link to `std::io::Error::x`
--> $DIR/intra-link-errors.rs:27:6
|
LL | /// [std::io::Error::x]
| ^^^^^^^^^^^^^^^^^ the struct `Error` has no field or associated item named `x`

error: unresolved link to `std::io::ErrorKind::x`
--> $DIR/intra-link-errors.rs:27:6
--> $DIR/intra-link-errors.rs:31:6
|
LL | /// [std::io::ErrorKind::x]
| ^^^^^^^^^^^^^^^^^^^^^ the enum `ErrorKind` has no variant or associated item named `x`

error: unresolved link to `f::A`
--> $DIR/intra-link-errors.rs:31:6
--> $DIR/intra-link-errors.rs:35:6
|
LL | /// [f::A]
| ^^^^ `f` is a function, not a module or type, and cannot have associated items

error: unresolved link to `f::A`
--> $DIR/intra-link-errors.rs:39:6
|
LL | /// [f::A!]
| ^^^^^ `f` is a function, not a module or type, and cannot have associated items

error: unresolved link to `S::A`
--> $DIR/intra-link-errors.rs:35:6
--> $DIR/intra-link-errors.rs:43:6
|
LL | /// [S::A]
| ^^^^ the struct `S` has no field or associated item named `A`

error: unresolved link to `S::fmt`
--> $DIR/intra-link-errors.rs:39:6
--> $DIR/intra-link-errors.rs:47:6
|
LL | /// [S::fmt]
| ^^^^^^ the struct `S` has no field or associated item named `fmt`

error: unresolved link to `E::D`
--> $DIR/intra-link-errors.rs:43:6
--> $DIR/intra-link-errors.rs:51:6
|
LL | /// [E::D]
| ^^^^ the enum `E` has no variant or associated item named `D`

error: unresolved link to `u8::not_found`
--> $DIR/intra-link-errors.rs:47:6
--> $DIR/intra-link-errors.rs:55:6
|
LL | /// [u8::not_found]
| ^^^^^^^^^^^^^ the builtin type `u8` does not have an associated item named `not_found`
| ^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`

error: unresolved link to `std::primitive::u8::not_found`
--> $DIR/intra-link-errors.rs:59:6
|
LL | /// [std::primitive::u8::not_found]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`

error: unresolved link to `Vec::into_iter`
--> $DIR/intra-link-errors.rs:63:6
|
LL | /// [type@Vec::into_iter]
| ^^^^^^^^^^^^^^^^^^^
| |
| this link resolves to the associated function `into_iter`, which is not in the type namespace
| help: to link to the associated function, add parentheses: `Vec::into_iter()`

error: unresolved link to `S`
--> $DIR/intra-link-errors.rs:51:6
--> $DIR/intra-link-errors.rs:68:6
|
LL | /// [S!]
| ^^
Expand All @@ -80,7 +107,7 @@ LL | /// [S!]
| help: to link to the struct, prefix with `struct@`: `struct@S`

error: unresolved link to `T::g`
--> $DIR/intra-link-errors.rs:69:6
--> $DIR/intra-link-errors.rs:86:6
|
LL | /// [type@T::g]
| ^^^^^^^^^
Expand All @@ -89,13 +116,13 @@ LL | /// [type@T::g]
| help: to link to the associated function, add parentheses: `T::g()`

error: unresolved link to `T::h`
--> $DIR/intra-link-errors.rs:74:6
--> $DIR/intra-link-errors.rs:91:6
|
LL | /// [T::h!]
| ^^^^^ the trait `T` has no macro named `h`

error: unresolved link to `S::h`
--> $DIR/intra-link-errors.rs:61:6
--> $DIR/intra-link-errors.rs:78:6
|
LL | /// [type@S::h]
| ^^^^^^^^^
Expand All @@ -104,13 +131,13 @@ LL | /// [type@S::h]
| help: to link to the associated function, add parentheses: `S::h()`

error: unresolved link to `m`
--> $DIR/intra-link-errors.rs:81:6
--> $DIR/intra-link-errors.rs:98:6
|
LL | /// [m()]
| ^^^
| |
| this link resolves to the macro `m`, which is not in the value namespace
| help: to link to the macro, add an exclamation mark: `m!`

error: aborting due to 16 previous errors
error: aborting due to 20 previous errors

2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/intra-link-span-ice-55723.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: unresolved link to `i`
--> $DIR/intra-link-span-ice-55723.rs:9:10
|
LL | /// (arr[i])
| ^ no item named `i` in `intra_link_span_ice_55723`
| ^ the module `intra_link_span_ice_55723` contains no item named `i`
|
note: the lint level is defined here
--> $DIR/intra-link-span-ice-55723.rs:1:9
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/intra-links-warning-crlf.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:7:6
|
LL | /// [error]
| ^^^^^ no item named `error` in `intra_links_warning_crlf`
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error`
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
Expand All @@ -11,23 +11,23 @@ warning: unresolved link to `error1`
--> $DIR/intra-links-warning-crlf.rs:12:11
|
LL | /// docs [error1]
| ^^^^^^ no item named `error1` in `intra_links_warning_crlf`
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error1`
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

warning: unresolved link to `error2`
--> $DIR/intra-links-warning-crlf.rs:15:11
|
LL | /// docs [error2]
| ^^^^^^ no item named `error2` in `intra_links_warning_crlf`
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error2`
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:23:20
|
LL | * It also has an [error].
| ^^^^^ no item named `error` in `intra_links_warning_crlf`
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error`
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

Expand Down
Loading