rust/src/librustdoc
Matthias Krüger 3376edac6d
Rollup merge of #132302 - fmease:rustdoc-better-vis-for-macro-decl, r=notriddle
rustdoc: Treat declarative macros more like other item kinds

Apparently at some time in the past we were unable to generate an href for the module path inside the visibility of decl macros 2.0 (`pub(in ...)`). As a result of this, a whole separate function was introduced specifically for printing the visibility of decl macros that didn't attempt to generate any links. The description of PR https://github.com/rust-lang/rust/pull/84074 states:

> This fixes the overly-complex invariant mentioned in https://github.com/rust-lang/rust/pull/83237#issuecomment-815346570, where the macro source can't have any links in it only because the cache hasn't been populated yet.

I can no longer reproduce the original issue. Reusing the existing visibility rendering logic *seems* to work just fine (I couldn't come up with any counterexamples, though I invite you to prove me wrong).

* Fixes #83000
* Fixes the visibility showing up "twice" in rustdoc-JSON output: Once as the `visibility` field, once baked into the source[^1]
* Fixes `#[doc(hidden)]` not getting rendered on doc(hidden) decl macros 2.0 under `--document-hiden-items` (for decl macros 1.2 the issue remains; I will address this separately when fixing #132304).

---

<details><summary>Outdated Section</summary>

NOTE: The current version of this PR is committing a UI crime, I'd like to receive feedback on that. Maybe you have a satisfactory solution for how to remedy it. Namely, as you know we have two different ways of / modes for highlighting code with color:

1. Only highlighting links / item paths and avoiding to highlight tokens by kind like keywords (to reduce visual noise and maybe also artifact size). Used for item declarations(\*).
2. Highlighting tokens by kind. Used for code blocks written by the user.

(\*): With the notable exception being macro declarations! Well, since this PR reuses the same function for rendering the item visibility (which only makes sense), we have a clash of modes: We now use both ways of highlighting code for decl macros: №1 for the visibility, №2 for the rest. This awkward. See for yourself:

* On master: ![Screenshot 2024-10-29 at 03-37-48 by_example_vis_named in decl_macro a b c - Rust](https://github.com/user-attachments/assets/22f0ab6e-9ba9-4c4e-8fb0-0741c91d360b)
* On this branch: ![Screenshot 2024-10-29 at 03-36-41 by_example_vis_named in decl_macro a b c - Rust](https://github.com/user-attachments/assets/b11d81a3-3e2e-43cb-a5b8-6773a3048732)

</details>

Furthermore, we now no longer syntax-highlight declarative macros (be it `macro_rules!` or `macro`) since that was inconsistent with the way we render all other item kinds. See (collapsed) *Outdated Section* above. See also https://github.com/rust-lang/rust/pull/132302#discussion_r1821310783.

| On master | On this branch |
|---|---|
| ![Screenshot 2024-11-13 at 16-12-46 by_example_vis_named in decl_macro a b c - Rust](https://github.com/user-attachments/assets/cb3aeb42-a56d-4ced-80d9-f2694f369af1) | ![Screenshot 2024-11-13 at 16-13-22 by_example_vis_named in decl_macro a b c - Rust](https://github.com/user-attachments/assets/b73bee50-1b85-4862-afba-5ad471443ccc) |

[^1]: E.g., `"visibility":{"restricted":{"parent":1,"path":"::a"}},/*OMITTED*/,"inner":{"macro":"pub(in a) macro by_example_vis_named($foo:expr) {\n    ...\n}"}`
2024-11-13 21:04:22 +01:00
..
clean Rollup merge of #132302 - fmease:rustdoc-better-vis-for-macro-decl, r=notriddle 2024-11-13 21:04:22 +01:00
doctest Rollup merge of #132210 - notriddle:notriddle/doctest-span-hack, r=GuillaumeGomez 2024-10-30 14:01:37 -07:00
formats Handle librustdoc cases of rustc::potential_query_instability lint 2024-10-06 10:39:03 +03:00
html Rollup merge of #132302 - fmease:rustdoc-better-vis-for-macro-decl, r=notriddle 2024-11-13 21:04:22 +01:00
json rustdoc: Directly use rustc_abi instead of reexports 2024-11-01 09:24:09 -07:00
passes Rename DocContext::is_json into DocContext::is_json_output 2024-11-04 17:29:57 +01:00
theme rustdoc: merge theme css into rustdoc.css 2023-09-15 07:40:17 -07:00
build.rs rustdoc: hash assets at rustdoc build time 2024-10-19 15:36:19 -07:00
Cargo.toml Update minifer version to 0.3.2 2024-11-10 16:32:22 +01:00
config.rs Rename target triple to target tuple in many places in the compiler 2024-11-02 21:29:59 +01:00
core.rs Auto merge of #126597 - estebank:unicode-output, r=fmease 2024-11-11 00:00:58 +00:00
docfs.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
doctest.rs Auto merge of #126597 - estebank:unicode-output, r=fmease 2024-11-11 00:00:58 +00:00
error.rs Fix clippy lints 2024-08-29 12:14:41 +02:00
externalfiles.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
fold.rs de-rc external traits 2024-09-25 23:45:57 +02:00
lib.rs Auto merge of #132282 - Noratrieb:it-is-the-end-of-serial, r=cjgillot 2024-11-12 15:14:56 +00:00
lint.rs Remove module passes filtering 2024-10-19 16:20:51 +02:00
markdown.rs rustdoc: Document markdown module. 2024-10-19 13:37:40 +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
rinja.toml Replace askama with rinja 2024-07-23 11:19:55 +02:00
scrape_examples.rs Fix file formatting 2024-11-07 17:13:00 +01:00
theme.rs Handle librustdoc cases of rustc::potential_query_instability lint 2024-10-06 10:39:03 +03:00
visit.rs rustdoc: add doc comment to DocVisitor 2024-09-28 19:21:37 -04:00
visit_ast.rs Rename DocContext::is_json into DocContext::is_json_output 2024-11-04 17:29:57 +01:00
visit_lib.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00

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