@@ -2886,7 +2886,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2886
2886
2887
2887
pub fn find_field_index ( self , ident : Ident , variant : & VariantDef ) -> Option < usize > {
2888
2888
variant. fields . iter ( ) . position ( |field| {
2889
- self . adjust_ident ( ident, variant . def_id , hir :: DUMMY_HIR_ID ) . 0 == field . ident . modern ( )
2889
+ self . hygienic_eq ( ident, field . ident , variant . def_id )
2890
2890
} )
2891
2891
}
2892
2892
@@ -3085,19 +3085,32 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
3085
3085
/// its supposed definition name (`def_name`). The method also needs `DefId` of the supposed
3086
3086
/// definition's parent/scope to perform comparison.
3087
3087
pub fn hygienic_eq ( self , use_name : Ident , def_name : Ident , def_parent_def_id : DefId ) -> bool {
3088
- self . adjust_ident ( use_name, def_parent_def_id, hir:: DUMMY_HIR_ID ) . 0 == def_name. modern ( )
3088
+ // We could use `Ident::eq` here, but we deliberately don't. The name
3089
+ // comparison fails frequently, and we want to avoid the expensive
3090
+ // `modern()` calls required for the span comparison whenever possible.
3091
+ use_name. name == def_name. name &&
3092
+ self . adjust_ident ( use_name, def_parent_def_id) . span . ctxt ( ) == def_name. modern ( ) . span . ctxt ( )
3089
3093
}
3090
3094
3091
- pub fn adjust_ident ( self , mut ident : Ident , scope : DefId , block : hir:: HirId ) -> ( Ident , DefId ) {
3092
- ident = ident. modern ( ) ;
3093
- let target_expansion = match scope. krate {
3095
+ fn expansion_that_defined ( self , scope : DefId ) -> Mark {
3096
+ match scope. krate {
3094
3097
LOCAL_CRATE => self . hir ( ) . definitions ( ) . expansion_that_defined ( scope. index ) ,
3095
3098
_ => Mark :: root ( ) ,
3096
- } ;
3097
- let scope = match ident. span . adjust ( target_expansion) {
3099
+ }
3100
+ }
3101
+
3102
+ pub fn adjust_ident ( self , mut ident : Ident , scope : DefId ) -> Ident {
3103
+ ident = ident. modern ( ) ;
3104
+ ident. span . adjust ( self . expansion_that_defined ( scope) ) ;
3105
+ ident
3106
+ }
3107
+
3108
+ pub fn adjust_ident_and_get_scope ( self , mut ident : Ident , scope : DefId , block : hir:: HirId )
3109
+ -> ( Ident , DefId ) {
3110
+ ident = ident. modern ( ) ;
3111
+ let scope = match ident. span . adjust ( self . expansion_that_defined ( scope) ) {
3098
3112
Some ( actual_expansion) =>
3099
3113
self . hir ( ) . definitions ( ) . parent_module_of_macro_def ( actual_expansion) ,
3100
- None if block == hir:: DUMMY_HIR_ID => DefId :: local ( CRATE_DEF_INDEX ) , // Dummy DefId
3101
3114
None => self . hir ( ) . get_module_parent_by_hir_id ( block) ,
3102
3115
} ;
3103
3116
( ident, scope)
0 commit comments