@@ -70,6 +70,7 @@ extern crate doc_comment;
7070doctest ! ( "../README.md" ) ; 
7171
7272use  std:: cmp; 
73+ use  std:: cmp:: Ordering ; 
7374use  std:: error:: Error ; 
7475use  std:: fmt; 
7576use  std:: fs; 
@@ -620,52 +621,56 @@ impl Pattern {
620621
621622                    let  count = i - old; 
622623
623-                     if  count > 2  { 
624-                         return  Err ( PatternError  { 
625-                             pos :  old + 2 , 
626-                             msg :  ERROR_WILDCARDS , 
627-                         } ) ; 
628-                     }  else  if  count == 2  { 
629-                         // ** can only be an entire path component 
630-                         // i.e. a/**/b is valid, but a**/b or a/**b is not 
631-                         // invalid matches are treated literally 
632-                         let  is_valid = if  i == 2  || path:: is_separator ( chars[ i - count - 1 ] )  { 
633-                             // it ends in a '/' 
634-                             if  i < chars. len ( )  && path:: is_separator ( chars[ i] )  { 
635-                                 i += 1 ; 
636-                                 true 
637-                             // or the pattern ends here 
638-                             // this enables the existing globbing mechanism 
639-                             }  else  if  i == chars. len ( )  { 
640-                                 true 
641-                             // `**` ends in non-separator 
624+                     match  count. cmp ( & 2 )  { 
625+                         Ordering :: Greater  => { 
626+                             return  Err ( PatternError  { 
627+                                 pos :  old + 2 , 
628+                                 msg :  ERROR_WILDCARDS , 
629+                             } ) 
630+                         } 
631+                         Ordering :: Equal  => { 
632+                             // ** can only be an entire path component 
633+                             // i.e. a/**/b is valid, but a**/b or a/**b is not 
634+                             // invalid matches are treated literally 
635+                             let  is_valid = if  i == 2  || path:: is_separator ( chars[ i - count - 1 ] )  { 
636+                                 // it ends in a '/' 
637+                                 if  i < chars. len ( )  && path:: is_separator ( chars[ i] )  { 
638+                                     i += 1 ; 
639+                                     true 
640+                                 // or the pattern ends here 
641+                                 // this enables the existing globbing mechanism 
642+                                 }  else  if  i == chars. len ( )  { 
643+                                     true 
644+                                 // `**` ends in non-separator 
645+                                 }  else  { 
646+                                     return  Err ( PatternError  { 
647+                                         pos :  i, 
648+                                         msg :  ERROR_RECURSIVE_WILDCARDS , 
649+                                     } ) ; 
650+                                 } 
651+                             // `**` begins with non-separator 
642652                            }  else  { 
643653                                return  Err ( PatternError  { 
644-                                     pos :  i , 
654+                                     pos :  old -  1 , 
645655                                    msg :  ERROR_RECURSIVE_WILDCARDS , 
646656                                } ) ; 
647-                             } 
648-                         // `**` begins with non-separator 
649-                         }  else  { 
650-                             return  Err ( PatternError  { 
651-                                 pos :  old - 1 , 
652-                                 msg :  ERROR_RECURSIVE_WILDCARDS , 
653-                             } ) ; 
654-                         } ; 
657+                             } ; 
655658
656-                         if  is_valid { 
657-                             // collapse consecutive AnyRecursiveSequence to a 
658-                             // single one 
659+                              if  is_valid { 
660+                                  // collapse consecutive AnyRecursiveSequence to a 
661+                                  // single one 
659662
660-                             let  tokens_len = tokens. len ( ) ; 
663+                                  let  tokens_len = tokens. len ( ) ; 
661664
662-                             if  !( tokens_len > 1  && tokens[ tokens_len - 1 ]  == AnyRecursiveSequence )  { 
663-                                 is_recursive = true ; 
664-                                 tokens. push ( AnyRecursiveSequence ) ; 
665+                                 if  !( tokens_len > 1 
666+                                     && tokens[ tokens_len - 1 ]  == AnyRecursiveSequence ) 
667+                                 { 
668+                                     is_recursive = true ; 
669+                                     tokens. push ( AnyRecursiveSequence ) ; 
670+                                 } 
665671                            } 
666672                        } 
667-                     }  else  { 
668-                         tokens. push ( AnySequence ) ; 
673+                         Ordering :: Less  => tokens. push ( AnySequence ) , 
669674                    } 
670675                } 
671676                '['  => { 
@@ -1029,7 +1034,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
10291034        true 
10301035    }  else  if  !case_sensitive && a. is_ascii ( )  && b. is_ascii ( )  { 
10311036        // FIXME: work with non-ascii chars properly (issue #9084) 
1032-         a. to_ascii_lowercase ( )  == b . to_ascii_lowercase ( ) 
1037+         a. eq_ignore_ascii_case ( & b ) 
10331038    }  else  { 
10341039        a == b
10351040    } 
@@ -1166,8 +1171,7 @@ mod test {
11661171                . ok ( ) 
11671172                . and_then ( |p| match  p. components ( ) . next ( ) . unwrap ( )  { 
11681173                    Component :: Prefix ( prefix_component)  => { 
1169-                         let  path = Path :: new ( prefix_component. as_os_str ( ) ) ; 
1170-                         path. join ( "*" ) ; 
1174+                         let  path = Path :: new ( prefix_component. as_os_str ( ) ) . join ( "*" ) ; 
11711175                        Some ( path. to_path_buf ( ) ) 
11721176                    } 
11731177                    _ => panic ! ( "no prefix in this path" ) , 
0 commit comments