Skip to content

Commit 5f9e716

Browse files
Add documentation for new FormatRenderer trait items
1 parent 5fa1653 commit 5f9e716

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/librustdoc/formats/renderer.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
1717
///
1818
/// This is true for html, and false for json. See #80664
1919
const RUN_ON_MODULE: bool;
20+
/// This associated type is the type where the current module information is stored.
21+
///
22+
/// For each module, we go through their items by calling for each item:
23+
///
24+
/// 1. make_child_renderer
25+
/// 2. item
26+
/// 3. set_back_info
27+
///
28+
/// However,the `item` method might update information in `self` (for example if the child is
29+
/// a module). To prevent it to impact the other children of the current module, we need to
30+
/// reset the information between each call to `item` by using `set_back_info`.
2031
type InfoType;
2132

2233
/// 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 {
2839
tcx: TyCtxt<'tcx>,
2940
) -> Result<(Self, clean::Crate), Error>;
3041

31-
/// Make a new renderer to render a child of the item currently being rendered.
42+
/// This method is called right before call [`Self::item`]. This method returns a type
43+
/// containing information that needs to be reset after the [`Self::item`] method has been
44+
/// called with the [`Self::set_back_info`] method.
45+
///
46+
/// In short it goes like this:
47+
///
48+
/// ```ignore (not valid code)
49+
/// let reset_data = type.make_child_renderer();
50+
/// type.item(item)?;
51+
/// type.set_back_info(reset_data);
52+
/// ```
3253
fn make_child_renderer(&mut self) -> Self::InfoType;
33-
fn set_back_info(&mut self, _info: Self::InfoType);
54+
/// Used to reset current module's information.
55+
fn set_back_info(&mut self, info: Self::InfoType);
3456

3557
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
3658
fn item(&mut self, item: clean::Item) -> Result<(), Error>;

src/librustdoc/html/render/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ pub(crate) struct Context<'tcx> {
6666
pub(crate) info: ContextInfo,
6767
}
6868

69+
/// This struct contains the information that needs to be reset between each
70+
/// [`FormatRenderer::render_item`] call.
71+
///
72+
/// When we enter a new module, we set these values for the whole module but they might be updated
73+
/// in each child item (especially if it's a module). So to prevent these changes to impact other
74+
/// items rendering in the same module, we need to reset them to the module's set values.
6975
#[derive(Clone, Copy)]
7076
pub(crate) struct ContextInfo {
7177
/// A flag, which when `true`, will render pages which redirect to the

0 commit comments

Comments
 (0)