about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-06-14 20:39:04 +0000
committerlrh2000 <lrh2000@pku.edu.cn>2021-06-26 23:11:14 +0800
commit2bcd66310062b54b07216008f9e10bc063f9ad5e (patch)
tree5738efd31e4c4e0d10cfad58e3a6abea88aac2f7
parent7490305e13bd90b4c4697d465ceea8df2625a7ad (diff)
downloadrust-2bcd66310062b54b07216008f9e10bc063f9ad5e.tar.gz
rust-2bcd66310062b54b07216008f9e10bc063f9ad5e.zip
Add reserved_prefixe tests for macros from different editions.
-rw-r--r--src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs25
-rw-r--r--src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs25
-rw-r--r--src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs21
-rw-r--r--src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr29
-rw-r--r--src/test/ui/rust-2021/reserved-prefixes-via-macro.rs12
5 files changed, 112 insertions, 0 deletions
diff --git a/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs
new file mode 100644
index 00000000000..eb301e5e1be
--- /dev/null
+++ b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs
@@ -0,0 +1,25 @@
+// force-host
+// edition:2018
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+use std::str::FromStr;
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_integer_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#123").unwrap().into_iter().count().to_string().parse().unwrap()
+}
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_char_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#'a'").unwrap().into_iter().count().to_string().parse().unwrap()
+}
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_string_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#\"abc\"").unwrap().into_iter().count().to_string().parse().unwrap()
+}
diff --git a/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs
new file mode 100644
index 00000000000..691bfdc15c3
--- /dev/null
+++ b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs
@@ -0,0 +1,25 @@
+// force-host
+// edition:2021
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+use std::str::FromStr;
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_integer_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#123").unwrap().into_iter().count().to_string().parse().unwrap()
+}
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_char_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#'a'").unwrap().into_iter().count().to_string().parse().unwrap()
+}
+
+#[proc_macro]
+pub fn number_of_tokens_in_a_prefixed_string_literal(_: TokenStream) -> TokenStream {
+    TokenStream::from_str("hey#\"abc\"").unwrap().into_iter().count().to_string().parse().unwrap()
+}
diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs
new file mode 100644
index 00000000000..74f20660613
--- /dev/null
+++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs
@@ -0,0 +1,21 @@
+// edition:2018
+// aux-build:reserved-prefixes-macro-2018.rs
+// aux-build:reserved-prefixes-macro-2021.rs
+
+extern crate reserved_prefixes_macro_2018 as m2018;
+extern crate reserved_prefixes_macro_2021 as m2021;
+
+fn main() {
+    // Ok:
+    m2018::number_of_tokens_in_a_prefixed_integer_literal!();
+    m2018::number_of_tokens_in_a_prefixed_char_literal!();
+    m2018::number_of_tokens_in_a_prefixed_string_literal!();
+
+    // Error, even though *this* crate is 2018:
+    m2021::number_of_tokens_in_a_prefixed_integer_literal!();
+    //~^ ERROR prefix `hey` is unknown
+    m2021::number_of_tokens_in_a_prefixed_char_literal!();
+    //~^ ERROR prefix `hey` is unknown
+    m2021::number_of_tokens_in_a_prefixed_string_literal!();
+    //~^ ERROR prefix `hey` is unknown
+}
diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr
new file mode 100644
index 00000000000..9d7ca570c4c
--- /dev/null
+++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr
@@ -0,0 +1,29 @@
+error: prefix `hey` is unknown
+  --> $DIR/reserved-prefixes-via-macro-2.rs:15:5
+   |
+LL |     m2021::number_of_tokens_in_a_prefixed_integer_literal!();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+   = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_integer_literal` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: prefix `hey` is unknown
+  --> $DIR/reserved-prefixes-via-macro-2.rs:17:5
+   |
+LL |     m2021::number_of_tokens_in_a_prefixed_char_literal!();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+   = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_char_literal` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: prefix `hey` is unknown
+  --> $DIR/reserved-prefixes-via-macro-2.rs:19:5
+   |
+LL |     m2021::number_of_tokens_in_a_prefixed_string_literal!();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+   = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_string_literal` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs b/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs
new file mode 100644
index 00000000000..110b6d64ccc
--- /dev/null
+++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs
@@ -0,0 +1,12 @@
+// run-pass
+// edition:2021
+// aux-build:reserved-prefixes-macro-2018.rs
+
+extern crate reserved_prefixes_macro_2018 as m2018;
+
+fn main() {
+    // Ok, even though *this* crate is 2021:
+    assert_eq!(m2018::number_of_tokens_in_a_prefixed_integer_literal!(), 3);
+    assert_eq!(m2018::number_of_tokens_in_a_prefixed_char_literal!(), 3);
+    assert_eq!(m2018::number_of_tokens_in_a_prefixed_string_literal!(), 3);
+}