@@ -25,7 +25,7 @@ use rustc_hir::{
25
25
use rustc_lint:: { LateContext , LintContext } ;
26
26
use rustc_middle:: ty:: TyCtxt ;
27
27
use rustc_session:: Session ;
28
- use rustc_span:: { Span , Symbol } ;
28
+ use rustc_span:: { symbol :: Ident , Span , Symbol } ;
29
29
use rustc_target:: spec:: abi:: Abi ;
30
30
31
31
/// The search pattern to look for. Used by `span_matches_pat`
@@ -344,14 +344,18 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
344
344
}
345
345
}
346
346
347
- pub trait WithSearchPat {
347
+ fn ident_search_pat ( ident : Ident ) -> ( Pat , Pat ) {
348
+ ( Pat :: OwnedStr ( ident. name . as_str ( ) . to_owned ( ) ) , Pat :: Str ( "" ) )
349
+ }
350
+
351
+ pub trait WithSearchPat < ' cx > {
348
352
type Context : LintContext ;
349
353
fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) ;
350
354
fn span ( & self ) -> Span ;
351
355
}
352
356
macro_rules! impl_with_search_pat {
353
357
( $cx: ident: $ty: ident with $fn: ident $( ( $tcx: ident) ) ?) => {
354
- impl <' cx> WithSearchPat for $ty<' cx> {
358
+ impl <' cx> WithSearchPat < ' cx> for $ty<' cx> {
355
359
type Context = $cx<' cx>;
356
360
#[ allow( unused_variables) ]
357
361
fn search_pat( & self , cx: & Self :: Context ) -> ( Pat , Pat ) {
@@ -372,7 +376,7 @@ impl_with_search_pat!(LateContext: FieldDef with field_def_search_pat);
372
376
impl_with_search_pat ! ( LateContext : Variant with variant_search_pat) ;
373
377
impl_with_search_pat ! ( LateContext : Ty with ty_search_pat) ;
374
378
375
- impl < ' cx > WithSearchPat for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
379
+ impl < ' cx > WithSearchPat < ' cx > for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
376
380
type Context = LateContext < ' cx > ;
377
381
378
382
fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) {
@@ -385,7 +389,7 @@ impl<'cx> WithSearchPat for (&FnKind<'cx>, &Body<'cx>, HirId, Span) {
385
389
}
386
390
387
391
// `Attribute` does not have the `hir` associated lifetime, so we cannot use the macro
388
- impl < ' cx > WithSearchPat for & ' cx Attribute {
392
+ impl < ' cx > WithSearchPat < ' cx > for & ' cx Attribute {
389
393
type Context = LateContext < ' cx > ;
390
394
391
395
fn search_pat ( & self , _cx : & Self :: Context ) -> ( Pat , Pat ) {
@@ -397,11 +401,24 @@ impl<'cx> WithSearchPat for &'cx Attribute {
397
401
}
398
402
}
399
403
404
+ // `Ident` does not have the `hir` associated lifetime, so we cannot use the macro
405
+ impl < ' cx > WithSearchPat < ' cx > for Ident {
406
+ type Context = LateContext < ' cx > ;
407
+
408
+ fn search_pat ( & self , _cx : & Self :: Context ) -> ( Pat , Pat ) {
409
+ ident_search_pat ( * self )
410
+ }
411
+
412
+ fn span ( & self ) -> Span {
413
+ self . span
414
+ }
415
+ }
416
+
400
417
/// Checks if the item likely came from a proc-macro.
401
418
///
402
419
/// This should be called after `in_external_macro` and the initial pattern matching of the ast as
403
420
/// it is significantly slower than both of those.
404
- pub fn is_from_proc_macro < T : WithSearchPat > ( cx : & T :: Context , item : & T ) -> bool {
421
+ pub fn is_from_proc_macro < ' cx , T : WithSearchPat < ' cx > > ( cx : & T :: Context , item : & T ) -> bool {
405
422
let ( start_pat, end_pat) = item. search_pat ( cx) ;
406
423
!span_matches_pat ( cx. sess ( ) , item. span ( ) , start_pat, end_pat)
407
424
}
0 commit comments