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