Feature gate raw identifiers.
This commit is contained in:
@@ -452,6 +452,9 @@ declare_features! (
|
||||
|
||||
// `use path as _;` and `extern crate c as _;`
|
||||
(active, underscore_imports, "1.26.0", Some(48216), None),
|
||||
|
||||
// Raw identifiers allowing keyword names to be used
|
||||
(active, raw_identifiers, "1.26.0", Some(48589), None),
|
||||
);
|
||||
|
||||
declare_features! (
|
||||
@@ -1932,6 +1935,17 @@ pub fn check_crate(krate: &ast::Crate,
|
||||
parse_sess: sess,
|
||||
plugin_attributes,
|
||||
};
|
||||
|
||||
if !features.raw_identifiers {
|
||||
for &span in sess.raw_identifier_spans.borrow().iter() {
|
||||
if !span.allows_unstable() {
|
||||
gate_feature!(&ctx, raw_identifiers, span,
|
||||
"raw identifiers are experimental and subject to change"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let visitor = &mut PostExpansionVisitor { context: &ctx };
|
||||
visitor.whole_crate_feature_gates(krate);
|
||||
visit::walk_crate(visitor, krate);
|
||||
|
||||
@@ -1796,6 +1796,7 @@ mod tests {
|
||||
included_mod_stack: RefCell::new(Vec::new()),
|
||||
code_map: cm,
|
||||
missing_fragment_specifiers: RefCell::new(HashSet::new()),
|
||||
raw_identifier_spans: RefCell::new(Vec::new()),
|
||||
registered_diagnostics: Lock::new(ErrorMap::new()),
|
||||
non_modrs_mods: RefCell::new(vec![]),
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ pub struct ParseSess {
|
||||
pub unstable_features: UnstableFeatures,
|
||||
pub config: CrateConfig,
|
||||
pub missing_fragment_specifiers: RefCell<HashSet<Span>>,
|
||||
/// Places where raw identifiers were used. This is used for feature gating
|
||||
/// raw identifiers
|
||||
pub raw_identifier_spans: RefCell<Vec<Span>>,
|
||||
/// The registered diagnostics codes
|
||||
pub registered_diagnostics: Lock<ErrorMap>,
|
||||
// Spans where a `mod foo;` statement was included in a non-mod.rs file.
|
||||
@@ -74,6 +77,7 @@ impl ParseSess {
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
config: HashSet::new(),
|
||||
missing_fragment_specifiers: RefCell::new(HashSet::new()),
|
||||
raw_identifier_spans: RefCell::new(Vec::new()),
|
||||
registered_diagnostics: Lock::new(ErrorMap::new()),
|
||||
included_mod_stack: RefCell::new(vec![]),
|
||||
code_map,
|
||||
|
||||
@@ -784,7 +784,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, ast::Ident> {
|
||||
match self.token {
|
||||
token::Ident(i, _) => {
|
||||
token::Ident(i, is_raw) => {
|
||||
if self.token.is_reserved_ident() {
|
||||
let mut err = self.expected_ident_found();
|
||||
if recover {
|
||||
@@ -793,6 +793,9 @@ impl<'a> Parser<'a> {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
if is_raw {
|
||||
self.sess.raw_identifier_spans.borrow_mut().push(self.span);
|
||||
}
|
||||
self.bump();
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user