about summary refs log tree commit diff
path: root/tests/ui/macros
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-08-19 14:43:48 +0000
committerbors <bors@rust-lang.org>2025-08-19 14:43:48 +0000
commit16ad385579cebb6f7d53367c552661b6b51a4a02 (patch)
tree9127978a6da3066df8319d286ccfa6ec8451b969 /tests/ui/macros
parent8c32e313cccf7df531e2d49ffb8227bb92304aee (diff)
parent5d37e8e707e74a0820e1171f200d45fd2b8fa13c (diff)
downloadrust-16ad385579cebb6f7d53367c552661b6b51a4a02.tar.gz
rust-16ad385579cebb6f7d53367c552661b6b51a4a02.zip
Auto merge of #145599 - jieyouxu:rollup-523cxhm, r=jieyouxu
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#139345 (Extend `QueryStability` to handle `IntoIterator` implementations)
 - rust-lang/rust#140740 (Add `-Zindirect-branch-cs-prefix`)
 - rust-lang/rust#142079 (nll-relate: improve hr opaque types support)
 - rust-lang/rust#142938 (implement std::fs::set_permissions_nofollow on unix)
 - rust-lang/rust#143730 (fmt of non-decimal radix untangled)
 - rust-lang/rust#144767 (Correct some grammar in integer documentation)
 - rust-lang/rust#144906 (Require approval from t-infra instead of t-release on tier bumps)
 - rust-lang/rust#144983 (Rehome 37 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - rust-lang/rust#145025 (run spellcheck as a tidy extra check in ci)
 - rust-lang/rust#145099 (rustc_target: Add the `32s` target feature for LoongArch)
 - rust-lang/rust#145166 (suggest using `pub(crate)` for E0364)
 - rust-lang/rust#145255 (dec2flt: Provide more valid inputs examples)
 - rust-lang/rust#145306 (Add tracing to various miscellaneous functions)
 - rust-lang/rust#145336 (Hide docs for `core::unicode`)
 - rust-lang/rust#145585 (Miri: fix handling of in-place argument and return place handling)

r? `@ghost`
`@rustbot` modify labels: rollup
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
+