Skip to content

Commit 69a879f

Browse files
committed
Store UNVERSIONED_FILES in a data structure
This allows querying it programatically.
1 parent 8ccc89b commit 69a879f

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

src/librustdoc/clean/types.rs

-18
Original file line numberDiff line numberDiff line change
@@ -1612,24 +1612,6 @@ impl PrimitiveType {
16121612
CELL.get_or_init(move || {
16131613
use self::PrimitiveType::*;
16141614

1615-
/// A macro to create a FxHashMap.
1616-
///
1617-
/// Example:
1618-
///
1619-
/// ```
1620-
/// let letters = map!{"a" => "b", "c" => "d"};
1621-
/// ```
1622-
///
1623-
/// Trailing commas are allowed.
1624-
/// Commas between elements are required (even if the expression is a block).
1625-
macro_rules! map {
1626-
($( $key: expr => $val: expr ),* $(,)*) => {{
1627-
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
1628-
$( map.insert($key, $val); )*
1629-
map
1630-
}}
1631-
}
1632-
16331615
let single = |a: Option<DefId>| a.into_iter().collect();
16341616
let both = |a: Option<DefId>, b: Option<DefId>| -> ArrayVec<_> {
16351617
a.into_iter().chain(b).collect()

src/librustdoc/html/render/write_shared.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs::{self, File};
44
use std::io::prelude::*;
55
use std::io::{self, BufReader};
66
use std::path::{Component, Path, PathBuf};
7+
use std::lazy::SyncLazy as Lazy;
78

89
use itertools::Itertools;
910
use rustc_data_structures::flock;
@@ -212,21 +213,26 @@ themePicker.onblur = handleThemeButtonsBlur;
212213
static_files::NORMALIZE_CSS,
213214
options.enable_minification,
214215
)?;
215-
write(cx.dst.join("FiraSans-Regular.woff2"), static_files::fira_sans::REGULAR2)?;
216-
write(cx.dst.join("FiraSans-Medium.woff2"), static_files::fira_sans::MEDIUM2)?;
217-
write(cx.dst.join("FiraSans-Regular.woff"), static_files::fira_sans::REGULAR)?;
218-
write(cx.dst.join("FiraSans-Medium.woff"), static_files::fira_sans::MEDIUM)?;
219-
write(cx.dst.join("FiraSans-LICENSE.txt"), static_files::fira_sans::LICENSE)?;
220-
write(cx.dst.join("SourceSerifPro-Regular.ttf.woff"), static_files::source_serif_pro::REGULAR)?;
221-
write(cx.dst.join("SourceSerifPro-Bold.ttf.woff"), static_files::source_serif_pro::BOLD)?;
222-
write(cx.dst.join("SourceSerifPro-It.ttf.woff"), static_files::source_serif_pro::ITALIC)?;
223-
write(cx.dst.join("SourceSerifPro-LICENSE.md"), static_files::source_serif_pro::LICENSE)?;
224-
write(cx.dst.join("SourceCodePro-Regular.woff"), static_files::source_code_pro::REGULAR)?;
225-
write(cx.dst.join("SourceCodePro-Semibold.woff"), static_files::source_code_pro::SEMIBOLD)?;
226-
write(cx.dst.join("SourceCodePro-LICENSE.txt"), static_files::source_code_pro::LICENSE)?;
227-
write(cx.dst.join("LICENSE-MIT.txt"), static_files::LICENSE_MIT)?;
228-
write(cx.dst.join("LICENSE-APACHE.txt"), static_files::LICENSE_APACHE)?;
229-
write(cx.dst.join("COPYRIGHT.txt"), static_files::COPYRIGHT)?;
216+
static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| map! {
217+
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
218+
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
219+
"FiraSans-Regular.woff" => static_files::fira_sans::REGULAR,
220+
"FiraSans-Medium.woff" => static_files::fira_sans::MEDIUM,
221+
"FiraSans-LICENSE.txt" => static_files::fira_sans::LICENSE,
222+
"SourceSerifPro-Regular.ttf.woff" => static_files::source_serif_pro::REGULAR,
223+
"SourceSerifPro-Bold.ttf.woff" => static_files::source_serif_pro::BOLD,
224+
"SourceSerifPro-It.ttf.woff" => static_files::source_serif_pro::ITALIC,
225+
"SourceSerifPro-LICENSE.md" => static_files::source_serif_pro::LICENSE,
226+
"SourceCodePro-Regular.woff" => static_files::source_code_pro::REGULAR,
227+
"SourceCodePro-Semibold.woff" => static_files::source_code_pro::SEMIBOLD,
228+
"SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
229+
"LICENSE-MIT.txt" => static_files::LICENSE_MIT,
230+
"LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
231+
"COPYRIGHT.txt" => static_files::COPYRIGHT,
232+
});
233+
for (file, contents) in &*FILES_UNVERSIONED {
234+
write(cx.dst.join(file), contents)?;
235+
}
230236

231237
fn collect(path: &Path, krate: &str, key: &str) -> io::Result<(Vec<String>, Vec<String>)> {
232238
let mut ret = Vec::new();

src/librustdoc/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
7171
use rustc_session::getopts;
7272
use rustc_session::{early_error, early_warn};
7373

74+
/// A macro to create a FxHashMap.
75+
///
76+
/// Example:
77+
///
78+
/// ```
79+
/// let letters = map!{"a" => "b", "c" => "d"};
80+
/// ```
81+
///
82+
/// Trailing commas are allowed.
83+
/// Commas between elements are required (even if the expression is a block).
84+
macro_rules! map {
85+
($( $key: expr => $val: expr ),* $(,)*) => {{
86+
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
87+
$( map.insert($key, $val); )*
88+
map
89+
}}
90+
}
91+
7492
#[macro_use]
7593
mod externalfiles;
7694

0 commit comments

Comments
 (0)