about summary refs log tree commit diff
path: root/src/test/ui/macros
diff options
context:
space:
mode:
authorCaio <c410.f3r@gmail.com>2021-11-14 14:38:42 -0300
committerCaio <c410.f3r@gmail.com>2021-11-14 14:38:42 -0300
commitab5434f9b8d3937fe33f813b3f8e1a43a4657781 (patch)
tree382869ba24cd359543b11a5440b6b9c04c0574dd /src/test/ui/macros
parentf820d9d4e5af7d298ffdc3145b48e206b65e8e28 (diff)
Move some tests to more reasonable directories
Diffstat (limited to 'src/test/ui/macros')
-rw-r--r--src/test/ui/macros/auxiliary/proc_macro_def.rs35
-rw-r--r--src/test/ui/macros/concat.rs6
-rw-r--r--src/test/ui/macros/concat.stderr30
-rw-r--r--src/test/ui/macros/include-single-expr-helper-1.rs5
-rw-r--r--src/test/ui/macros/include-single-expr-helper.rs5
-rw-r--r--src/test/ui/macros/include-single-expr.rs6
-rw-r--r--src/test/ui/macros/include-single-expr.stderr10
-rw-r--r--src/test/ui/macros/malformed_macro_lhs.rs7
-rw-r--r--src/test/ui/macros/malformed_macro_lhs.stderr8
-rw-r--r--src/test/ui/macros/no-std-macros.rs13
-rw-r--r--src/test/ui/macros/proc_macro.rs37
11 files changed, 162 insertions, 0 deletions
diff --git a/src/test/ui/macros/auxiliary/proc_macro_def.rs b/src/test/ui/macros/auxiliary/proc_macro_def.rs
new file mode 100644
index 00000000000..0497e4ae07d
--- /dev/null
+++ b/src/test/ui/macros/auxiliary/proc_macro_def.rs
@@ -0,0 +1,35 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![feature(proc_macro_quote)]
+
+extern crate proc_macro;
+
+use proc_macro::*;
+
+#[proc_macro_attribute]
+pub fn attr_tru(_attr: TokenStream, item: TokenStream) -> TokenStream {
+    let name = item.into_iter().nth(1).unwrap();
+    quote!(fn $name() -> bool { true })
+}
+
+#[proc_macro_attribute]
+pub fn attr_identity(_attr: TokenStream, item: TokenStream) -> TokenStream {
+    quote!($item)
+}
+
+#[proc_macro]
+pub fn tru(_ts: TokenStream) -> TokenStream {
+    quote!(true)
+}
+
+#[proc_macro]
+pub fn ret_tru(_ts: TokenStream) -> TokenStream {
+    quote!(return true;)
+}
+
+#[proc_macro]
+pub fn identity(ts: TokenStream) -> TokenStream {
+    quote!($ts)
+}
diff --git a/src/test/ui/macros/concat.rs b/src/test/ui/macros/concat.rs
new file mode 100644
index 00000000000..d7ab7d62625
--- /dev/null
+++ b/src/test/ui/macros/concat.rs
@@ -0,0 +1,6 @@
+fn main() {
+    concat!(b'f');  //~ ERROR: cannot concatenate a byte string literal
+    concat!(b"foo");  //~ ERROR: cannot concatenate a byte string literal
+    concat!(foo);   //~ ERROR: expected a literal
+    concat!(foo()); //~ ERROR: expected a literal
+}
diff --git a/src/test/ui/macros/concat.stderr b/src/test/ui/macros/concat.stderr
new file mode 100644
index 00000000000..61fb9de1ef9
--- /dev/null
+++ b/src/test/ui/macros/concat.stderr
@@ -0,0 +1,30 @@
+error: cannot concatenate a byte string literal
+  --> $DIR/concat.rs:2:13
+   |
+LL |     concat!(b'f');
+   |             ^^^^
+
+error: cannot concatenate a byte string literal
+  --> $DIR/concat.rs:3:13
+   |
+LL |     concat!(b"foo");
+   |             ^^^^^^
+
+error: expected a literal
+  --> $DIR/concat.rs:4:13
+   |
+LL |     concat!(foo);
+   |             ^^^
+   |
+   = note: only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()`
+
+error: expected a literal
+  --> $DIR/concat.rs:5:13
+   |
+LL |     concat!(foo());
+   |             ^^^^^
+   |
+   = note: only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/macros/include-single-expr-helper-1.rs b/src/test/ui/macros/include-single-expr-helper-1.rs
new file mode 100644
index 00000000000..aa6380bd24d
--- /dev/null
+++ b/src/test/ui/macros/include-single-expr-helper-1.rs
@@ -0,0 +1,5 @@
+// ignore-test auxiliary file for include-single-expr.rs
+
+0
+
+// trailing comment permitted
diff --git a/src/test/ui/macros/include-single-expr-helper.rs b/src/test/ui/macros/include-single-expr-helper.rs
new file mode 100644
index 00000000000..84d8b69603b
--- /dev/null
+++ b/src/test/ui/macros/include-single-expr-helper.rs
@@ -0,0 +1,5 @@
+// ignore-test auxiliary file for include-single-expr.rs
+
+0
+10
+100
diff --git a/src/test/ui/macros/include-single-expr.rs b/src/test/ui/macros/include-single-expr.rs
new file mode 100644
index 00000000000..0f4c29ec014
--- /dev/null
+++ b/src/test/ui/macros/include-single-expr.rs
@@ -0,0 +1,6 @@
+// error-pattern include macro expected single expression
+
+fn main() {
+    include!("include-single-expr-helper.rs");
+    include!("include-single-expr-helper-1.rs");
+}
diff --git a/src/test/ui/macros/include-single-expr.stderr b/src/test/ui/macros/include-single-expr.stderr
new file mode 100644
index 00000000000..80eecf8f1b9
--- /dev/null
+++ b/src/test/ui/macros/include-single-expr.stderr
@@ -0,0 +1,10 @@
+error: include macro expected single expression in source
+  --> $DIR/include-single-expr-helper.rs:4:1
+   |
+LL | 10
+   | ^^
+   |
+   = note: `#[deny(incomplete_include)]` on by default
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/macros/malformed_macro_lhs.rs b/src/test/ui/macros/malformed_macro_lhs.rs
new file mode 100644
index 00000000000..f57d2fb4dc9
--- /dev/null
+++ b/src/test/ui/macros/malformed_macro_lhs.rs
@@ -0,0 +1,7 @@
+macro_rules! my_precioooous {
+    t => (1); //~ ERROR invalid macro matcher
+}
+
+fn main() {
+    my_precioooous!();
+}
diff --git a/src/test/ui/macros/malformed_macro_lhs.stderr b/src/test/ui/macros/malformed_macro_lhs.stderr
new file mode 100644
index 00000000000..adf64b08935
--- /dev/null
+++ b/src/test/ui/macros/malformed_macro_lhs.stderr
@@ -0,0 +1,8 @@
+error: invalid macro matcher; matchers must be contained in balanced delimiters
+  --> $DIR/malformed_macro_lhs.rs:2:5
+   |
+LL |     t => (1);
+   |     ^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/macros/no-std-macros.rs b/src/test/ui/macros/no-std-macros.rs
new file mode 100644
index 00000000000..ada643c7ac0
--- /dev/null
+++ b/src/test/ui/macros/no-std-macros.rs
@@ -0,0 +1,13 @@
+// compile-flags: --crate-type=lib
+// check-pass
+// issue #55482
+#![no_std]
+
+macro_rules! foo {
+    ($e:expr) => {
+        $crate::core::assert!($e);
+        $crate::core::assert_eq!($e, true);
+    };
+}
+
+pub fn foo() { foo!(true); }
diff --git a/src/test/ui/macros/proc_macro.rs b/src/test/ui/macros/proc_macro.rs
new file mode 100644
index 00000000000..66f9cdc5567
--- /dev/null
+++ b/src/test/ui/macros/proc_macro.rs
@@ -0,0 +1,37 @@
+// run-pass
+// aux-build:proc_macro_def.rs
+// ignore-cross-compile
+
+extern crate proc_macro_def;
+
+use proc_macro_def::{attr_tru, attr_identity, identity, ret_tru, tru};
+
+#[attr_tru]
+fn f1() -> bool {
+    return false;
+}
+
+#[attr_identity]
+fn f2() -> bool {
+    return identity!(true);
+}
+
+fn f3() -> identity!(bool) {
+    ret_tru!();
+}
+
+fn f4(x: bool) -> bool {
+    match x {
+        identity!(true) => false,
+        identity!(false) => true,
+    }
+}
+
+fn main() {
+    assert!(f1());
+    assert!(f2());
+    assert!(tru!());
+    assert!(f3());
+    assert!(identity!(5 == 5));
+    assert!(f4(false));
+}