@@ -25,7 +25,7 @@ use rustc_hir::{
2525use rustc_lint:: { LateContext , LintContext } ;
2626use rustc_middle:: ty:: TyCtxt ;
2727use rustc_session:: Session ;
28- use rustc_span:: { Span , Symbol } ;
28+ use rustc_span:: { symbol :: Ident , Span , Symbol } ;
2929use rustc_target:: spec:: abi:: Abi ;
3030
3131/// The search pattern to look for. Used by `span_matches_pat`
@@ -344,14 +344,18 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
344344 }
345345}
346346
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 > {
348352 type Context : LintContext ;
349353 fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) ;
350354 fn span ( & self ) -> Span ;
351355}
352356macro_rules! impl_with_search_pat {
353357 ( $cx: ident: $ty: ident with $fn: ident $( ( $tcx: ident) ) ?) => {
354- impl <' cx> WithSearchPat for $ty<' cx> {
358+ impl <' cx> WithSearchPat < ' cx> for $ty<' cx> {
355359 type Context = $cx<' cx>;
356360 #[ allow( unused_variables) ]
357361 fn search_pat( & self , cx: & Self :: Context ) -> ( Pat , Pat ) {
@@ -372,7 +376,7 @@ impl_with_search_pat!(LateContext: FieldDef with field_def_search_pat);
372376impl_with_search_pat ! ( LateContext : Variant with variant_search_pat) ;
373377impl_with_search_pat ! ( LateContext : Ty with ty_search_pat) ;
374378
375- impl < ' cx > WithSearchPat for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
379+ impl < ' cx > WithSearchPat < ' cx > for ( & FnKind < ' cx > , & Body < ' cx > , HirId , Span ) {
376380 type Context = LateContext < ' cx > ;
377381
378382 fn search_pat ( & self , cx : & Self :: Context ) -> ( Pat , Pat ) {
@@ -385,7 +389,7 @@ impl<'cx> WithSearchPat for (&FnKind<'cx>, &Body<'cx>, HirId, Span) {
385389}
386390
387391// `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 {
389393 type Context = LateContext < ' cx > ;
390394
391395 fn search_pat ( & self , _cx : & Self :: Context ) -> ( Pat , Pat ) {
@@ -397,11 +401,24 @@ impl<'cx> WithSearchPat for &'cx Attribute {
397401 }
398402}
399403
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+
400417/// Checks if the item likely came from a proc-macro.
401418///
402419/// This should be called after `in_external_macro` and the initial pattern matching of the ast as
403420/// 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 {
405422 let ( start_pat, end_pat) = item. search_pat ( cx) ;
406423 !span_matches_pat ( cx. sess ( ) , item. span ( ) , start_pat, end_pat)
407424}
0 commit comments