@@ -75,30 +75,20 @@ struct FileEntry {
75
75
type Cache = HashMap < PathBuf , FileEntry > ;
76
76
77
77
impl FileEntry {
78
- fn parse_ids ( & mut self ,
79
- file : & Path ,
80
- contents : & str ,
81
- errors : & mut bool )
82
- {
78
+ fn parse_ids ( & mut self , file : & Path , contents : & str , errors : & mut bool ) {
83
79
if self . ids . is_empty ( ) {
84
80
with_attrs_in_source ( contents, " id" , |fragment, i| {
85
81
let frag = fragment. trim_left_matches ( "#" ) . to_owned ( ) ;
86
82
if !self . ids . insert ( frag) {
87
83
* errors = true ;
88
- println ! ( "{}:{}: id is not unique: `{}`" ,
89
- file. display( ) , i, fragment) ;
84
+ println ! ( "{}:{}: id is not unique: `{}`" , file. display( ) , i, fragment) ;
90
85
}
91
86
} ) ;
92
87
}
93
88
}
94
89
}
95
90
96
- fn walk ( cache : & mut Cache ,
97
- root : & Path ,
98
- dir : & Path ,
99
- url : & mut Url ,
100
- errors : & mut bool )
101
- {
91
+ fn walk ( cache : & mut Cache , root : & Path , dir : & Path , url : & mut Url , errors : & mut bool ) {
102
92
for entry in t ! ( dir. read_dir( ) ) . map ( |e| t ! ( e) ) {
103
93
let path = entry. path ( ) ;
104
94
let kind = t ! ( entry. file_type( ) ) ;
@@ -122,8 +112,8 @@ fn check(cache: &mut Cache,
122
112
root : & Path ,
123
113
file : & Path ,
124
114
base : & Url ,
125
- errors : & mut bool ) -> Option < PathBuf >
126
- {
115
+ errors : & mut bool )
116
+ -> Option < PathBuf > {
127
117
// ignore js files as they are not prone to errors as the rest of the
128
118
// documentation is and they otherwise bring up false positives.
129
119
if file. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "js" ) {
@@ -173,8 +163,9 @@ fn check(cache: &mut Cache,
173
163
Err ( _) => return None ,
174
164
} ;
175
165
{
176
- cache. get_mut ( & pretty_file) . unwrap ( )
177
- . parse_ids ( & pretty_file, & contents, errors) ;
166
+ cache. get_mut ( & pretty_file)
167
+ . unwrap ( )
168
+ . parse_ids ( & pretty_file, & contents, errors) ;
178
169
}
179
170
180
171
// Search for anything that's the regex 'href[ ]*=[ ]*".*?"'
@@ -195,8 +186,10 @@ fn check(cache: &mut Cache,
195
186
// the docs offline so it's best to avoid them.
196
187
* errors = true ;
197
188
let pretty_path = path. strip_prefix ( root) . unwrap_or ( & path) ;
198
- println ! ( "{}:{}: directory link - {}" , pretty_file. display( ) ,
199
- i + 1 , pretty_path. display( ) ) ;
189
+ println ! ( "{}:{}: directory link - {}" ,
190
+ pretty_file. display( ) ,
191
+ i + 1 ,
192
+ pretty_path. display( ) ) ;
200
193
return ;
201
194
}
202
195
let res = load_file ( cache, root, path. clone ( ) , FromRedirect ( false ) ) ;
@@ -205,7 +198,9 @@ fn check(cache: &mut Cache,
205
198
Err ( LoadError :: IOError ( err) ) => panic ! ( format!( "{}" , err) ) ,
206
199
Err ( LoadError :: BrokenRedirect ( target, _) ) => {
207
200
print ! ( "{}:{}: broken redirect to {}" ,
208
- pretty_file. display( ) , i + 1 , target. display( ) ) ;
201
+ pretty_file. display( ) ,
202
+ i + 1 ,
203
+ target. display( ) ) ;
209
204
return ;
210
205
}
211
206
Err ( LoadError :: IsRedirect ) => unreachable ! ( ) ,
@@ -225,9 +220,9 @@ fn check(cache: &mut Cache,
225
220
if !entry. ids . contains ( fragment) {
226
221
* errors = true ;
227
222
print ! ( "{}:{}: broken link fragment " ,
228
- pretty_file. display( ) , i + 1 ) ;
229
- println ! ( "`#{}` pointing to `{}`" ,
230
- fragment, pretty_path. display( ) ) ;
223
+ pretty_file. display( ) ,
224
+ i + 1 ) ;
225
+ println ! ( "`#{}` pointing to `{}`" , fragment, pretty_path. display( ) ) ;
231
226
} ;
232
227
}
233
228
} else {
@@ -243,15 +238,16 @@ fn check(cache: &mut Cache,
243
238
fn load_file ( cache : & mut Cache ,
244
239
root : & Path ,
245
240
file : PathBuf ,
246
- redirect : Redirect ) -> Result < ( PathBuf , String ) , LoadError > {
241
+ redirect : Redirect )
242
+ -> Result < ( PathBuf , String ) , LoadError > {
247
243
let mut contents = String :: new ( ) ;
248
244
let pretty_file = PathBuf :: from ( file. strip_prefix ( root) . unwrap_or ( & file) ) ;
249
245
250
246
let maybe_redirect = match cache. entry ( pretty_file. clone ( ) ) {
251
247
Entry :: Occupied ( entry) => {
252
248
contents = entry. get ( ) . source . clone ( ) ;
253
249
None
254
- } ,
250
+ }
255
251
Entry :: Vacant ( entry) => {
256
252
let mut fp = try!( File :: open ( file. clone ( ) ) . map_err ( |err| {
257
253
if let FromRedirect ( true ) = redirect {
@@ -275,7 +271,7 @@ fn load_file(cache: &mut Cache,
275
271
} ) ;
276
272
}
277
273
maybe
278
- } ,
274
+ }
279
275
} ;
280
276
let base = Url :: from_file_path ( & file) . unwrap ( ) ;
281
277
let mut parser = UrlParser :: new ( ) ;
@@ -286,7 +282,7 @@ fn load_file(cache: &mut Cache,
286
282
let path = PathBuf :: from ( redirect_file) ;
287
283
load_file ( cache, root, path, FromRedirect ( true ) )
288
284
}
289
- None => Ok ( ( pretty_file, contents) )
285
+ None => Ok ( ( pretty_file, contents) ) ,
290
286
}
291
287
}
292
288
@@ -307,25 +303,22 @@ fn maybe_redirect(source: &str) -> Option<String> {
307
303
}
308
304
309
305
fn url_to_file_path ( parser : & UrlParser , url : & str ) -> Option < ( Url , PathBuf ) > {
310
- parser. parse ( url) . ok ( ) . and_then ( |parsed_url| {
311
- parsed_url . to_file_path ( ) . ok ( ) . map ( |f| ( parsed_url , f ) )
312
- } )
306
+ parser. parse ( url)
307
+ . ok ( )
308
+ . and_then ( |parsed_url| parsed_url . to_file_path ( ) . ok ( ) . map ( |f| ( parsed_url , f ) ) )
313
309
}
314
310
315
- fn with_attrs_in_source < F : FnMut ( & str , usize ) > ( contents : & str ,
316
- attr : & str ,
317
- mut f : F )
318
- {
311
+ fn with_attrs_in_source < F : FnMut ( & str , usize ) > ( contents : & str , attr : & str , mut f : F ) {
319
312
for ( i, mut line) in contents. lines ( ) . enumerate ( ) {
320
313
while let Some ( j) = line. find ( attr) {
321
- let rest = & line[ j + attr. len ( ) ..] ;
314
+ let rest = & line[ j + attr. len ( ) ..] ;
322
315
line = rest;
323
316
let pos_equals = match rest. find ( "=" ) {
324
317
Some ( i) => i,
325
318
None => continue ,
326
319
} ;
327
320
if rest[ ..pos_equals] . trim_left_matches ( " " ) != "" {
328
- continue
321
+ continue ;
329
322
}
330
323
331
324
let rest = & rest[ pos_equals + 1 ..] ;
@@ -337,7 +330,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize)>(contents: &str,
337
330
let quote_delim = rest. as_bytes ( ) [ pos_quote] as char ;
338
331
339
332
if rest[ ..pos_quote] . trim_left_matches ( " " ) != "" {
340
- continue
333
+ continue ;
341
334
}
342
335
let rest = & rest[ pos_quote + 1 ..] ;
343
336
let url = match rest. find ( quote_delim) {
0 commit comments