mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 17:18:32 +03:00
librustdoc: make item_path formatting lazy
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::{self, Write as _};
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::mpsc::{Receiver, channel};
|
||||
use std::{fmt, io};
|
||||
|
||||
use rinja::Template;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
@@ -270,7 +271,7 @@ fn render_item(&mut self, it: &clean::Item, is_module: bool) -> String {
|
||||
path.push_str(name.as_str());
|
||||
path.push('/');
|
||||
}
|
||||
path.push_str(&item_path(ty, names.last().unwrap().as_str()));
|
||||
let _ = write!(path, "{}", item_path(ty, names.last().unwrap().as_str()));
|
||||
match self.shared.redirections {
|
||||
Some(ref redirections) => {
|
||||
let mut current_path = String::new();
|
||||
@@ -278,8 +279,12 @@ fn render_item(&mut self, it: &clean::Item, is_module: bool) -> String {
|
||||
current_path.push_str(name.as_str());
|
||||
current_path.push('/');
|
||||
}
|
||||
current_path.push_str(&item_path(ty, names.last().unwrap().as_str()));
|
||||
redirections.borrow_mut().insert(current_path, path);
|
||||
let _ = write!(
|
||||
current_path,
|
||||
"{}",
|
||||
item_path(ty, names.last().unwrap().as_str())
|
||||
);
|
||||
redirections.borrow_mut().insert(current_path, path.to_string());
|
||||
}
|
||||
None => {
|
||||
return layout::redirect(&format!(
|
||||
@@ -854,9 +859,9 @@ fn item(&mut self, item: clean::Item) -> Result<(), Error> {
|
||||
if !buf.is_empty() {
|
||||
let name = item.name.as_ref().unwrap();
|
||||
let item_type = item.type_();
|
||||
let file_name = &item_path(item_type, name.as_str());
|
||||
let file_name = item_path(item_type, name.as_str()).to_string();
|
||||
self.shared.ensure_dir(&self.dst)?;
|
||||
let joint_dst = self.dst.join(file_name);
|
||||
let joint_dst = self.dst.join(&file_name);
|
||||
self.shared.fs.write(joint_dst, buf)?;
|
||||
|
||||
if !self.info.render_redirect_pages {
|
||||
@@ -873,7 +878,7 @@ fn item(&mut self, item: clean::Item) -> Result<(), Error> {
|
||||
format!("{crate_name}/{file_name}"),
|
||||
);
|
||||
} else {
|
||||
let v = layout::redirect(file_name);
|
||||
let v = layout::redirect(&file_name);
|
||||
let redir_dst = self.dst.join(redir_name);
|
||||
self.shared.fs.write(redir_dst, v)?;
|
||||
}
|
||||
|
||||
@@ -2115,11 +2115,11 @@ pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String {
|
||||
s
|
||||
}
|
||||
|
||||
pub(super) fn item_path(ty: ItemType, name: &str) -> String {
|
||||
match ty {
|
||||
ItemType::Module => format!("{}index.html", ensure_trailing_slash(name)),
|
||||
_ => format!("{ty}.{name}.html"),
|
||||
}
|
||||
pub(super) fn item_path(ty: ItemType, name: &str) -> impl Display + '_ {
|
||||
fmt::from_fn(move |f| match ty {
|
||||
ItemType::Module => write!(f, "{}index.html", ensure_trailing_slash(name)),
|
||||
_ => write!(f, "{ty}.{name}.html"),
|
||||
})
|
||||
}
|
||||
|
||||
fn bounds<'a, 'tcx>(
|
||||
|
||||
Reference in New Issue
Block a user