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