about summary refs log tree commit diff
path: root/src/librustdoc/formats
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-11-27 14:30:01 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-12-01 21:54:55 +0100
commit5f9e71627c860058e30c0bc1f8cd4c42de5083ce (patch)
treec751e81987f04ed1eb7ceeaef5560b3389119978 /src/librustdoc/formats
parent5fa1653c5cd175430d14c3c3d8416635772811da (diff)
downloadrust-5f9e71627c860058e30c0bc1f8cd4c42de5083ce.tar.gz
rust-5f9e71627c860058e30c0bc1f8cd4c42de5083ce.zip
Add documentation for new `FormatRenderer` trait items
Diffstat (limited to 'src/librustdoc/formats')
-rw-r--r--src/librustdoc/formats/renderer.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs
index f7ba5bff51b..8ae3cad74e3 100644
--- a/src/librustdoc/formats/renderer.rs
+++ b/src/librustdoc/formats/renderer.rs
@@ -17,6 +17,17 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
     ///
     /// This is true for html, and false for json. See #80664
     const RUN_ON_MODULE: bool;
+    /// This associated type is the type where the current module information is stored.
+    ///
+    /// For each module, we go through their items by calling for each item:
+    ///
+    /// 1. make_child_renderer
+    /// 2. item
+    /// 3. set_back_info
+    ///
+    /// However,the `item` method might update information in `self` (for example if the child is
+    /// a module). To prevent it to impact the other children of the current module, we need to
+    /// reset the information between each call to `item` by using `set_back_info`.
     type InfoType;
 
     /// Sets up any state required for the renderer. When this is called the cache has already been
@@ -28,9 +39,20 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
         tcx: TyCtxt<'tcx>,
     ) -> Result<(Self, clean::Crate), Error>;
 
-    /// Make a new renderer to render a child of the item currently being rendered.
+    /// This method is called right before call [`Self::item`]. This method returns a type
+    /// containing information that needs to be reset after the [`Self::item`] method has been
+    /// called with the [`Self::set_back_info`] method.
+    ///
+    /// In short it goes like this:
+    ///
+    /// ```ignore (not valid code)
+    /// let reset_data = type.make_child_renderer();
+    /// type.item(item)?;
+    /// type.set_back_info(reset_data);
+    /// ```
     fn make_child_renderer(&mut self) -> Self::InfoType;
-    fn set_back_info(&mut self, _info: Self::InfoType);
+    /// Used to reset current module's information.
+    fn set_back_info(&mut self, info: Self::InfoType);
 
     /// Renders a single non-module item. This means no recursive sub-item rendering is required.
     fn item(&mut self, item: clean::Item) -> Result<(), Error>;