Fix feature gating for crate/extern in paths
This commit is contained in:
parent
3a30bad6de
commit
1458684279
1 changed files with 10 additions and 2 deletions
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue