@@ -32,12 +32,11 @@ use std::iter::Peekable;
32
32
use std:: ops:: { ControlFlow , Range } ;
33
33
use std:: path:: PathBuf ;
34
34
use std:: str:: { self , CharIndices } ;
35
- use std:: sync:: OnceLock ;
36
35
37
36
use pulldown_cmark:: {
38
37
BrokenLink , CodeBlockKind , CowStr , Event , LinkType , Options , Parser , Tag , TagEnd , html,
39
38
} ;
40
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
39
+ use rustc_data_structures:: fx:: FxHashMap ;
41
40
use rustc_errors:: { Diag , DiagMessage } ;
42
41
use rustc_hir:: def_id:: LocalDefId ;
43
42
use rustc_middle:: ty:: TyCtxt ;
@@ -1882,66 +1881,63 @@ pub(crate) fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<Rust
1882
1881
1883
1882
#[ derive( Clone , Default , Debug ) ]
1884
1883
pub struct IdMap {
1885
- map : FxHashMap < Cow < ' static , str > , usize > ,
1884
+ map : FxHashMap < String , usize > ,
1886
1885
existing_footnotes : usize ,
1887
1886
}
1888
1887
1889
- // The map is pre-initialized and then can be used as is to prevent cloning it for each item
1890
- // (in the sidebar rendering).
1891
- static DEFAULT_ID_MAP : OnceLock < FxHashSet < & ' static str > > = OnceLock :: new ( ) ;
1892
-
1893
- fn init_id_map ( ) -> FxHashSet < & ' static str > {
1894
- let mut map = FxHashSet :: default ( ) ;
1895
- // This is the list of IDs used in JavaScript.
1896
- map. insert ( "help" ) ;
1897
- map. insert ( "settings" ) ;
1898
- map. insert ( "not-displayed" ) ;
1899
- map. insert ( "alternative-display" ) ;
1900
- map. insert ( "search" ) ;
1901
- map. insert ( "crate-search" ) ;
1902
- map. insert ( "crate-search-div" ) ;
1903
- // This is the list of IDs used in HTML generated in Rust (including the ones
1904
- // used in tera template files).
1905
- map. insert ( "themeStyle" ) ;
1906
- map. insert ( "settings-menu" ) ;
1907
- map. insert ( "help-button" ) ;
1908
- map. insert ( "sidebar-button" ) ;
1909
- map. insert ( "main-content" ) ;
1910
- map. insert ( "toggle-all-docs" ) ;
1911
- map. insert ( "all-types" ) ;
1912
- map. insert ( "default-settings" ) ;
1913
- map. insert ( "sidebar-vars" ) ;
1914
- map. insert ( "copy-path" ) ;
1915
- map. insert ( "rustdoc-toc" ) ;
1916
- map. insert ( "rustdoc-modnav" ) ;
1917
- // This is the list of IDs used by rustdoc sections (but still generated by
1918
- // rustdoc).
1919
- map. insert ( "fields" ) ;
1920
- map. insert ( "variants" ) ;
1921
- map. insert ( "implementors-list" ) ;
1922
- map. insert ( "synthetic-implementors-list" ) ;
1923
- map. insert ( "foreign-impls" ) ;
1924
- map. insert ( "implementations" ) ;
1925
- map. insert ( "trait-implementations" ) ;
1926
- map. insert ( "synthetic-implementations" ) ;
1927
- map. insert ( "blanket-implementations" ) ;
1928
- map. insert ( "required-associated-types" ) ;
1929
- map. insert ( "provided-associated-types" ) ;
1930
- map. insert ( "provided-associated-consts" ) ;
1931
- map. insert ( "required-associated-consts" ) ;
1932
- map. insert ( "required-methods" ) ;
1933
- map. insert ( "provided-methods" ) ;
1934
- map. insert ( "dyn-compatibility" ) ;
1935
- map. insert ( "implementors" ) ;
1936
- map. insert ( "synthetic-implementors" ) ;
1937
- map. insert ( "implementations-list" ) ;
1938
- map. insert ( "trait-implementations-list" ) ;
1939
- map. insert ( "synthetic-implementations-list" ) ;
1940
- map. insert ( "blanket-implementations-list" ) ;
1941
- map. insert ( "deref-methods" ) ;
1942
- map. insert ( "layout" ) ;
1943
- map. insert ( "aliased-type" ) ;
1944
- map
1888
+ fn is_default_id ( id : & str ) -> bool {
1889
+ matches ! (
1890
+ id,
1891
+ // This is the list of IDs used in JavaScript.
1892
+ "help"
1893
+ | "settings"
1894
+ | "not-displayed"
1895
+ | "alternative-display"
1896
+ | "search"
1897
+ | "crate-search"
1898
+ | "crate-search-div"
1899
+ // This is the list of IDs used in HTML generated in Rust (including the ones
1900
+ // used in tera template files).
1901
+ | "themeStyle"
1902
+ | "settings-menu"
1903
+ | "help-button"
1904
+ | "sidebar-button"
1905
+ | "main-content"
1906
+ | "toggle-all-docs"
1907
+ | "all-types"
1908
+ | "default-settings"
1909
+ | "sidebar-vars"
1910
+ | "copy-path"
1911
+ | "rustdoc-toc"
1912
+ | "rustdoc-modnav"
1913
+ // This is the list of IDs used by rustdoc sections (but still generated by
1914
+ // rustdoc).
1915
+ | "fields"
1916
+ | "variants"
1917
+ | "implementors-list"
1918
+ | "synthetic-implementors-list"
1919
+ | "foreign-impls"
1920
+ | "implementations"
1921
+ | "trait-implementations"
1922
+ | "synthetic-implementations"
1923
+ | "blanket-implementations"
1924
+ | "required-associated-types"
1925
+ | "provided-associated-types"
1926
+ | "provided-associated-consts"
1927
+ | "required-associated-consts"
1928
+ | "required-methods"
1929
+ | "provided-methods"
1930
+ | "dyn-compatibility"
1931
+ | "implementors"
1932
+ | "synthetic-implementors"
1933
+ | "implementations-list"
1934
+ | "trait-implementations-list"
1935
+ | "synthetic-implementations-list"
1936
+ | "blanket-implementations-list"
1937
+ | "deref-methods"
1938
+ | "layout"
1939
+ | "aliased-type"
1940
+ )
1945
1941
}
1946
1942
1947
1943
impl IdMap {
@@ -1953,7 +1949,7 @@ impl IdMap {
1953
1949
let id = match self . map . get_mut ( candidate. as_ref ( ) ) {
1954
1950
None => {
1955
1951
let candidate = candidate. to_string ( ) ;
1956
- if DEFAULT_ID_MAP . get_or_init ( init_id_map ) . contains ( candidate. as_str ( ) ) {
1952
+ if is_default_id ( & candidate) {
1957
1953
let id = format ! ( "{}-{}" , candidate, 1 ) ;
1958
1954
self . map . insert ( candidate. into ( ) , 2 ) ;
1959
1955
id
0 commit comments