rust/src/librustdoc
bors 4ff90232a0 Auto merge of #90475 - camelid:docvisitor, r=notriddle
rustdoc: Add `DocVisitor` and use it where possible

`DocFolder` allows transforming the docs, accomplished by making its methods take and return types by-value. However, several of the rustdoc `DocFolder` impls only *visit* the docs; they don't change anything. Passing around types by-value is thus unnecessary, confusing, and potentially inefficient for those impls.

`DocVisitor` is very similar to `DocFolder`, except that its methods take shared references and return nothing (i.e., the unit type). This should both be more efficient and make the code clearer.

There is an additional reason to add `DocVisitor`, too. As part of my cleanup of `external_traits`, I'm planning to add a `fn cache(&mut self) -> &mut Cache` method to `DocFolder` so that `external_traits` can be retrieved explicitly from the `Cache`, rather than implicitly via `Crate.external_traits` (which is an `Rc<RefCell<...>>`). However, some of the `DocFolder` impls that could be turned into `DocVisitor` impls only have a shared reference to the `Cache`, because they are used during rendering. (They have to access the `Cache` via `html::render::Context.shared.cache`, which involves an `Rc`.)

Since `DocVisitor` does not mutate any of the types it's visiting, its equivalent `cache()` method will only need a shared reference to the `Cache`, avoiding the problem described above.

r? `@GuillaumeGomez`
cc `@jyn514`
2021-11-03 21:10:22 +00:00
..
clean Split doc_cfg and doc_auto_cfg features 2021-11-02 16:55:50 +01:00
doctest Rename --display-warnings to --display-doctest-warnings 2021-09-14 10:49:56 +02:00
formats Fix invalid handling of generics 2021-10-29 20:54:15 +02:00
html Auto merge of #90475 - camelid:docvisitor, r=notriddle 2021-11-03 21:10:22 +00:00
json Fix invalid handling of generics 2021-10-29 20:54:15 +02:00
passes List all cases explicitly in Doc{Folder,Visitor} 2021-11-01 16:15:46 -07:00
theme Clean up rustdoc static files 2021-07-07 17:52:18 +02:00
Cargo.toml rustdoc: Switch to mainline rayon 2021-10-28 18:26:57 -07:00
config.rs Fix clippy lints in librustdoc 2021-10-25 11:30:09 +02:00
core.rs Fix clippy lints in librustdoc 2021-10-25 11:30:09 +02:00
docfs.rs rustdoc: Remove a single-use macro 2021-10-28 18:39:32 -07:00
doctest.rs Fix clippy lints in librustdoc 2021-10-25 11:30:09 +02:00
doctree.rs Teach tools that macros are now HIR items 2021-08-28 00:24:39 -07:00
error.rs Make all rustdoc functions and structs crate-private 2020-11-15 11:21:12 -05:00
externalfiles.rs heading_level: u32 -> heading_offset: HeadingOffset 2021-10-04 22:28:04 -04:00
fold.rs List all cases explicitly in Doc{Folder,Visitor} 2021-11-01 16:15:46 -07:00
lib.rs rustdoc: Add DocVisitor 2021-10-31 20:18:52 -07:00
lint.rs Warn when rustdoc:: group is omitted from lint names 2021-07-03 15:32:09 -04:00
markdown.rs heading_level: u32 -> heading_offset: HeadingOffset 2021-10-04 22:28:04 -04: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 Fix rare ICE during typeck in rustdoc scrape_examples 2021-10-29 13:21:50 -07:00
theme.rs Change librustdoc write(.. \n) to writeln(..); fix comment in grammar 2021-05-03 02:19:57 -05:00
visit.rs List all cases explicitly in Doc{Folder,Visitor} 2021-11-01 16:15:46 -07:00
visit_ast.rs Fix clippy lints in librustdoc 2021-10-25 11:30:09 +02:00
visit_lib.rs rustc: Remove local variable IDs from Exports 2021-09-10 23:41:48 +03:00

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