@@ -19,8 +19,8 @@ use rustc_ast::{
19
19
} ;
20
20
use rustc_hir:: {
21
21
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 ,
24
24
} ;
25
25
use rustc_lint:: { LateContext , LintContext } ;
26
26
use rustc_middle:: ty:: TyCtxt ;
@@ -319,6 +319,31 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
319
319
}
320
320
}
321
321
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
+
322
347
pub trait WithSearchPat {
323
348
type Context : LintContext ;
324
349
fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) ;
@@ -345,6 +370,7 @@ impl_with_search_pat!(LateContext: TraitItem with trait_item_search_pat);
345
370
impl_with_search_pat ! ( LateContext : ImplItem with impl_item_search_pat) ;
346
371
impl_with_search_pat ! ( LateContext : FieldDef with field_def_search_pat) ;
347
372
impl_with_search_pat ! ( LateContext : Variant with variant_search_pat) ;
373
+ impl_with_search_pat ! ( LateContext : Ty with ty_search_pat) ;
348
374
349
375
impl < ' cx > WithSearchPat for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
350
376
type Context = LateContext < ' cx > ;
0 commit comments