// `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! (
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);
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![]),
}
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.
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,
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 {
return Err(err);
}
}
+ if is_raw {
+ self.sess.raw_identifier_spans.borrow_mut().push(self.span);
+ }
self.bump();
Ok(i)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(raw_identifiers)]
+
use std::mem;
#[r#repr(r#C, r#packed)]
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(raw_identifiers)]
+
fn r#fn(r#match: u32) -> u32 {
r#match
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(raw_identifiers)]
+
#[derive(Debug, PartialEq, Eq)]
struct IntWrapper(u32);
// except according to those terms.
#![feature(decl_macro)]
+#![feature(raw_identifiers)]
r#macro_rules! r#struct {
($r#struct:expr) => { $r#struct }
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change
+ println!("{}", foo);
+}
--- /dev/null
+error[E0658]: raw identifiers are experimental and subject to change (see issue #48589)
+ --> $DIR/feature-gate-raw-identifiers.rs:12:9
+ |
+LL | let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change
+ | ^^^^^
+ |
+ = help: add #![feature(raw_identifiers)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
// compile-flags: -Z parse-only
#![feature(dyn_trait)]
+#![feature(raw_identifiers)]
fn test_if() {
r#if true { } //~ ERROR found `true`
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `true`
- --> $DIR/raw-literal-keywords.rs:16:10
+ --> $DIR/raw-literal-keywords.rs:17:10
|
LL | r#if true { } //~ ERROR found `true`
| ^^^^ expected one of 8 possible tokens here
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
- --> $DIR/raw-literal-keywords.rs:20:14
+ --> $DIR/raw-literal-keywords.rs:21:14
|
LL | r#struct Test; //~ ERROR found `Test`
| ^^^^ expected one of 8 possible tokens here
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
- --> $DIR/raw-literal-keywords.rs:24:13
+ --> $DIR/raw-literal-keywords.rs:25:13
|
LL | r#union Test; //~ ERROR found `Test`
| ^^^^ expected one of 8 possible tokens here
// compile-flags: -Z parse-only
+#![feature(raw_identifiers)]
+
fn self_test(r#self: u32) {
//~^ ERROR `r#self` is not currently supported.
}
error: `r#self` is not currently supported.
- --> $DIR/raw-literal-self.rs:13:14
+ --> $DIR/raw-literal-self.rs:15:14
|
LL | fn self_test(r#self: u32) {
| ^^^^^^