@@ -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 ;
@@ -542,97 +542,94 @@ fn ident_search_pat(ident: Ident) -> (Pat, Pat) {
542542
543543fn pat_search_pat ( tcx : TyCtxt < ' _ > , pat : & rustc_hir:: Pat < ' _ > ) -> ( Pat , Pat ) {
544544 match pat. kind {
545- rustc_hir:: PatKind :: Missing | rustc_hir:: PatKind :: Err ( _) => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
546- rustc_hir:: PatKind :: Wild => ( Pat :: Sym ( kw:: Underscore ) , Pat :: Sym ( kw:: Underscore ) ) ,
547- rustc_hir:: PatKind :: Binding ( binding_mode, _, ident, Some ( end_pat) ) => {
548- let start = match binding_mode. 0 {
549- rustc_hir:: ByRef :: Yes ( rustc_hir:: Mutability :: Not ) => Pat :: Str ( "ref" ) ,
550- rustc_hir:: ByRef :: Yes ( rustc_hir:: Mutability :: Mut ) => Pat :: Str ( "ref mut" ) ,
551- rustc_hir:: ByRef :: No => {
552- let ( s, _) = ident_search_pat ( ident) ;
553- s
554- } ,
545+ PatKind :: Missing | PatKind :: Err ( _) => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
546+ PatKind :: Wild => ( Pat :: Sym ( kw:: Underscore ) , Pat :: Sym ( kw:: Underscore ) ) ,
547+ PatKind :: Binding ( binding_mode, _, ident, Some ( end_pat) ) => {
548+ let start = if binding_mode == BindingMode :: NONE {
549+ ident_search_pat ( ident) . 0
550+ } else {
551+ Pat :: Str ( binding_mode. prefix_str ( ) )
555552 } ;
556553
557554 let ( _, end) = pat_search_pat ( tcx, end_pat) ;
558555 ( start, end)
559556 } ,
560- rustc_hir :: PatKind :: Binding ( binding_mode, _, ident, None ) => {
557+ PatKind :: Binding ( binding_mode, _, ident, None ) => {
561558 let ( s, end) = ident_search_pat ( ident) ;
562- let start = match binding_mode. 0 {
563- rustc_hir :: ByRef :: Yes ( rustc_hir :: Mutability :: Not ) => Pat :: Str ( "ref" ) ,
564- rustc_hir :: ByRef :: Yes ( rustc_hir :: Mutability :: Mut ) => Pat :: Str ( "ref mut" ) ,
565- rustc_hir :: ByRef :: No => s ,
559+ let start = if binding_mode == BindingMode :: NONE {
560+ s
561+ } else {
562+ Pat :: Str ( binding_mode . prefix_str ( ) )
566563 } ;
567564
568565 ( start, end)
569566 } ,
570- rustc_hir :: PatKind :: Struct ( path, _, _) => {
567+ PatKind :: Struct ( path, _, _) => {
571568 let ( start, _) = qpath_search_pat ( & path) ;
572569 ( start, Pat :: Str ( "}" ) )
573570 } ,
574- rustc_hir :: PatKind :: TupleStruct ( path, _, _) => {
571+ PatKind :: TupleStruct ( path, _, _) => {
575572 let ( start, _) = qpath_search_pat ( & path) ;
576573 ( start, Pat :: Str ( ")" ) )
577574 } ,
578- rustc_hir :: PatKind :: Or ( plist) => {
575+ PatKind :: Or ( plist) => {
579576 // documented invariant
580577 debug_assert ! ( plist. len( ) >= 2 ) ;
581578 let ( start, _) = pat_search_pat ( tcx, plist. first ( ) . unwrap ( ) ) ;
582579 let ( _, end) = pat_search_pat ( tcx, plist. last ( ) . unwrap ( ) ) ;
583580 ( start, end)
584581 } ,
585- rustc_hir :: PatKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
586- rustc_hir :: PatKind :: Tuple ( _, _) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
587- rustc_hir :: PatKind :: Box ( p) => {
582+ PatKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
583+ PatKind :: Tuple ( _, _) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
584+ PatKind :: Box ( p) => {
588585 let ( _, end) = pat_search_pat ( tcx, p) ;
589586 ( Pat :: Str ( "box" ) , end)
590587 } ,
591- rustc_hir :: PatKind :: Deref ( _) => ( Pat :: Str ( "deref!(" ) , Pat :: Str ( ")" ) ) ,
592- rustc_hir :: PatKind :: Ref ( p, _) => {
588+ PatKind :: Deref ( _) => ( Pat :: Str ( "deref!(" ) , Pat :: Str ( ")" ) ) ,
589+ PatKind :: Ref ( p, _) => {
593590 let ( _, end) = pat_search_pat ( tcx, p) ;
594591 ( Pat :: Str ( "&" ) , end)
595592 } ,
596- rustc_hir :: PatKind :: Expr ( expr) => pat_search_pat_expr_kind ( expr) ,
597- rustc_hir :: PatKind :: Guard ( pat, guard) => {
593+ PatKind :: Expr ( expr) => pat_search_pat_expr_kind ( expr) ,
594+ PatKind :: Guard ( pat, guard) => {
598595 let ( start, _) = pat_search_pat ( tcx, pat) ;
599596 let ( _, end) = expr_search_pat ( tcx, guard) ;
600597 ( start, end)
601598 } ,
602- rustc_hir :: PatKind :: Range ( None , None , range) => match range {
599+ PatKind :: Range ( None , None , range) => match range {
603600 rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "..=" ) , Pat :: Str ( "" ) ) ,
604601 rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( ".." ) , Pat :: Str ( "" ) ) ,
605602 } ,
606- rustc_hir :: PatKind :: Range ( r_start, r_end, range) => {
607- let ( start, _ ) = match r_start {
608- Some ( e) => pat_search_pat_expr_kind ( e) ,
603+ PatKind :: Range ( r_start, r_end, range) => {
604+ let start = match r_start {
605+ Some ( e) => pat_search_pat_expr_kind ( e) . 0 ,
609606 None => match range {
610- rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "..=" ) , Pat :: Str ( "" ) ) ,
611- rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( ".." ) , Pat :: Str ( "" ) ) ,
607+ rustc_hir:: RangeEnd :: Included => Pat :: Str ( "..=" ) ,
608+ rustc_hir:: RangeEnd :: Excluded => Pat :: Str ( ".." ) ,
612609 } ,
613610 } ;
614611
615- let ( _ , end) = match r_end {
616- Some ( e) => pat_search_pat_expr_kind ( e) ,
612+ let end = match r_end {
613+ Some ( e) => pat_search_pat_expr_kind ( e) . 1 ,
617614 None => match range {
618- rustc_hir:: RangeEnd :: Included => ( Pat :: Str ( "" ) , Pat :: Str ( " ..=") ) ,
619- rustc_hir:: RangeEnd :: Excluded => ( Pat :: Str ( "" ) , Pat :: Str ( " ..") ) ,
615+ rustc_hir:: RangeEnd :: Included => Pat :: Str ( "..=" ) ,
616+ rustc_hir:: RangeEnd :: Excluded => Pat :: Str ( ".." ) ,
620617 } ,
621618 } ;
622619 ( start, end)
623620 } ,
624- rustc_hir :: PatKind :: Slice ( _, _, _) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
621+ PatKind :: Slice ( _, _, _) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
625622 }
626623}
627624
628- fn pat_search_pat_expr_kind ( expr : & crate :: PatExpr < ' _ > ) -> ( Pat , Pat ) {
625+ fn pat_search_pat_expr_kind ( expr : & PatExpr < ' _ > ) -> ( Pat , Pat ) {
629626 match expr. kind {
630- crate :: PatExprKind :: Lit { lit, negated } => {
627+ PatExprKind :: Lit { lit, negated } => {
631628 let ( start, end) = lit_search_pat ( & lit. node ) ;
632629 if negated { ( Pat :: Str ( "!" ) , end) } else { ( start, end) }
633630 } ,
634- crate :: PatExprKind :: ConstBlock ( _block) => ( Pat :: Str ( "const {" ) , Pat :: Str ( "}" ) ) ,
635- crate :: PatExprKind :: Path ( path) => qpath_search_pat ( & path) ,
631+ PatExprKind :: ConstBlock ( _block) => ( Pat :: Str ( "const {" ) , Pat :: Str ( "}" ) ) ,
632+ PatExprKind :: Path ( path) => qpath_search_pat ( & path) ,
636633 }
637634}
638635
0 commit comments