about summary refs log tree commit diff
path: root/tests/ui/macros
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/macros')
-rw-r--r--tests/ui/macros/macro-invocation-span-error-7970.rs11
-rw-r--r--tests/ui/macros/macro-invocation-span-error-7970.stderr17
-rw-r--r--tests/ui/macros/macro-path-type-bounds-8521.rs26
-rw-r--r--tests/ui/macros/macro-self-mutability-7911.rs38
-rw-r--r--tests/ui/macros/macro-self-mutability-7911.stderr12
5 files changed, 104 insertions, 0 deletions
diff --git a/tests/ui/macros/macro-invocation-span-error-7970.rs b/tests/ui/macros/macro-invocation-span-error-7970.rs
new file mode 100644
index 00000000000..df7e1cfea88
--- /dev/null
+++ b/tests/ui/macros/macro-invocation-span-error-7970.rs
@@ -0,0 +1,11 @@
+// https://github.com/rust-lang/rust/issues/7970
+macro_rules! one_arg_macro {
+    ($fmt:expr) => {
+        print!(concat!($fmt, "\n"))
+    };
+}
+
+fn main() {
+    one_arg_macro!();
+    //~^ ERROR unexpected end of macro invocation
+}
diff --git a/tests/ui/macros/macro-invocation-span-error-7970.stderr b/tests/ui/macros/macro-invocation-span-error-7970.stderr
new file mode 100644
index 00000000000..beb54e05992
--- /dev/null
+++ b/tests/ui/macros/macro-invocation-span-error-7970.stderr
@@ -0,0 +1,17 @@
+error: unexpected end of macro invocation
+  --> $DIR/macro-invocation-span-error-7970.rs:9:5
+   |
+LL | macro_rules! one_arg_macro {
+   | -------------------------- when calling this macro
+...
+LL |     one_arg_macro!();
+   |     ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
+   |
+note: while trying to match meta-variable `$fmt:expr`
+  --> $DIR/macro-invocation-span-error-7970.rs:3:6
+   |
+LL |     ($fmt:expr) => {
+   |      ^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/macros/macro-path-type-bounds-8521.rs b/tests/ui/macros/macro-path-type-bounds-8521.rs
new file mode 100644
index 00000000000..975d3dc402e
--- /dev/null
+++ b/tests/ui/macros/macro-path-type-bounds-8521.rs
@@ -0,0 +1,26 @@
+// https://github.com/rust-lang/rust/issues/8521
+//@ check-pass
+trait Foo1 {}
+
+trait A {}
+
+macro_rules! foo1(($t:path) => {
+    impl<T: $t> Foo1 for T {}
+});
+
+foo1!(A);
+
+trait Foo2 {}
+
+trait B<T> {}
+
+#[allow(unused)]
+struct C {}
+
+macro_rules! foo2(($t:path) => {
+    impl<T: $t> Foo2 for T {}
+});
+
+foo2!(B<C>);
+
+fn main() {}
diff --git a/tests/ui/macros/macro-self-mutability-7911.rs b/tests/ui/macros/macro-self-mutability-7911.rs
new file mode 100644
index 00000000000..5313f86d97f
--- /dev/null
+++ b/tests/ui/macros/macro-self-mutability-7911.rs
@@ -0,0 +1,38 @@
+// https://github.com/rust-lang/rust/issues/7911
+//@ run-pass
+// (Closes #7911) Test that we can use the same self expression
+// with different mutability in macro in two methods
+
+#![allow(unused_variables)] // unused foobar_immut + foobar_mut
+trait FooBar {
+    fn dummy(&self) { } //~ WARN method `dummy` is never used
+}
+struct Bar(#[allow(dead_code)] i32);
+struct Foo { bar: Bar }
+
+impl FooBar for Bar {}
+
+trait Test {
+    fn get_immut(&self) -> &dyn FooBar;
+    fn get_mut(&mut self) -> &mut dyn FooBar;
+}
+
+macro_rules! generate_test { ($type_:path, $slf:ident, $field:expr) => (
+    impl Test for $type_ {
+        fn get_immut(&$slf) -> &dyn FooBar {
+            &$field as &dyn FooBar
+        }
+
+        fn get_mut(&mut $slf) -> &mut dyn FooBar {
+            &mut $field as &mut dyn FooBar
+        }
+    }
+)}
+
+generate_test!(Foo, self, self.bar);
+
+pub fn main() {
+    let mut foo: Foo = Foo { bar: Bar(42) };
+    { let foobar_immut = foo.get_immut(); }
+    { let foobar_mut = foo.get_mut(); }
+}
diff --git a/tests/ui/macros/macro-self-mutability-7911.stderr b/tests/ui/macros/macro-self-mutability-7911.stderr
new file mode 100644
index 00000000000..7fc2abe06eb
--- /dev/null
+++ b/tests/ui/macros/macro-self-mutability-7911.stderr
@@ -0,0 +1,12 @@
+warning: method `dummy` is never used
+  --> $DIR/macro-self-mutability-7911.rs:8:8
+   |
+LL | trait FooBar {
+   |       ------ method in this trait
+LL |     fn dummy(&self) { }
+   |        ^^^^^
+   |
+   = note: `#[warn(dead_code)]` on by default
+
+warning: 1 warning emitted
+