1
1
//! Checks that the rustdoc ID map is up-to-date. The goal here is to check a few things:
2
2
//!
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.
4
5
//! * There are no unused IDs.
5
6
6
7
use std:: collections:: HashMap ;
@@ -31,7 +32,8 @@ fn extract_ids(path: &Path, bad: &mut bool) -> HashMap<String, usize> {
31
32
}
32
33
}
33
34
// 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 ( ) ;
35
37
let line = line. trim_start ( ) ;
36
38
if line. starts_with ( "// " ) {
37
39
// It's a comment, ignoring this line...
@@ -44,13 +46,14 @@ fn extract_ids(path: &Path, bad: &mut bool) -> HashMap<String, usize> {
44
46
if ids. insert ( id. to_owned ( ) , 0 ) . is_some ( ) {
45
47
eprintln ! (
46
48
"=> ID `{}` is defined more than once in the ID map in file `{}`" ,
47
- id, ID_MAP_PATH
49
+ id,
50
+ path. display( ) ,
48
51
) ;
49
52
* bad = true ;
50
53
}
51
54
}
52
55
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 ( ) ) ;
54
57
* bad = true ;
55
58
}
56
59
ids
@@ -102,7 +105,11 @@ fn check_ids(
102
105
check_id ( path, trimmed. split ( '"' ) . skip ( 1 ) . next ( ) . unwrap ( ) , ids, line_nb, bad) ;
103
106
is_checking_small_section_header = None ;
104
107
}
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 ( "" ) ;
106
113
// This function is used to create section: the second argument of the function is an
107
114
// ID and we need to check it as well, hence this specific check...
108
115
if trimmed. contains ( ',' ) {
@@ -145,12 +152,12 @@ pub fn check(path: &Path, bad: &mut bool) {
145
152
) ;
146
153
if small_section_header_checked == 0 {
147
154
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?" ,
149
156
) ;
150
157
* bad = true ;
151
158
}
152
159
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 ( ) ) {
154
161
if nb != 0 {
155
162
eprintln ! ( "=> ID `{}` is not supposed to be used in Rust code but in the JS!" , id) ;
156
163
* bad = true ;
0 commit comments