@@ -21,10 +21,10 @@ use rustc_ast::ast::{
21
21
use rustc_ast:: token:: CommentKind ;
22
22
use rustc_hir:: intravisit:: FnKind ;
23
23
use rustc_hir:: {
24
- 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 ,
24
+ Block , BlockCheckMode , Body , BoundConstness , BoundPolarity , Closure , Destination , Expr , ExprKind , FieldDef ,
25
+ FnHeader , FnRetTy , HirId , Impl , ImplItem , ImplItemImplKind , ImplItemKind , IsAuto , Item , ItemKind , Lit , LoopSource ,
26
+ MatchSource , MutTy , Node , Path , PolyTraitRef , QPath , Safety , TraitBoundModifiers , TraitImplHeader , TraitItem ,
27
+ TraitItemKind , TraitRef , Ty , TyKind , UnOp , UnsafeSource , Variant , VariantData , YieldSource ,
28
28
} ;
29
29
use rustc_lint:: { EarlyContext , LateContext , LintContext } ;
30
30
use rustc_middle:: ty:: TyCtxt ;
@@ -540,6 +540,40 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) {
540
540
}
541
541
}
542
542
543
+ // NOTE: can't `impl WithSearchPat for TraitRef`, because `TraitRef` doesn't have a `span` field
544
+ // (nor a method)
545
+ fn trait_ref_search_pat ( trait_ref : & TraitRef < ' _ > ) -> ( Pat , Pat ) {
546
+ path_search_pat ( trait_ref. path )
547
+ }
548
+
549
+ fn poly_trait_ref_search_pat ( poly_trait_ref : & PolyTraitRef < ' _ > ) -> ( Pat , Pat ) {
550
+ // NOTE: unfortunately we can't use `bound_generic_params` to see whether the pattern starts with
551
+ // `for<..>`, because if it's empty, we could have either `for<>` (nothing bound), or
552
+ // no `for` at all
553
+ let PolyTraitRef {
554
+ modifiers : TraitBoundModifiers { constness, polarity } ,
555
+ trait_ref,
556
+ ..
557
+ } = poly_trait_ref;
558
+
559
+ let trait_ref_search_pat = trait_ref_search_pat ( trait_ref) ;
560
+
561
+ let start = match constness {
562
+ BoundConstness :: Never => None ,
563
+ BoundConstness :: Maybe ( _) => Some ( Pat :: Str ( "[const]" ) ) ,
564
+ BoundConstness :: Always ( _) => Some ( Pat :: Str ( "const" ) ) ,
565
+ }
566
+ . or ( match polarity {
567
+ BoundPolarity :: Negative ( _) => Some ( Pat :: Str ( "!" ) ) ,
568
+ BoundPolarity :: Maybe ( _) => Some ( Pat :: Str ( "?" ) ) ,
569
+ BoundPolarity :: Positive => None ,
570
+ } )
571
+ . unwrap_or ( trait_ref_search_pat. 0 ) ;
572
+ let end = trait_ref_search_pat. 1 ;
573
+
574
+ ( start, end)
575
+ }
576
+
543
577
fn ident_search_pat ( ident : Ident ) -> ( Pat , Pat ) {
544
578
( Pat :: Sym ( ident. name ) , Pat :: Sym ( ident. name ) )
545
579
}
@@ -572,6 +606,7 @@ impl_with_search_pat!((_cx: LateContext<'tcx>, self: Ty<'_>) => ty_search_pat(se
572
606
impl_with_search_pat ! ( ( _cx: LateContext <' tcx>, self : Ident ) => ident_search_pat( * self ) ) ;
573
607
impl_with_search_pat ! ( ( _cx: LateContext <' tcx>, self : Lit ) => lit_search_pat( & self . node) ) ;
574
608
impl_with_search_pat ! ( ( _cx: LateContext <' tcx>, self : Path <' _>) => path_search_pat( self ) ) ;
609
+ impl_with_search_pat ! ( ( _cx: LateContext <' tcx>, self : PolyTraitRef <' _>) => poly_trait_ref_search_pat( self ) ) ;
575
610
576
611
impl_with_search_pat ! ( ( _cx: EarlyContext <' tcx>, self : Attribute ) => attr_search_pat( self ) ) ;
577
612
impl_with_search_pat ! ( ( _cx: EarlyContext <' tcx>, self : ast:: Ty ) => ast_ty_search_pat( self ) ) ;
0 commit comments