提交 a9d49679 编写于 作者: B bors

Auto merge of #53236 - alexreg:stabilise-raw-idents, r=cramertj

Stabilise raw_identifiers feature

* [Reference PR](https://github.com/rust-lang-nursery/reference/pull/395)
* [Book PR](https://github.com/rust-lang/book/pull/1480)
* [Rust by Example PR](https://github.com/rust-lang/rust-by-example/pull/1095)

Closes #48589.

r? @cramertj
CC @cuviper @centril
......@@ -1928,14 +1928,12 @@ fn report(&mut self, cx: &EarlyContext, span: Span) {
);
// Don't suggest about raw identifiers if the feature isn't active
if cx.sess.features_untracked().raw_identifiers {
lint.span_suggestion_with_applicability(
span,
"you can use a raw identifier to stay compatible",
"r#async".to_string(),
Applicability::MachineApplicable,
);
}
lint.span_suggestion_with_applicability(
span,
"you can use a raw identifier to stay compatible",
"r#async".to_string(),
Applicability::MachineApplicable,
);
lint.emit()
}
}
......
......@@ -382,8 +382,9 @@ fn main() {}
```ignore (limited to a warning during 2018 edition development)
#![feature(rust_2018_preview)]
#![feature(raw_identifiers)] // error: the feature `raw_identifiers` is
// included in the Rust 2018 edition
#![feature(impl_header_lifetime_elision)] // error: the feature
// `impl_header_lifetime_elision` is
// included in the Rust 2018 edition
```
"##,
......
......@@ -423,9 +423,6 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// `use path as _;` and `extern crate c as _;`
(active, underscore_imports, "1.26.0", Some(48216), None),
// Allows keywords to be escaped for use as identifiers
(active, raw_identifiers, "1.26.0", Some(48589), Some(Edition::Edition2018)),
// Allows macro invocations in `extern {}` blocks
(active, macros_in_extern, "1.27.0", Some(49476), None),
......@@ -651,6 +648,8 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// Allows importing and reexporting macros with `use`,
// enables macro modularization in general.
(accepted, use_extern_macros, "1.30.0", Some(35896), None),
// Allows keywords to be escaped for use as identifiers
(accepted, raw_identifiers, "1.30.0", Some(48589), None),
);
// If you change this, please modify src/doc/unstable-book as well. You must
......@@ -2072,16 +2071,6 @@ pub fn check_crate(krate: &ast::Crate,
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);
......
......@@ -10,8 +10,6 @@
// edition:2015
#![feature(raw_identifiers)]
#[macro_export]
macro_rules! produces_async {
() => (pub fn async() {})
......
......@@ -11,8 +11,6 @@
// edition:2015
// aux-build:edition-kw-macro-2015.rs
#![feature(raw_identifiers)]
#[macro_use]
extern crate edition_kw_macro_2015;
......
......@@ -11,8 +11,6 @@
// edition:2015
// aux-build:edition-kw-macro-2018.rs
#![feature(raw_identifiers)]
#[macro_use]
extern crate edition_kw_macro_2018;
......
......@@ -8,8 +8,6 @@
// 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)]
......
......@@ -8,8 +8,6 @@
// 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
}
......
......@@ -8,8 +8,6 @@
// 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);
......
......@@ -9,7 +9,6 @@
// except according to those terms.
#![feature(decl_macro)]
#![feature(raw_identifiers)]
r#macro_rules! r#struct {
($r#struct:expr) => { $r#struct }
......
......@@ -10,11 +10,8 @@
// compile-pass
#![feature(raw_identifiers)]
//~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition
#![feature(impl_header_lifetime_elision)]
//~^ WARN the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition
#![feature(rust_2018_preview)]
fn main() {
let foo = 0;
let bar = r#foo;
}
fn main() {}
warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition
warning[E0705]: the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition
--> $DIR/E0705.rs:13:12
|
LL | #![feature(raw_identifiers)]
| ^^^^^^^^^^^^^^^
LL | #![feature(impl_header_lifetime_elision)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -10,7 +10,6 @@
// edition:2015
#![feature(raw_identifiers)]
#![allow(async_idents)]
#[macro_export]
......
......@@ -12,7 +12,6 @@
// aux-build:edition-kw-macro-2015.rs
// compile-pass
#![feature(raw_identifiers)]
#![allow(async_idents)]
#[macro_use]
......
......@@ -11,8 +11,6 @@
// edition:2015
// aux-build:edition-kw-macro-2015.rs
#![feature(raw_identifiers)]
#[macro_use]
extern crate edition_kw_macro_2015;
......
error: no rules expected the token `r#async`
--> $DIR/edition-keywords-2015-2015-parsing.rs:24:31
--> $DIR/edition-keywords-2015-2015-parsing.rs:22:31
|
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
| ^^^^^^^
error: no rules expected the token `async`
--> $DIR/edition-keywords-2015-2015-parsing.rs:25:35
--> $DIR/edition-keywords-2015-2015-parsing.rs:23:35
|
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
| ^^^^^
......
......@@ -11,8 +11,6 @@
// edition:2015
// aux-build:edition-kw-macro-2018.rs
#![feature(raw_identifiers)]
#[macro_use]
extern crate edition_kw_macro_2018;
......
error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2015-2018-expansion.rs:20:5
--> $DIR/edition-keywords-2015-2018-expansion.rs:18:5
|
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword
| ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
......
......@@ -11,8 +11,6 @@
// edition:2015
// aux-build:edition-kw-macro-2018.rs
#![feature(raw_identifiers)]
#[macro_use]
extern crate edition_kw_macro_2018;
......
error: no rules expected the token `r#async`
--> $DIR/edition-keywords-2015-2018-parsing.rs:24:31
--> $DIR/edition-keywords-2015-2018-parsing.rs:22:31
|
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
| ^^^^^^^
error: no rules expected the token `async`
--> $DIR/edition-keywords-2015-2018-parsing.rs:25:35
--> $DIR/edition-keywords-2015-2018-parsing.rs:23:35
|
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
| ^^^^^
......
// 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);
}
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`.
......@@ -10,8 +10,6 @@
// compile-flags: -Z parse-only
#![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:14: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:18: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:22:13
|
LL | r#union Test; //~ ERROR found `Test`
| ^^^^ expected one of 8 possible tokens here
......
......@@ -10,8 +10,6 @@
// 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:15:14
--> $DIR/raw-literal-self.rs:13:14
|
LL | fn self_test(r#self: u32) {
| ^^^^^^
......
......@@ -2,7 +2,7 @@ error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident-allowed.rs:19:9
|
LL | let async = 3; //~ ERROR: is a keyword
| ^^^^^
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
|
note: lint level defined here
--> $DIR/async-ident-allowed.rs:13:9
......
......@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(raw_identifiers)]
#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)]
#![deny(async_idents)]
......
......@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(raw_identifiers)]
#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)]
#![deny(async_idents)]
......
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:18:4
--> $DIR/async-ident.rs:17:4
|
LL | fn async() {} //~ ERROR async
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
|
note: lint level defined here
--> $DIR/async-ident.rs:13:9
--> $DIR/async-ident.rs:12:9
|
LL | #![deny(async_idents)]
| ^^^^^^^^^^^^
......@@ -13,7 +13,7 @@ LL | #![deny(async_idents)]
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:23:7
--> $DIR/async-ident.rs:22:7
|
LL | ($async:expr, async) => {};
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -22,7 +22,7 @@ LL | ($async:expr, async) => {};
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:23:19
--> $DIR/async-ident.rs:22:19
|
LL | ($async:expr, async) => {};
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -31,7 +31,7 @@ LL | ($async:expr, async) => {};
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:37:11
--> $DIR/async-ident.rs:36:11
|
LL | trait async {}
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -40,7 +40,7 @@ LL | trait async {}
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:41:10
--> $DIR/async-ident.rs:40:10
|
LL | impl async for MyStruct {}
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -49,7 +49,7 @@ LL | impl async for MyStruct {}
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:47:12
--> $DIR/async-ident.rs:46:12
|
LL | static async: u32 = 0;
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -58,7 +58,7 @@ LL | static async: u32 = 0;
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:53:11
--> $DIR/async-ident.rs:52:11
|
LL | const async: u32 = 0;
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -67,7 +67,7 @@ LL | const async: u32 = 0;
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:59:15
--> $DIR/async-ident.rs:58:15
|
LL | impl Foo { fn async() {} }
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -76,7 +76,7 @@ LL | impl Foo { fn async() {} }
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:64:12
--> $DIR/async-ident.rs:63:12
|
LL | struct async {}
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -85,7 +85,7 @@ LL | struct async {}
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:67:9
--> $DIR/async-ident.rs:66:9
|
LL | let async: async = async {};
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -94,7 +94,7 @@ LL | let async: async = async {};
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:67:16
--> $DIR/async-ident.rs:66:16
|
LL | let async: async = async {};
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -103,7 +103,7 @@ LL | let async: async = async {};
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:67:24
--> $DIR/async-ident.rs:66:24
|
LL | let async: async = async {};
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -112,7 +112,7 @@ LL | let async: async = async {};
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:78:19
--> $DIR/async-ident.rs:77:19
|
LL | () => (pub fn async() {})
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......@@ -121,7 +121,7 @@ LL | () => (pub fn async() {})
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:85:6
--> $DIR/async-ident.rs:84:6
|
LL | (async) => (1)
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册