@@ -19,8 +19,8 @@ use rustc_ast::{
1919} ;
2020use rustc_hir:: {
2121 intravisit:: FnKind , Block , BlockCheckMode , Body , Closure , Destination , Expr , ExprKind , FieldDef , FnHeader , HirId ,
22- Impl , ImplItem , ImplItemKind , IsAuto , Item , ItemKind , LoopSource , MatchSource , Node , QPath , TraitItem ,
23- TraitItemKind , UnOp , UnsafeSource , Unsafety , Variant , VariantData , YieldSource ,
22+ Impl , ImplItem , ImplItemKind , IsAuto , Item , ItemKind , LoopSource , MatchSource , MutTy , Node , QPath , TraitItem ,
23+ TraitItemKind , Ty , TyKind , UnOp , UnsafeSource , Unsafety , Variant , VariantData , YieldSource ,
2424} ;
2525use rustc_lint:: { LateContext , LintContext } ;
2626use rustc_middle:: ty:: TyCtxt ;
@@ -319,6 +319,31 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
319319 }
320320}
321321
322+ fn ty_search_pat ( ty : & Ty < ' _ > ) -> ( Pat , Pat ) {
323+ match ty. kind {
324+ TyKind :: Slice ( ..) | TyKind :: Array ( ..) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
325+ TyKind :: Ptr ( MutTy { mutbl, ty } ) => (
326+ if mutbl. is_mut ( ) {
327+ Pat :: Str ( "*const" )
328+ } else {
329+ Pat :: Str ( "*mut" )
330+ } ,
331+ ty_search_pat ( ty) . 1 ,
332+ ) ,
333+ TyKind :: Ref ( _, MutTy { ty, .. } ) => ( Pat :: Str ( "&" ) , ty_search_pat ( ty) . 1 ) ,
334+ TyKind :: BareFn ( bare_fn) => (
335+ Pat :: OwnedStr ( format ! ( "{}{} fn" , bare_fn. unsafety. prefix_str( ) , bare_fn. abi. name( ) ) ) ,
336+ ty_search_pat ( ty) . 1 ,
337+ ) ,
338+ TyKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
339+ TyKind :: Tup ( ..) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
340+ TyKind :: OpaqueDef ( ..) => ( Pat :: Str ( "impl" ) , Pat :: Str ( "" ) ) ,
341+ TyKind :: Path ( qpath) => qpath_search_pat ( & qpath) ,
342+ // NOTE: This is missing `TraitObject`. It always return true then.
343+ _ => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
344+ }
345+ }
346+
322347pub trait WithSearchPat {
323348 type Context : LintContext ;
324349 fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) ;
@@ -345,6 +370,7 @@ impl_with_search_pat!(LateContext: TraitItem with trait_item_search_pat);
345370impl_with_search_pat ! ( LateContext : ImplItem with impl_item_search_pat) ;
346371impl_with_search_pat ! ( LateContext : FieldDef with field_def_search_pat) ;
347372impl_with_search_pat ! ( LateContext : Variant with variant_search_pat) ;
373+ impl_with_search_pat ! ( LateContext : Ty with ty_search_pat) ;
348374
349375impl < ' cx > WithSearchPat for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
350376 type Context = LateContext < ' cx > ;
0 commit comments