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
This commit is contained in:
parent
831ae3c136
commit
8dee9bc8fc
5 changed files with 172 additions and 7 deletions
36
src/test/ui/rust-2021/reserved-prefixes.rs
Normal file
36
src/test/ui/rust-2021/reserved-prefixes.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
92
src/test/ui/rust-2021/reserved-prefixes.stderr
Normal file
92
src/test/ui/rust-2021/reserved-prefixes.stderr
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue