24
24
html_favicon_url = "http://www.rust-lang.org/favicon.ico" ,
25
25
html_root_url = "http://doc.rust-lang.org/glob/" ) ]
26
26
#![ allow( unstable) ]
27
+ #![ cfg_attr( test, deny( warnings) ) ]
27
28
28
29
use std:: ascii:: AsciiExt ;
29
30
use std:: cell:: Cell ;
@@ -166,8 +167,8 @@ pub fn glob_with(pattern: &str, options: &MatchOptions) -> Result<Paths, Pattern
166
167
let scope = root. map ( to_scope) . unwrap_or_else ( || Path :: new ( "." ) ) ;
167
168
168
169
let mut dir_patterns = Vec :: new ( ) ;
169
- let mut components = pattern. slice_from ( cmp:: min ( root_len, pattern. len ( ) ) )
170
- . split_terminator ( is_sep) ;
170
+ let mut components = pattern[ cmp:: min ( root_len, pattern. len ( ) ) .. ]
171
+ . split_terminator ( is_sep) ;
171
172
172
173
for component in components {
173
174
let compiled = try!( Pattern :: new ( component) ) ;
@@ -191,6 +192,7 @@ pub fn glob_with(pattern: &str, options: &MatchOptions) -> Result<Paths, Pattern
191
192
/// This is typically returned when a particular path cannot be read
192
193
/// to determine if its contents match the glob pattern. This is possible
193
194
/// if the program lacks the permissions, for example.
195
+ #[ derive( Debug ) ]
194
196
pub struct GlobError {
195
197
path : Path ,
196
198
error : IoError ,
@@ -208,15 +210,10 @@ impl GlobError {
208
210
}
209
211
}
210
212
211
- impl fmt:: String for GlobError {
213
+ impl fmt:: Display for GlobError {
212
214
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
213
- write ! ( f, "attempting to read `{:?}` resulted in an error: {}" , self . path, self . error)
214
- }
215
- }
216
-
217
- impl fmt:: Show for GlobError {
218
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
219
- fmt:: String :: fmt ( self , f)
215
+ write ! ( f, "attempting to read `{}` resulted in an error: {}" ,
216
+ self . path. display( ) , self . error)
220
217
}
221
218
}
222
219
@@ -321,6 +318,8 @@ impl Iterator for Paths {
321
318
}
322
319
323
320
/// A pattern parsing error.
321
+ #[ derive( Debug ) ]
322
+ #[ allow( missing_copy_implementations) ]
324
323
pub struct PatternError {
325
324
/// The approximate character index of where the error occurred.
326
325
pub pos : usize ,
@@ -329,19 +328,13 @@ pub struct PatternError {
329
328
pub msg : & ' static str ,
330
329
}
331
330
332
- impl fmt:: String for PatternError {
331
+ impl fmt:: Display for PatternError {
333
332
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
334
333
write ! ( f, "Pattern syntax error near position {}: {}" ,
335
334
self . pos, self . msg)
336
335
}
337
336
}
338
337
339
- impl fmt:: Show for PatternError {
340
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
341
- fmt:: String :: fmt ( self , f)
342
- }
343
- }
344
-
345
338
/// A compiled Unix shell style pattern.
346
339
///
347
340
/// `?` matches any single character
@@ -366,28 +359,21 @@ impl fmt::Show for PatternError {
366
359
/// set, so `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.
367
360
/// The `-` character can be specified inside a character sequence pattern by
368
361
/// placing it at the start or the end, e.g. `[abc-]`.
369
- #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Default ) ]
362
+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Default , Debug ) ]
370
363
pub struct Pattern {
371
364
original : String ,
372
365
tokens : Vec < PatternToken > ,
373
366
is_recursive : bool ,
374
367
}
375
368
376
369
/// Show the original glob pattern.
377
- impl fmt:: String for Pattern {
370
+ impl fmt:: Display for Pattern {
378
371
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
379
372
self . original . fmt ( f)
380
373
}
381
374
}
382
375
383
- /// Show the original glob pattern.
384
- impl fmt:: Show for Pattern {
385
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
386
- fmt:: String :: fmt ( self , f)
387
- }
388
- }
389
-
390
- #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
376
+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
391
377
enum PatternToken {
392
378
Char ( char ) ,
393
379
AnyChar ,
@@ -397,7 +383,7 @@ enum PatternToken {
397
383
AnyExcept ( Vec < CharSpecifier > )
398
384
}
399
385
400
- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
386
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
401
387
enum CharSpecifier {
402
388
SingleChar ( char ) ,
403
389
CharRange ( char , char )
@@ -497,21 +483,21 @@ impl Pattern {
497
483
'[' => {
498
484
499
485
if i <= chars. len ( ) - 4 && chars[ i + 1 ] == '!' {
500
- match chars. slice_from ( i + 3 ) . position_elem ( & ']' ) {
486
+ match chars[ i + 3 .. ] . position_elem ( & ']' ) {
501
487
None => ( ) ,
502
488
Some ( j) => {
503
- let chars = chars. slice ( i + 2 , i + 3 + j) ;
489
+ let chars = & chars[ i + 2 .. i + 3 + j] ;
504
490
let cs = parse_char_specifiers ( chars) ;
505
491
tokens. push ( AnyExcept ( cs) ) ;
506
492
i += j + 4 ;
507
493
continue ;
508
494
}
509
495
}
510
496
} else if i <= chars. len ( ) - 3 && chars[ i + 1 ] != '!' {
511
- match chars. slice_from ( i + 2 ) . position_elem ( & ']' ) {
497
+ match chars[ i + 2 .. ] . position_elem ( & ']' ) {
512
498
None => ( ) ,
513
499
Some ( j) => {
514
- let cs = parse_char_specifiers ( chars. slice ( i + 1 , i + 2 + j) ) ;
500
+ let cs = parse_char_specifiers ( & chars[ i + 1 .. i + 2 + j] ) ;
515
501
tokens. push ( AnyWithin ( cs) ) ;
516
502
i += j + 3 ;
517
503
continue ;
@@ -619,7 +605,7 @@ impl Pattern {
619
605
&& is_sep ( prev_char. get ( ) . unwrap_or ( '/' ) ) )
620
606
} ;
621
607
622
- for ( ti, token) in self . tokens . slice_from ( i ) . iter ( ) . enumerate ( ) {
608
+ for ( ti, token) in self . tokens [ i.. ] . iter ( ) . enumerate ( ) {
623
609
match * token {
624
610
AnySequence | AnyRecursiveSequence => {
625
611
loop {
@@ -918,7 +904,7 @@ mod test {
918
904
let err = next. unwrap ( ) ;
919
905
assert ! ( err. is_err( ) ) ;
920
906
921
- let err = err. unwrap_err ( ) ;
907
+ let err = err. err ( ) . unwrap ( ) ;
922
908
assert ! ( * err. path( ) == Path :: new( "/root" ) ) ;
923
909
assert ! ( err. error( ) . kind == :: std:: io:: IoErrorKind :: PermissionDenied ) ;
924
910
}
0 commit comments