rust/src/librustdoc
Matthias Krüger 97b5b9b817
Rollup merge of #148169 - fmease:rustdoc-bad-intra-bad-preprocess, r=lolbinarycat
Fix bad intra-doc-link preprocessing

How did rust-lang/rust#147981 happen?

1. We don't parse intra-doc links as Rust paths or qpaths. Instead they follow a very lenient bespoke grammar. We completely ignore Markdown links if they contain characters that don't match `/[a-zA-Z0-9_:<>, !*&;]/` (we don't even emit lint *broken-intra-doc-links* for these).
2. PR [#132748](https://github.com/rust-lang/rust/pull/132748) made rustdoc intepret more Markdown links as potential intra-doc links. Namely, if the link is surrounded by backticks (and some other conditions apply) then it doesn't matter if the (partially processed) link contains bad characters as defined above (cc `ignore_urllike && should_ignore_link(path_str)`).
3. However, rustdoc's `preprocess_link` must be kept in sync with a simplified counterpart in rustc. More specifically, whenever rustdoc's preprocessor returns a successful result then rustc's must yield the same result. Otherwise, rustc doesn't resolve the necessary links for rustdoc.
4. This uncovered a "dormant bug" / "mistake" in rustc's `preprocess_link`. Namely, when presented with a link like `struct@Type@suffix`, it didn't cut off the disambiguator if present (here: `struct@`). Instead it `rsplit('``@')``` which is incorrect if the "path" contains ```@``` itself (yielding `suffix` instead of `Type@suffix` here). Prior to PR [#132748](https://github.com/rust-lang/rust/pull/132748), a link like ``[`struct@Type@suffix`]`` was not considered a potential intra-doc link / worth querying rustc for. Now it is due to the backticks.
5. Finally, since rustc didn't record a resolution for `Type@suffix` (it only recorded `suffix` (to be `Res::Err`)), we triggered an assertion we have in place to catch cases like this.

Fixes rust-lang/rust#147981.

I didn't and still don't have the time to investigate if rust-lang/rust#132748 led to more rustc/rustdoc mismatches (after all, the PR made rustdoc's `preprocess_link` return `Some(Ok(_))` in more cases). I've at least added another much needed "warning banner" & made the existing one more flashy.

While this fixes a stable-to-beta regression, I don't think it's worth beta backporting, esp. since it's only P-medium and since the final 1.91 release steps commence today / the next days, so it would only be stressful to get it in on time. However, feel free to nominate.

<sub>(I've written such a verbose PR description since I tend to reread my old PR descriptions in the far future to fully freshen my memories when I have to work again in this area)</sub>

r? ``@lolbinarycat``
2025-11-30 18:44:22 +01:00
..
clean Rollup merge of #149334 - asukaminato0721:149288, r=notriddle 2025-11-27 15:59:13 +01:00
doctest fix(rustdoc): Color doctest errors 2025-11-11 17:23:35 -07:00
formats Remove UrlFragment::render method to unify clean::types::links and anchor 2025-11-18 18:30:47 +01:00
html Auto merge of #149327 - lolbinarycat:rustdoc-types-fixup, r=notriddle 2025-11-30 07:16:47 +00:00
json rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution 2025-11-21 09:22:59 +00:00
passes Rollup merge of #148169 - fmease:rustdoc-bad-intra-bad-preprocess, r=lolbinarycat 2025-11-30 18:44:22 +01:00
theme rustdoc: merge theme css into rustdoc.css 2023-09-15 07:40:17 -07:00
askama.toml Update to new rinja version (askama) 2025-04-03 15:38:08 +02:00
build.rs rustdoc-search: search backend with partitioned suffix tree 2025-08-15 10:26:03 -07:00
Cargo.toml Auto merge of #148896 - Kobzol:revert-146627, r=madsmtm 2025-11-13 21:15:20 +00:00
config.rs Rollup merge of #148234 - notriddle:doc-cci, r=GuillaumeGomez 2025-11-24 19:10:43 +01:00
core.rs Rollup merge of #147832 - aDotInTheVoid:rustdoc-format-options, r=GuillaumeGomez 2025-11-12 12:26:36 +11:00
display.rs Improve code 2025-11-11 18:45:36 +01:00
docfs.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
doctest.rs Auto merge of #148188 - Muscraft:annotate-snippets-default-on-nightly, r=estebank 2025-11-06 11:45:06 +00:00
error.rs Fix clippy lints 2024-08-29 12:14:41 +02:00
externalfiles.rs Ensure external paths passed via flags end up in rustdoc depinfo 2025-07-28 20:53:01 +02:00
fold.rs Add new doc(attribute = "...") attribute 2025-08-28 15:56:29 +02:00
lib.rs Simplify jemalloc setup 2025-11-23 10:44:13 +01:00
lint.rs rustdoc: remove unportable markdown lint and old parser 2025-05-06 10:33:04 -07:00
markdown.rs Lazy-ify some markdown rendering 2025-06-29 12:41:16 +00:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
scrape_examples.rs rustdoc: fix --emit=dep-info on scraped examples 2025-10-29 14:54:54 -07:00
theme.rs Fix new clippy lints 2024-11-28 03:05:43 +01:00
visit.rs Add new doc(attribute = "...") attribute 2025-08-28 15:56:29 +02:00
visit_ast.rs rustdoc: Don't pass RenderOptions to DocContext 2025-11-11 22:00:28 +00:00
visit_lib.rs rustdoc: Don't pass RenderOptions to DocContext 2025-11-11 22:00:28 +00:00

For more information about how librustdoc works, see the rustc dev guide.