Skip to content

rustdoc: fix ICE from rustc_resolve and librustdoc parse divergence #110501

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

Merged
merged 1 commit into from
Apr 21, 2023
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
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ fn preprocess_link(link: &str) -> Box<str> {
let link = link.strip_suffix("{}").unwrap_or(link);
let link = link.strip_suffix("[]").unwrap_or(link);
let link = if link != "!" { link.strip_suffix('!').unwrap_or(link) } else { link };
let link = link.trim();
strip_generics_from_path(link).unwrap_or_else(|_| link.into())
}

Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// this test used to ICE
#![deny(rustdoc::broken_intra_doc_links)]
//! [Clone ()]. //~ ERROR unresolved
//! [Clone !]. //~ ERROR incompatible
//! [`Clone ()`]. //~ ERROR unresolved
//! [`Clone !`]. //~ ERROR incompatible
54 changes: 54 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:3:6
|
LL | //! [Clone ()].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
|
note: the lint level is defined here
--> $DIR/issue-110495-suffix-with-space.rs:2:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the trait, prefix with `trait@`
|
LL - //! [Clone ()].
LL + //! [trait@Clone ].
|

error: incompatible link kind for `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:4:6
|
LL | //! [Clone !].
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
|
help: to link to the derive macro, prefix with `derive@`
|
LL - //! [Clone !].
LL + //! [derive@Clone ].
|

error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:5:7
|
LL | //! [`Clone ()`].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
|
help: to link to the trait, prefix with `trait@`
|
LL - //! [`Clone ()`].
LL + //! [`trait@Clone (`].
|

error: incompatible link kind for `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:6:7
|
LL | //! [`Clone !`].
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
|
help: to link to the derive macro, prefix with `derive@`
|
LL | //! [`derive@Clone !`].
| +++++++

error: aborting due to 4 previous errors