@@ -1756,11 +1756,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
1756
1756
1757
1757
fn visit_path ( & mut self , path : & ' a ast:: Path , _id : NodeId ) {
1758
1758
for segment in & path. segments {
1759
+ // Identifiers we are going to check could come from a legacy macro (e.g. `#[test]`).
1760
+ // For such macros identifiers must have empty context, because this context is
1761
+ // used during name resolution and produced names must be unhygienic for compatibility.
1762
+ // On the other hand, we need the actual non-empty context for feature gate checking
1763
+ // because it's hygienic even for legacy macros. As previously stated, such context
1764
+ // cannot be kept in identifiers, so it's kept in paths instead and we take it from
1765
+ // there while keeping location info from the ident span.
1766
+ let span = segment. ident . span . with_ctxt ( path. span . ctxt ( ) ) ;
1759
1767
if segment. ident . name == keywords:: Crate . name ( ) {
1760
- gate_feature_post ! ( & self , crate_in_paths, segment . ident . span,
1768
+ gate_feature_post ! ( & self , crate_in_paths, span,
1761
1769
"`crate` in paths is experimental" ) ;
1762
1770
} else if segment. ident . name == keywords:: Extern . name ( ) {
1763
- gate_feature_post ! ( & self , extern_in_paths, segment . ident . span,
1771
+ gate_feature_post ! ( & self , extern_in_paths, span,
1764
1772
"`extern` in paths is experimental" ) ;
1765
1773
}
1766
1774
}
0 commit comments