diff options
| author | lrh2000 <lrh2000@pku.edu.cn> | 2021-05-16 11:10:05 +0800 |
|---|---|---|
| committer | lrh2000 <lrh2000@pku.edu.cn> | 2021-06-26 23:09:43 +0800 |
| commit | 8dee9bc8fcaf74776d067f34745bc4d7411d80f7 (patch) | |
| tree | eab3a0117f3ae89f6f7248124821a922016f8048 /src | |
| parent | 831ae3c1364b7b033bd1da430bc1cb86d93ad186 (diff) | |
| download | rust-8dee9bc8fcaf74776d067f34745bc4d7411d80f7.tar.gz rust-8dee9bc8fcaf74776d067f34745bc4d7411d80f7.zip | |
Reserve prefixed identifiers and string literals (RFC 3101)
This commit denies any identifiers immediately followed by one of three tokens `"`, `'` or `#`, which is stricter than the requirements of RFC 3101 but may be necessary according to the discussion at [Zulip]. [Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/268952-edition-2021/topic/reserved.20prefixes/near/238470099
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/highlight.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/rust-2021/reserved-prefixes.rs | 36 | ||||
| -rw-r--r-- | src/test/ui/rust-2021/reserved-prefixes.stderr | 92 |
3 files changed, 129 insertions, 1 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 51392ca1191..36e4a240f14 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -413,7 +413,7 @@ impl<'a> Classifier<'a> { }, c => c, }, - TokenKind::RawIdent => Class::Ident, + TokenKind::RawIdent | TokenKind::BadPrefix => Class::Ident, TokenKind::Lifetime { .. } => Class::Lifetime, }; // Anything that didn't return above is the simple case where we the diff --git a/src/test/ui/rust-2021/reserved-prefixes.rs b/src/test/ui/rust-2021/reserved-prefixes.rs new file mode 100644 index 00000000000..5882c7d83d8 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes.rs @@ -0,0 +1,36 @@ +// compile-flags: -Z unstable-options --edition 2021 + +macro_rules! demo2 { + ( $a:tt $b:tt ) => { println!("two tokens") }; +} + +macro_rules! demo3 { + ( $a:tt $b:tt $c:tt ) => { println!("three tokens") }; +} + +macro_rules! demo4 { + ( $a:tt $b:tt $c:tt $d:tt ) => { println!("four tokens") }; +} + +fn main() { + demo3!(foo#bar); //~ ERROR prefix `foo` is unknown + demo2!(foo"bar"); //~ ERROR prefix `foo` is unknown + demo2!(foo'b'); //~ ERROR prefix `foo` is unknown + + demo2!(foo'b); //~ ERROR prefix `foo` is unknown + demo3!(foo# bar); //~ ERROR prefix `foo` is unknown + demo4!(foo#! bar); //~ ERROR prefix `foo` is unknown + demo4!(foo## bar); //~ ERROR prefix `foo` is unknown + + demo4!(foo#bar#); + //~^ ERROR prefix `foo` is unknown + //~| ERROR prefix `bar` is unknown + + demo3!(foo # bar); + demo3!(foo #bar); + demo4!(foo!#bar); + demo4!(foo ##bar); + + demo3!(r"foo"#bar); + demo3!(r#foo#bar); +} diff --git a/src/test/ui/rust-2021/reserved-prefixes.stderr b/src/test/ui/rust-2021/reserved-prefixes.stderr new file mode 100644 index 00000000000..ffaad315202 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes.stderr @@ -0,0 +1,92 @@ +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:16:12 + | +LL | demo3!(foo#bar); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:17:12 + | +LL | demo2!(foo"bar"); + | ^^^- help: consider inserting a whitespace before this `"` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:18:12 + | +LL | demo2!(foo'b'); + | ^^^- help: consider inserting a whitespace before this `'` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:20:12 + | +LL | demo2!(foo'b); + | ^^^- help: consider inserting a whitespace before this `'` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:21:12 + | +LL | demo3!(foo# bar); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:22:12 + | +LL | demo4!(foo#! bar); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:23:12 + | +LL | demo4!(foo## bar); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:25:12 + | +LL | demo4!(foo#bar#); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: prefix `bar` is unknown + --> $DIR/reserved-prefixes.rs:25:16 + | +LL | demo4!(foo#bar#); + | ^^^- help: consider inserting a whitespace before this `#` + | | + | unknown prefix + | + = note: prefixed identifiers and string literals are reserved since Rust 2021 + +error: aborting due to 9 previous errors + |
