@@ -16,15 +16,15 @@ use rustc_abi::ExternAbi;
1616use rustc_ast as ast;
1717use rustc_ast:: AttrStyle ;
1818use rustc_ast:: ast:: {
19- AttrKind , Attribute , GenericArgs , IntTy , LitIntType , LitKind , StrStyle , TraitObjectSyntax , UintTy ,
19+ AttrKind , Attribute , BindingMode , GenericArgs , IntTy , LitIntType , LitKind , StrStyle , TraitObjectSyntax , UintTy ,
2020} ;
2121use rustc_ast:: token:: CommentKind ;
2222use rustc_hir:: intravisit:: FnKind ;
2323use rustc_hir:: {
2424 Block , BlockCheckMode , Body , Closure , Destination , Expr , ExprKind , FieldDef , FnHeader , FnRetTy , HirId , Impl ,
25- ImplItem , ImplItemImplKind , ImplItemKind , IsAuto , Item , ItemKind , Lit , LoopSource , MatchSource , MutTy , Node , Path ,
26- QPath , Safety , TraitImplHeader , TraitItem , TraitItemKind , Ty , TyKind , UnOp , UnsafeSource , Variant , VariantData ,
27- YieldSource ,
25+ ImplItem , ImplItemImplKind , ImplItemKind , IsAuto , Item , ItemKind , Lit , LoopSource , MatchSource , MutTy , Node ,
26+ PatExpr , PatExprKind , PatKind , Path , QPath , Safety , TraitImplHeader , TraitItem , TraitItemKind , Ty , TyKind , UnOp ,
27+ UnsafeSource , Variant , VariantData , YieldSource ,
2828} ;
2929use rustc_lint:: { EarlyContext , LateContext , LintContext } ;
3030use rustc_middle:: ty:: TyCtxt ;
@@ -548,97 +548,94 @@ fn ident_search_pat(ident: Ident) -> (Pat, Pat) {
548548
549549fn pat_search_pat ( tcx : TyCtxt < ' _ > , pat : & rustc_hir:: Pat < ' _ > ) -> ( Pat , Pat ) {
550550 match pat. kind {
551- rustc_hir:: PatKind :: Missing | rustc_hir:: PatKind :: Err ( _) => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
552- rustc_hir:: PatKind :: Wild => ( Pat :: Sym ( kw:: Underscore ) , Pat :: Sym ( kw:: Underscore ) ) ,
553- rustc_hir:: PatKind :: Binding ( binding_mode, _, ident, Some ( end_pat) ) => {
554- let start = match binding_mode. 0 {
555- rustc_hir:: ByRef :: Yes ( rustc_hir:: Mutability :: Not ) => Pat :: Str ( "ref" ) ,
556- rustc_hir:: ByRef :: Yes ( rustc_hir:: Mutability :: Mut ) => Pat :: Str ( "ref mut" ) ,
557- rustc_hir:: ByRef :: No => {
558- let ( s, _) = ident_search_pat ( ident) ;
559- s
560- } ,
551+ PatKind :: Missing | PatKind :: Err ( _) => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
552+ PatKind :: Wild => ( Pat :: Sym ( kw:: Underscore ) , Pat :: Sym ( kw:: Underscore ) ) ,
553+ PatKind :: Binding ( binding_mode, _, ident, Some ( end_pat) ) => {
554+ let start = if binding_mode == BindingMode :: NONE {
555+ ident_search_pat ( ident) . 0
556+ } else {
557+ Pat :: Str ( binding_mode. prefix_str ( ) )
561558 } ;
562559
563560 let ( _, end) = pat_search_pat ( tcx, end_pat) ;
564561 ( start, end)
565562 } ,
566- rustc_hir :: PatKind :: Binding ( binding_mode, _, ident, None ) => {
563+ PatKind :: Binding ( binding_mode, _, ident, None ) => {
567564 let ( s, end) = ident_search_pat ( ident) ;
568- let start = match binding_mode. 0 {
569- rustc_hir :: ByRef :: Yes ( rustc_hir :: Mutability :: Not ) => Pat :: Str ( "ref" ) ,
570- rustc_hir :: ByRef :: Yes ( rustc_hir :: Mutability :: Mut ) => Pat :: Str ( "ref mut" ) ,
571- rustc_hir :: ByRef :: No => s ,
565+ let start = if binding_mode == BindingMode :: NONE {
566+ s
567+ } else {
568+ Pat :: Str ( binding_mode . prefix_str ( ) )
572569 } ;
573570
574571 ( start, end)
575572 } ,
576- rustc_hir :: PatKind :: Struct ( path, _, _) => {
573+ PatKind :: Struct ( path, _, _) => {
577574 let ( start, _) = qpath_search_pat ( & path) ;
578575 ( start, Pat :: Str ( "}" ) )
579576 } ,
580- rustc_hir :: PatKind :: TupleStruct ( path, _, _) => {
577+ PatKind :: TupleStruct ( path, _, _) => {
581578 let ( start, _) = qpath_search_pat ( & path) ;
582579 ( start, Pat :: Str ( ")" ) )
583580 } ,
584- rustc_hir :: PatKind :: Or ( plist) => {
581+ PatKind :: Or ( plist) => {
585582 // documented invariant
586583 debug_assert ! ( plist. len( ) >= 2 ) ;
587584 let ( start, _) = pat_search_pat ( tcx, plist. first ( ) . unwrap ( ) ) ;
588585 let ( _, end) = pat_search_pat ( tcx, plist. last ( ) . unwrap ( ) ) ;
589586 ( start, end)
590587 } ,
591- rustc_hir :: PatKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
592- rustc_hir :: PatKind :: Tuple ( _, _) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
593- rustc_hir :: PatKind :: Box ( p) => {
588+ PatKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
589+ PatKind :: Tuple ( _, _) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
590+ PatKind :: Box ( p) => {
594591 let ( _, end) = pat_search_pat ( tcx, p) ;
595592 ( Pat :: Str ( "box" ) , end)
596593 } ,
597- rustc_hir :: PatKind :: Deref ( _) => ( Pat :: Str ( "deref!(" ) , Pat :: Str ( ")" ) ) ,
598- rustc_hir :: PatKind :: Ref ( p, _) => {
594+ PatKind :: Deref ( _) => ( Pat :: Str ( "deref!(" ) , Pat :: Str ( ")" ) ) ,
595+ PatKind :: Ref ( p, _) => {
599596 let ( _, end) = pat_search_pat ( tcx, p) ;
600597 ( Pat :: Str ( "&" ) , end)
601598 } ,
602- rustc_hir :: PatKind :: Expr ( expr) => pat_search_pat_expr_kind ( expr) ,
603- rustc_hir :: PatKind :: Guard ( pat, guard) => {
599+ PatKind :: Expr ( expr) => pat_search_pat_expr_kind ( expr) ,
600+ PatKind :: Guard ( pat, guard) => {
604601 let ( start, _) = pat_search_pat ( tcx, pat) ;
605602 let ( _, end) = expr_search_pat ( tcx, guard) ;
606603 ( start, end)
607604 } ,
608- rustc_hir :: PatKind :: Range ( None , None , range) => match range {
605+ PatKind :: Range ( None , None , range) => match range {
609606 rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "..=" ) , Pat :: Str ( "" ) ) ,
610607 rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( ".." ) , Pat :: Str ( "" ) ) ,
611608 } ,
612- rustc_hir :: PatKind :: Range ( r_start, r_end, range) => {
613- let ( start, _ ) = match r_start {
614- Some ( e) => pat_search_pat_expr_kind ( e) ,
609+ PatKind :: Range ( r_start, r_end, range) => {
610+ let start = match r_start {
611+ Some ( e) => pat_search_pat_expr_kind ( e) . 0 ,
615612 None => match range {
616- rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "..=" ) , Pat :: Str ( "" ) ) ,
617- rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( ".." ) , Pat :: Str ( "" ) ) ,
613+ rustc_hir:: RangeEnd :: Included => Pat :: Str ( "..=" ) ,
614+ rustc_hir:: RangeEnd :: Excluded => Pat :: Str ( ".." ) ,
618615 } ,
619616 } ;
620617
621- let ( _ , end) = match r_end {
622- Some ( e) => pat_search_pat_expr_kind ( e) ,
618+ let end = match r_end {
619+ Some ( e) => pat_search_pat_expr_kind ( e) . 1 ,
623620 None => match range {
624- rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "" ) , Pat :: Str ( " ..=") ) ,
625- rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( "" ) , Pat :: Str ( " ..") ) ,
621+ rustc_hir:: RangeEnd :: Included => Pat :: Str ( "..=" ) ,
622+ rustc_hir:: RangeEnd :: Excluded => Pat :: Str ( ".." ) ,
626623 } ,
627624 } ;
628625 ( start, end)
629626 } ,
630- rustc_hir :: PatKind :: Slice ( _, _, _) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
627+ PatKind :: Slice ( _, _, _) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
631628 }
632629}
633630
634- fn pat_search_pat_expr_kind ( expr : & crate :: PatExpr < ' _ > ) -> ( Pat , Pat ) {
631+ fn pat_search_pat_expr_kind ( expr : & PatExpr < ' _ > ) -> ( Pat , Pat ) {
635632 match expr. kind {
636- crate :: PatExprKind :: Lit { lit, negated } => {
633+ PatExprKind :: Lit { lit, negated } => {
637634 let ( start, end) = lit_search_pat ( & lit. node ) ;
638635 if negated { ( Pat :: Str ( "!" ) , end) } else { ( start, end) }
639636 } ,
640- crate :: PatExprKind :: ConstBlock ( _block) => ( Pat :: Str ( "const {" ) , Pat :: Str ( "}" ) ) ,
641- crate :: PatExprKind :: Path ( path) => qpath_search_pat ( & path) ,
637+ PatExprKind :: ConstBlock ( _block) => ( Pat :: Str ( "const {" ) , Pat :: Str ( "}" ) ) ,
638+ PatExprKind :: Path ( path) => qpath_search_pat ( & path) ,
642639 }
643640}
644641
0 commit comments