Skip to content

Commit 802a293

Browse files
Improve code and add documentation
1 parent af66036 commit 802a293

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/librustdoc/html/markdown.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ fn init_id_map() -> FxHashMap<String, usize> {
14491449
}}
14501450
}
14511451

1452+
// IMPORTANT: Do NOT change the formatting or name of this macro
1453+
// without updating the tidy check.
14521454
html_id_map!(
14531455
// This is the list of IDs used in Javascript.
14541456
"help",

src/librustdoc/html/render/print_item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
628628
// Trait documentation
629629
document(w, cx, it, None, HeadingOffset::H2);
630630

631+
// This function is checked in tidy for rustdoc IDs. If you rename/update it, don't forget
632+
// to update the `src/tools/tidy/rustdoc_html_ids.rs` file.
631633
fn write_small_section_header(w: &mut Buffer, id: &str, title: &str, extra_content: &str) {
632634
write!(
633635
w,

src/tools/tidy/src/rustdoc_html_ids.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Checks that the rustdoc ID map is up-to-date. The goal here is to check a few things:
22
//!
3-
//! * All IDs created by rustdoc (through JS or files generation) are declared in the ID map.
3+
//! * All IDs created by rustdoc (through JS or `.html` files generation) are declared in the
4+
//! ID map.
45
//! * There are no unused IDs.
56
67
use std::collections::HashMap;
@@ -31,7 +32,8 @@ fn extract_ids(path: &Path, bad: &mut bool) -> HashMap<String, usize> {
3132
}
3233
}
3334
// We're now in the function body, time to retrieve the IDs!
34-
while let Some(Ok(line)) = iter.next() {
35+
while let Some(line) = iter.next() {
36+
let line = line.unwrap();
3537
let line = line.trim_start();
3638
if line.starts_with("// ") {
3739
// It's a comment, ignoring this line...
@@ -44,13 +46,14 @@ fn extract_ids(path: &Path, bad: &mut bool) -> HashMap<String, usize> {
4446
if ids.insert(id.to_owned(), 0).is_some() {
4547
eprintln!(
4648
"=> ID `{}` is defined more than once in the ID map in file `{}`",
47-
id, ID_MAP_PATH
49+
id,
50+
path.display(),
4851
);
4952
*bad = true;
5053
}
5154
}
5255
if ids.is_empty() {
53-
eprintln!("=> No IDs were found in rustdoc in file `{}`...", ID_MAP_PATH);
56+
eprintln!("=> No IDs were found in rustdoc in file `{}`...", path.display());
5457
*bad = true;
5558
}
5659
ids
@@ -102,7 +105,11 @@ fn check_ids(
102105
check_id(path, trimmed.split('"').skip(1).next().unwrap(), ids, line_nb, bad);
103106
is_checking_small_section_header = None;
104107
}
105-
} else if trimmed.starts_with("write_small_section_header(") {
108+
} else if trimmed.contains("write_small_section_header(")
109+
&& !trimmed.contains("fn write_small_section_header(")
110+
{
111+
// First we extract the arguments.
112+
let trimmed = trimmed.split("write_small_section_header(").skip(1).next().unwrap_or("");
106113
// This function is used to create section: the second argument of the function is an
107114
// ID and we need to check it as well, hence this specific check...
108115
if trimmed.contains(',') {
@@ -145,12 +152,12 @@ pub fn check(path: &Path, bad: &mut bool) {
145152
);
146153
if small_section_header_checked == 0 {
147154
eprintln!(
148-
"No call to the `write_small_section_header` function was found. Was it renamed?",
155+
"=> No call to the `write_small_section_header` function was found. Was it renamed?",
149156
);
150157
*bad = true;
151158
}
152159
for (id, nb) in ids {
153-
if IDS_USED_IN_JS.iter().any(|i| i == &id) {
160+
if IDS_USED_IN_JS.contains(&id.as_str()) {
154161
if nb != 0 {
155162
eprintln!("=> ID `{}` is not supposed to be used in Rust code but in the JS!", id);
156163
*bad = true;

0 commit comments

Comments
 (0)