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
67use 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