Skip to content

Commit

Permalink
Fix feature gating for crate/extern in paths
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 6, 2018
1 parent 3a30bad commit 1458684
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -1766,11 +1766,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

fn visit_path(&mut self, path: &'a ast::Path, _id: NodeId) {
for segment in &path.segments {
// Identifiers we are going to check could come from a legacy macro (e.g. `#[test]`).
// For such macros identifiers must have empty context, because this context is
// used during name resolution and produced names must be unhygienic for compatibility.
// On the other hand, we need the actual non-empty context for feature gate checking
// because it's hygienic even for legacy macros. As previously stated, such context
// cannot be kept in identifiers, so it's kept in paths instead and we take it from
// there while keeping location info from the ident span.
let span = segment.ident.span.with_ctxt(path.span.ctxt());
if segment.ident.name == keywords::Crate.name() {
gate_feature_post!(&self, crate_in_paths, segment.ident.span,
gate_feature_post!(&self, crate_in_paths, span,
"`crate` in paths is experimental");
} else if segment.ident.name == keywords::Extern.name() {
gate_feature_post!(&self, extern_in_paths, segment.ident.span,
gate_feature_post!(&self, extern_in_paths, span,
"`extern` in paths is experimental");
}
}
Expand Down

0 comments on commit 1458684

Please sign in to comment.