@@ -75,30 +75,20 @@ struct FileEntry {
7575type Cache = HashMap < PathBuf , FileEntry > ;
7676
7777impl 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 ) {
8379 if self . ids . is_empty ( ) {
8480 with_attrs_in_source ( contents, " id" , |fragment, i| {
8581 let frag = fragment. trim_left_matches ( "#" ) . to_owned ( ) ;
8682 if !self . ids . insert ( frag) {
8783 * errors = true ;
88- println ! ( "{}:{}: id is not unique: `{}`" ,
89- file. display( ) , i, fragment) ;
84+ println ! ( "{}:{}: id is not unique: `{}`" , file. display( ) , i, fragment) ;
9085 }
9186 } ) ;
9287 }
9388 }
9489}
9590
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 ) {
10292 for entry in t ! ( dir. read_dir( ) ) . map ( |e| t ! ( e) ) {
10393 let path = entry. path ( ) ;
10494 let kind = t ! ( entry. file_type( ) ) ;
@@ -122,8 +112,8 @@ fn check(cache: &mut Cache,
122112 root : & Path ,
123113 file : & Path ,
124114 base : & Url ,
125- errors : & mut bool ) -> Option < PathBuf >
126- {
115+ errors : & mut bool )
116+ -> Option < PathBuf > {
127117 // ignore js files as they are not prone to errors as the rest of the
128118 // documentation is and they otherwise bring up false positives.
129119 if file. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "js" ) {
@@ -173,8 +163,9 @@ fn check(cache: &mut Cache,
173163 Err ( _) => return None ,
174164 } ;
175165 {
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) ;
178169 }
179170
180171 // Search for anything that's the regex 'href[ ]*=[ ]*".*?"'
@@ -195,8 +186,10 @@ fn check(cache: &mut Cache,
195186 // the docs offline so it's best to avoid them.
196187 * errors = true ;
197188 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( ) ) ;
200193 return ;
201194 }
202195 let res = load_file ( cache, root, path. clone ( ) , FromRedirect ( false ) ) ;
@@ -205,7 +198,9 @@ fn check(cache: &mut Cache,
205198 Err ( LoadError :: IOError ( err) ) => panic ! ( format!( "{}" , err) ) ,
206199 Err ( LoadError :: BrokenRedirect ( target, _) ) => {
207200 print ! ( "{}:{}: broken redirect to {}" ,
208- pretty_file. display( ) , i + 1 , target. display( ) ) ;
201+ pretty_file. display( ) ,
202+ i + 1 ,
203+ target. display( ) ) ;
209204 return ;
210205 }
211206 Err ( LoadError :: IsRedirect ) => unreachable ! ( ) ,
@@ -225,9 +220,9 @@ fn check(cache: &mut Cache,
225220 if !entry. ids . contains ( fragment) {
226221 * errors = true ;
227222 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( ) ) ;
231226 } ;
232227 }
233228 } else {
@@ -243,15 +238,16 @@ fn check(cache: &mut Cache,
243238fn load_file ( cache : & mut Cache ,
244239 root : & Path ,
245240 file : PathBuf ,
246- redirect : Redirect ) -> Result < ( PathBuf , String ) , LoadError > {
241+ redirect : Redirect )
242+ -> Result < ( PathBuf , String ) , LoadError > {
247243 let mut contents = String :: new ( ) ;
248244 let pretty_file = PathBuf :: from ( file. strip_prefix ( root) . unwrap_or ( & file) ) ;
249245
250246 let maybe_redirect = match cache. entry ( pretty_file. clone ( ) ) {
251247 Entry :: Occupied ( entry) => {
252248 contents = entry. get ( ) . source . clone ( ) ;
253249 None
254- } ,
250+ }
255251 Entry :: Vacant ( entry) => {
256252 let mut fp = try!( File :: open ( file. clone ( ) ) . map_err ( |err| {
257253 if let FromRedirect ( true ) = redirect {
@@ -275,7 +271,7 @@ fn load_file(cache: &mut Cache,
275271 } ) ;
276272 }
277273 maybe
278- } ,
274+ }
279275 } ;
280276 let base = Url :: from_file_path ( & file) . unwrap ( ) ;
281277 let mut parser = UrlParser :: new ( ) ;
@@ -286,7 +282,7 @@ fn load_file(cache: &mut Cache,
286282 let path = PathBuf :: from ( redirect_file) ;
287283 load_file ( cache, root, path, FromRedirect ( true ) )
288284 }
289- None => Ok ( ( pretty_file, contents) )
285+ None => Ok ( ( pretty_file, contents) ) ,
290286 }
291287}
292288
@@ -307,25 +303,22 @@ fn maybe_redirect(source: &str) -> Option<String> {
307303}
308304
309305fn 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 ) ) )
313309}
314310
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 ) {
319312 for ( i, mut line) in contents. lines ( ) . enumerate ( ) {
320313 while let Some ( j) = line. find ( attr) {
321- let rest = & line[ j + attr. len ( ) ..] ;
314+ let rest = & line[ j + attr. len ( ) ..] ;
322315 line = rest;
323316 let pos_equals = match rest. find ( "=" ) {
324317 Some ( i) => i,
325318 None => continue ,
326319 } ;
327320 if rest[ ..pos_equals] . trim_left_matches ( " " ) != "" {
328- continue
321+ continue ;
329322 }
330323
331324 let rest = & rest[ pos_equals + 1 ..] ;
@@ -337,7 +330,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize)>(contents: &str,
337330 let quote_delim = rest. as_bytes ( ) [ pos_quote] as char ;
338331
339332 if rest[ ..pos_quote] . trim_left_matches ( " " ) != "" {
340- continue
333+ continue ;
341334 }
342335 let rest = & rest[ pos_quote + 1 ..] ;
343336 let url = match rest. find ( quote_delim) {
0 commit comments