@@ -1756,11 +1756,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
17561756
17571757 fn visit_path ( & mut self , path : & ' a ast:: Path , _id : NodeId ) {
17581758 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 ( ) ) ;
17591767 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,
17611769 "`crate` in paths is experimental" ) ;
17621770 } 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,
17641772 "`extern` in paths is experimental" ) ;
17651773 }
17661774 }
0 commit comments