1
Fork 0

Rollup merge of #133764 - aDotInTheVoid:rename, r=GuillaumeGomez

rustdoc: Rename `set_back_info` to `restore_module_data`.

Follow-up to #133345, r? `@GuillaumeGomez`

Most of the references to `info` got removed as it was clear that `module_data` makes more sense here. Makes it clearer that `save_module_data` and `restore_module_data` are a pair.
This commit is contained in:
Matthias Krüger 2024-12-04 05:42:07 +01:00 committed by GitHub
commit afffc1a865
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 18 deletions

View file

@ -17,17 +17,18 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
/// ///
/// This is true for html, and false for json. See #80664 /// This is true for html, and false for json. See #80664
const RUN_ON_MODULE: bool; const RUN_ON_MODULE: bool;
/// This associated type is the type where the current module information is stored. /// 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: /// For each module, we go through their items by calling for each item:
/// ///
/// 1. save_module_data /// 1. `save_module_data`
/// 2. item /// 2. `item`
/// 3. set_back_info /// 3. `restore_module_data`
/// ///
/// However,the `item` method might update information in `self` (for example if the child is /// This is because the `item` method might update information in `self` (for example if the child
/// a module). To prevent it to impact the other children of the current module, we need to /// is a module). To prevent it from impacting the other children of the current module, we need to
/// reset the information between each call to `item` by using `set_back_info`. /// reset the information between each call to `item` by using `restore_module_data`.
type ModuleData; type ModuleData;
/// Sets up any state required for the renderer. When this is called the cache has already been /// Sets up any state required for the renderer. When this is called the cache has already been
@ -41,18 +42,18 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
/// This method is called right before call [`Self::item`]. This method returns a type /// 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 /// containing information that needs to be reset after the [`Self::item`] method has been
/// called with the [`Self::set_back_info`] method. /// called with the [`Self::restore_module_data`] method.
/// ///
/// In short it goes like this: /// In short it goes like this:
/// ///
/// ```ignore (not valid code) /// ```ignore (not valid code)
/// let reset_data = type.save_module_data(); /// let reset_data = renderer.save_module_data();
/// type.item(item)?; /// renderer.item(item)?;
/// type.set_back_info(reset_data); /// renderer.restore_module_data(reset_data);
/// ``` /// ```
fn save_module_data(&mut self) -> Self::ModuleData; fn save_module_data(&mut self) -> Self::ModuleData;
/// Used to reset current module's information. /// Used to reset current module's information.
fn set_back_info(&mut self, info: Self::ModuleData); fn restore_module_data(&mut self, info: Self::ModuleData);
/// Renders a single non-module item. This means no recursive sub-item rendering is required. /// Renders a single non-module item. This means no recursive sub-item rendering is required.
fn item(&mut self, item: clean::Item) -> Result<(), Error>; fn item(&mut self, item: clean::Item) -> Result<(), Error>;
@ -91,7 +92,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
for it in module.items { for it in module.items {
let info = cx.save_module_data(); let info = cx.save_module_data();
run_format_inner(cx, it, prof)?; run_format_inner(cx, it, prof)?;
cx.set_back_info(info); cx.restore_module_data(info);
} }
cx.mod_item_out()?; cx.mod_item_out()?;

View file

@ -601,7 +601,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
self.info self.info
} }
fn set_back_info(&mut self, info: Self::ModuleData) { fn restore_module_data(&mut self, info: Self::ModuleData) {
self.info = info; self.info = info;
} }

View file

@ -163,11 +163,10 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
} }
fn save_module_data(&mut self) -> Self::ModuleData { fn save_module_data(&mut self) -> Self::ModuleData {
unreachable!("RUN_ON_MODULE = false should never call save_module_data") unreachable!("RUN_ON_MODULE = false, should never call save_module_data")
} }
fn restore_module_data(&mut self, _info: Self::ModuleData) {
fn set_back_info(&mut self, _info: Self::ModuleData) { unreachable!("RUN_ON_MODULE = false, should never call set_back_info")
unreachable!("RUN_ON_MODULE = false should never call set_back_info")
} }
/// Inserts an item into the index. This should be used rather than directly calling insert on /// Inserts an item into the index. This should be used rather than directly calling insert on
@ -248,7 +247,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
} }
fn mod_item_in(&mut self, _item: &clean::Item) -> Result<(), Error> { fn mod_item_in(&mut self, _item: &clean::Item) -> Result<(), Error> {
unreachable!("RUN_ON_MODULE = false should never call mod_item_in") unreachable!("RUN_ON_MODULE = false, should never call mod_item_in")
} }
fn after_krate(&mut self) -> Result<(), Error> { fn after_krate(&mut self) -> Result<(), Error> {