diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 4bb50f7579197..550f672ed4cf6 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1129,9 +1129,36 @@ pub struct IdMap {
map: FxHashMap,
}
+fn init_id_map() -> FxHashMap {
+ let mut map = FxHashMap::default();
+ // This is the list of IDs used by rustdoc templates.
+ map.insert("mainThemeStyle".to_owned(), 1);
+ map.insert("themeStyle".to_owned(), 1);
+ map.insert("theme-picker".to_owned(), 1);
+ map.insert("theme-choices".to_owned(), 1);
+ map.insert("settings-menu".to_owned(), 1);
+ map.insert("main".to_owned(), 1);
+ map.insert("search".to_owned(), 1);
+ map.insert("crate-search".to_owned(), 1);
+ map.insert("render-detail".to_owned(), 1);
+ map.insert("toggle-all-docs".to_owned(), 1);
+ map.insert("all-types".to_owned(), 1);
+ // This is the list of IDs used by rustdoc sections.
+ map.insert("fields".to_owned(), 1);
+ map.insert("variants".to_owned(), 1);
+ map.insert("implementors-list".to_owned(), 1);
+ map.insert("synthetic-implementors-list".to_owned(), 1);
+ map.insert("implementations".to_owned(), 1);
+ map.insert("trait-implementations".to_owned(), 1);
+ map.insert("synthetic-implementations".to_owned(), 1);
+ map.insert("blanket-implementations".to_owned(), 1);
+ map.insert("deref-methods".to_owned(), 1);
+ map
+}
+
impl IdMap {
pub fn new() -> Self {
- IdMap::default()
+ IdMap { map: init_id_map() }
}
pub fn populate>(&mut self, ids: I) {
@@ -1141,7 +1168,7 @@ impl IdMap {
}
pub fn reset(&mut self) {
- self.map = FxHashMap::default();
+ self.map = init_id_map();
}
pub fn derive(&mut self, candidate: String) -> String {
diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs
index c871587a0a919..bf0451a1d9d65 100644
--- a/src/librustdoc/html/markdown/tests.rs
+++ b/src/librustdoc/html/markdown/tests.rs
@@ -29,8 +29,8 @@ fn test_unique_id() {
"examples-2",
"method.into_iter-1",
"foo-1",
- "main",
- "search",
+ "main-1",
+ "search-1",
"methods",
"examples-3",
"method.into_iter-2",
@@ -191,8 +191,8 @@ fn test_header_ids_multiple_blocks() {
t(
&mut map,
"# Main",
- "",
+ "",
);
t(
&mut map,
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 387ef03f06773..666e59b9a045e 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -3413,8 +3413,8 @@ fn render_assoc_items(
write!(
w,
"\
-