@@ -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,43 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
319
319
}
320
320
}
321
321
322
+ // TODO: Waiting on `ty_search_pat`.
323
+ // fn where_pred_search_pat(where_pred: &WherePredicate<'_>) -> (Pat, Pat) {
324
+ // match where_pred {
325
+ // WherePredicate::BoundPredicate(bound) => {
326
+ // todo!();
327
+ // },
328
+ // WherePredicate::RegionPredicate(region) => {
329
+ //
330
+ // },
331
+ // WherePredicate::EqPredicate(..) => unimplemented!(),
332
+ // }
333
+ // }
334
+
335
+ fn ty_search_pat ( ty : & Ty < ' _ > ) -> ( Pat , Pat ) {
336
+ match ty. kind {
337
+ TyKind :: Slice ( ..) | TyKind :: Array ( ..) => ( Pat :: Str ( "[" ) , Pat :: Str ( "]" ) ) ,
338
+ TyKind :: Ptr ( MutTy { mutbl, ty } ) => (
339
+ if mutbl. is_mut ( ) {
340
+ Pat :: Str ( "*const" )
341
+ } else {
342
+ Pat :: Str ( "*mut" )
343
+ } ,
344
+ ty_search_pat ( ty) . 1 ,
345
+ ) ,
346
+ TyKind :: Ref ( _, MutTy { ty, .. } ) => ( Pat :: Str ( "&" ) , ty_search_pat ( ty) . 1 ) ,
347
+ TyKind :: BareFn ( bare_fn) => (
348
+ Pat :: OwnedStr ( format ! ( "{}{} fn" , bare_fn. unsafety. prefix_str( ) , bare_fn. abi. name( ) ) ) ,
349
+ ty_search_pat ( ty) . 1 ,
350
+ ) ,
351
+ TyKind :: Never => ( Pat :: Str ( "!" ) , Pat :: Str ( "" ) ) ,
352
+ TyKind :: Tup ( ..) => ( Pat :: Str ( "(" ) , Pat :: Str ( ")" ) ) ,
353
+ TyKind :: OpaqueDef ( ..) => ( Pat :: Str ( "impl" ) , Pat :: Str ( "" ) ) ,
354
+ // NOTE: This is missing `TraitObject` and `Path` here. It always return true then.
355
+ _ => ( Pat :: Str ( "" ) , Pat :: Str ( "" ) ) ,
356
+ }
357
+ }
358
+
322
359
pub trait WithSearchPat {
323
360
type Context : LintContext ;
324
361
fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) ;
@@ -345,6 +382,7 @@ impl_with_search_pat!(LateContext: TraitItem with trait_item_search_pat);
345
382
impl_with_search_pat ! ( LateContext : ImplItem with impl_item_search_pat) ;
346
383
impl_with_search_pat ! ( LateContext : FieldDef with field_def_search_pat) ;
347
384
impl_with_search_pat ! ( LateContext : Variant with variant_search_pat) ;
385
+ impl_with_search_pat ! ( LateContext : Ty with ty_search_pat) ;
348
386
349
387
impl < ' cx > WithSearchPat for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
350
388
type Context = LateContext < ' cx > ;
0 commit comments