summaryrefslogtreecommitdiffstats
path: root/tests/ui/macros/auxiliary
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/macros/auxiliary
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/macros/auxiliary')
-rw-r--r--tests/ui/macros/auxiliary/attr-from-macro.rs15
-rw-r--r--tests/ui/macros/auxiliary/define-macro.rs6
-rw-r--r--tests/ui/macros/auxiliary/deprecated-macros.rs3
-rw-r--r--tests/ui/macros/auxiliary/dollar-crate-nested-encoding.rs10
-rw-r--r--tests/ui/macros/auxiliary/foreign-crate-macro-pat.rs11
-rw-r--r--tests/ui/macros/auxiliary/issue-100199.rs18
-rw-r--r--tests/ui/macros/auxiliary/issue-19163.rs6
-rw-r--r--tests/ui/macros/auxiliary/issue-40469.rs1
-rw-r--r--tests/ui/macros/auxiliary/issue-75982.rs12
-rw-r--r--tests/ui/macros/auxiliary/macro-comma-support.rs1
-rw-r--r--tests/ui/macros/auxiliary/macro-def-site-super.rs13
-rw-r--r--tests/ui/macros/auxiliary/macro-in-other-crate.rs14
-rw-r--r--tests/ui/macros/auxiliary/macro-include-items-expr.rs3
-rw-r--r--tests/ui/macros/auxiliary/macro-include-items-item.rs3
-rw-r--r--tests/ui/macros/auxiliary/macro_crate_def_only.rs4
-rw-r--r--tests/ui/macros/auxiliary/macro_crate_nonterminal.rs12
-rw-r--r--tests/ui/macros/auxiliary/macro_export_inner_module.rs6
-rw-r--r--tests/ui/macros/auxiliary/macro_with_super_1.rs16
-rw-r--r--tests/ui/macros/auxiliary/or-pattern.rs6
-rw-r--r--tests/ui/macros/auxiliary/proc_macro_def.rs35
-rw-r--r--tests/ui/macros/auxiliary/proc_macro_sequence.rs27
-rw-r--r--tests/ui/macros/auxiliary/two_macros-rpass.rs5
-rw-r--r--tests/ui/macros/auxiliary/two_macros.rs5
-rw-r--r--tests/ui/macros/auxiliary/unstable-macros.rs16
-rw-r--r--tests/ui/macros/auxiliary/use-macro-self.rs6
25 files changed, 254 insertions, 0 deletions
diff --git a/tests/ui/macros/auxiliary/attr-from-macro.rs b/tests/ui/macros/auxiliary/attr-from-macro.rs
new file mode 100644
index 000000000..9b388675c
--- /dev/null
+++ b/tests/ui/macros/auxiliary/attr-from-macro.rs
@@ -0,0 +1,15 @@
+#[macro_export]
+macro_rules! creator {
+ (struct $name1:ident; enum $name2:ident; enum $name3:ident;) => {
+ #[derive(Debug)]
+ pub struct $name1;
+
+ #[derive(Debug)]
+ #[repr(u32)]
+ pub enum $name2 { A }
+
+ #[derive(Debug)]
+ #[repr(u16)]
+ pub enum $name3 { A }
+ }
+}
diff --git a/tests/ui/macros/auxiliary/define-macro.rs b/tests/ui/macros/auxiliary/define-macro.rs
new file mode 100644
index 000000000..4956907c5
--- /dev/null
+++ b/tests/ui/macros/auxiliary/define-macro.rs
@@ -0,0 +1,6 @@
+#[macro_export]
+macro_rules! define_macro {
+ ($i:ident) => {
+ macro_rules! $i { () => {} }
+ }
+}
diff --git a/tests/ui/macros/auxiliary/deprecated-macros.rs b/tests/ui/macros/auxiliary/deprecated-macros.rs
new file mode 100644
index 000000000..657a7252a
--- /dev/null
+++ b/tests/ui/macros/auxiliary/deprecated-macros.rs
@@ -0,0 +1,3 @@
+#[deprecated(since = "1.0.0", note = "deprecation note")]
+#[macro_export]
+macro_rules! deprecated_macro{ () => () }
diff --git a/tests/ui/macros/auxiliary/dollar-crate-nested-encoding.rs b/tests/ui/macros/auxiliary/dollar-crate-nested-encoding.rs
new file mode 100644
index 000000000..bbe6a48c5
--- /dev/null
+++ b/tests/ui/macros/auxiliary/dollar-crate-nested-encoding.rs
@@ -0,0 +1,10 @@
+pub type S = u8;
+
+macro_rules! generate_exported { () => {
+ #[macro_export]
+ macro_rules! exported {
+ () => ($crate::S)
+ }
+}}
+
+generate_exported!();
diff --git a/tests/ui/macros/auxiliary/foreign-crate-macro-pat.rs b/tests/ui/macros/auxiliary/foreign-crate-macro-pat.rs
new file mode 100644
index 000000000..26d4c96d5
--- /dev/null
+++ b/tests/ui/macros/auxiliary/foreign-crate-macro-pat.rs
@@ -0,0 +1,11 @@
+// edition:2018
+
+#[macro_export]
+macro_rules! custom_matches {
+ ($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => {
+ match $expression {
+ $( $pattern )|+ $( if $guard )? => true,
+ _ => false
+ }
+ }
+}
diff --git a/tests/ui/macros/auxiliary/issue-100199.rs b/tests/ui/macros/auxiliary/issue-100199.rs
new file mode 100644
index 000000000..9e190b542
--- /dev/null
+++ b/tests/ui/macros/auxiliary/issue-100199.rs
@@ -0,0 +1,18 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![feature(proc_macro_quote)]
+
+extern crate proc_macro;
+
+use proc_macro::{quote, Ident, Span, TokenStream, TokenTree};
+
+#[proc_macro_attribute]
+pub fn struct_with_bound(_: TokenStream, _: TokenStream) -> TokenStream {
+ let crate_ident = TokenTree::Ident(Ident::new("crate", Span::call_site()));
+ let trait_ident = TokenTree::Ident(Ident::new("MyTrait", Span::call_site()));
+ quote!(
+ struct Foo<T: $crate_ident::$trait_ident> {}
+ )
+}
diff --git a/tests/ui/macros/auxiliary/issue-19163.rs b/tests/ui/macros/auxiliary/issue-19163.rs
new file mode 100644
index 000000000..0c0d9e43c
--- /dev/null
+++ b/tests/ui/macros/auxiliary/issue-19163.rs
@@ -0,0 +1,6 @@
+#![crate_type = "lib"]
+
+#[macro_export]
+macro_rules! mywrite {
+ ($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
+}
diff --git a/tests/ui/macros/auxiliary/issue-40469.rs b/tests/ui/macros/auxiliary/issue-40469.rs
new file mode 100644
index 000000000..4f2f41f2c
--- /dev/null
+++ b/tests/ui/macros/auxiliary/issue-40469.rs
@@ -0,0 +1 @@
+macro_rules! m { () => { $crate::main(); } }
diff --git a/tests/ui/macros/auxiliary/issue-75982.rs b/tests/ui/macros/auxiliary/issue-75982.rs
new file mode 100644
index 000000000..1e1a6126a
--- /dev/null
+++ b/tests/ui/macros/auxiliary/issue-75982.rs
@@ -0,0 +1,12 @@
+const _: () = {
+ #[macro_export]
+ macro_rules! first_macro {
+ () => {}
+ }
+ mod foo {
+ #[macro_export]
+ macro_rules! second_macro {
+ () => {}
+ }
+ }
+};
diff --git a/tests/ui/macros/auxiliary/macro-comma-support.rs b/tests/ui/macros/auxiliary/macro-comma-support.rs
new file mode 100644
index 000000000..6a452c185
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro-comma-support.rs
@@ -0,0 +1 @@
+()
diff --git a/tests/ui/macros/auxiliary/macro-def-site-super.rs b/tests/ui/macros/auxiliary/macro-def-site-super.rs
new file mode 100644
index 000000000..cab747c2c
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro-def-site-super.rs
@@ -0,0 +1,13 @@
+#![feature(decl_macro)]
+
+mod inner1 {
+ pub struct Struct {}
+
+ pub mod inner2 {
+ pub macro mac() {
+ super::Struct
+ }
+ }
+}
+
+pub use inner1::inner2 as public;
diff --git a/tests/ui/macros/auxiliary/macro-in-other-crate.rs b/tests/ui/macros/auxiliary/macro-in-other-crate.rs
new file mode 100644
index 000000000..db8e92018
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro-in-other-crate.rs
@@ -0,0 +1,14 @@
+#[macro_export]
+macro_rules! mac {
+ ($ident:ident) => { let $ident = 42; }
+}
+
+#[macro_export]
+macro_rules! inline {
+ () => ()
+}
+
+#[macro_export]
+macro_rules! from_prelude {
+ () => ()
+}
diff --git a/tests/ui/macros/auxiliary/macro-include-items-expr.rs b/tests/ui/macros/auxiliary/macro-include-items-expr.rs
new file mode 100644
index 000000000..7394f194b
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro-include-items-expr.rs
@@ -0,0 +1,3 @@
+// ignore-test: this is not a test
+
+1
diff --git a/tests/ui/macros/auxiliary/macro-include-items-item.rs b/tests/ui/macros/auxiliary/macro-include-items-item.rs
new file mode 100644
index 000000000..7d54745e0
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro-include-items-item.rs
@@ -0,0 +1,3 @@
+// ignore-test: this is not a test
+
+fn foo() { bar() }
diff --git a/tests/ui/macros/auxiliary/macro_crate_def_only.rs b/tests/ui/macros/auxiliary/macro_crate_def_only.rs
new file mode 100644
index 000000000..c267eefde
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro_crate_def_only.rs
@@ -0,0 +1,4 @@
+#[macro_export]
+macro_rules! make_a_5 {
+ () => (5)
+}
diff --git a/tests/ui/macros/auxiliary/macro_crate_nonterminal.rs b/tests/ui/macros/auxiliary/macro_crate_nonterminal.rs
new file mode 100644
index 000000000..2e2440462
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro_crate_nonterminal.rs
@@ -0,0 +1,12 @@
+pub fn increment(x: usize) -> usize {
+ x + 1
+}
+
+#[macro_export]
+macro_rules! increment {
+ ($x:expr) => ($crate::increment($x))
+}
+
+pub fn check_local() {
+ assert_eq!(increment!(3), 4);
+}
diff --git a/tests/ui/macros/auxiliary/macro_export_inner_module.rs b/tests/ui/macros/auxiliary/macro_export_inner_module.rs
new file mode 100644
index 000000000..d71af9ee6
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro_export_inner_module.rs
@@ -0,0 +1,6 @@
+pub mod inner {
+ #[macro_export]
+ macro_rules! foo {
+ () => (1)
+ }
+}
diff --git a/tests/ui/macros/auxiliary/macro_with_super_1.rs b/tests/ui/macros/auxiliary/macro_with_super_1.rs
new file mode 100644
index 000000000..b015500df
--- /dev/null
+++ b/tests/ui/macros/auxiliary/macro_with_super_1.rs
@@ -0,0 +1,16 @@
+#![crate_type = "lib"]
+
+#[macro_export]
+macro_rules! declare {
+ () => (
+ pub fn aaa() {}
+
+ pub mod bbb {
+ use super::aaa;
+
+ pub fn ccc() {
+ aaa();
+ }
+ }
+ )
+}
diff --git a/tests/ui/macros/auxiliary/or-pattern.rs b/tests/ui/macros/auxiliary/or-pattern.rs
new file mode 100644
index 000000000..a319c405e
--- /dev/null
+++ b/tests/ui/macros/auxiliary/or-pattern.rs
@@ -0,0 +1,6 @@
+#![crate_type = "lib"]
+
+#[macro_export]
+macro_rules! a {
+ ($x:pat|) => ();
+}
diff --git a/tests/ui/macros/auxiliary/proc_macro_def.rs b/tests/ui/macros/auxiliary/proc_macro_def.rs
new file mode 100644
index 000000000..0497e4ae0
--- /dev/null
+++ b/tests/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/tests/ui/macros/auxiliary/proc_macro_sequence.rs b/tests/ui/macros/auxiliary/proc_macro_sequence.rs
new file mode 100644
index 000000000..1331480d8
--- /dev/null
+++ b/tests/ui/macros/auxiliary/proc_macro_sequence.rs
@@ -0,0 +1,27 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![feature(proc_macro_span, proc_macro_quote)]
+
+extern crate proc_macro;
+
+use proc_macro::{quote, Span, TokenStream, TokenTree};
+
+fn assert_same_span(a: Span, b: Span) {
+ assert_eq!(a.start(), b.start());
+ assert_eq!(a.end(), b.end());
+}
+
+// This macro generates a macro with the same macro definition as `manual_foo` in
+// `same-sequence-span.rs` but with the same span for all sequences.
+#[proc_macro]
+pub fn make_foo(_: TokenStream) -> TokenStream {
+ let result = quote! {
+ macro_rules! generated_foo {
+ (1 $$x:expr $$($$y:tt,)* $$(= $$z:tt)*) => {};
+ }
+ };
+
+ result
+}
diff --git a/tests/ui/macros/auxiliary/two_macros-rpass.rs b/tests/ui/macros/auxiliary/two_macros-rpass.rs
new file mode 100644
index 000000000..441a978dd
--- /dev/null
+++ b/tests/ui/macros/auxiliary/two_macros-rpass.rs
@@ -0,0 +1,5 @@
+#[macro_export]
+macro_rules! macro_one { ($($t:tt)*) => ($($t)*) }
+
+#[macro_export]
+macro_rules! macro_two { ($($t:tt)*) => ($($t)*) }
diff --git a/tests/ui/macros/auxiliary/two_macros.rs b/tests/ui/macros/auxiliary/two_macros.rs
new file mode 100644
index 000000000..2330c75c8
--- /dev/null
+++ b/tests/ui/macros/auxiliary/two_macros.rs
@@ -0,0 +1,5 @@
+#[macro_export]
+macro_rules! macro_one { () => ("one") }
+
+#[macro_export]
+macro_rules! macro_two { () => ("two") }
diff --git a/tests/ui/macros/auxiliary/unstable-macros.rs b/tests/ui/macros/auxiliary/unstable-macros.rs
new file mode 100644
index 000000000..3aadd4b0c
--- /dev/null
+++ b/tests/ui/macros/auxiliary/unstable-macros.rs
@@ -0,0 +1,16 @@
+#![feature(decl_macro)]
+#![feature(staged_api)]
+#![stable(feature = "unit_test", since = "1.0.0")]
+
+#[unstable(feature = "unstable_macros", issue = "none")]
+#[macro_export]
+macro_rules! unstable_macro{ () => () }
+
+#[stable(feature = "deprecated_macros", since = "1.0.0")]
+#[deprecated(since = "1.0.0", note = "deprecation note")]
+#[macro_export]
+macro_rules! deprecated_macro{ () => () }
+
+// FIXME: Cannot use a `pub` macro 2.0 in a staged API crate due to reachability issues.
+// #[unstable(feature = "unstable_macros", issue = "none")]
+// pub macro unstable_macro_modern() {}
diff --git a/tests/ui/macros/auxiliary/use-macro-self.rs b/tests/ui/macros/auxiliary/use-macro-self.rs
new file mode 100644
index 000000000..f1307411a
--- /dev/null
+++ b/tests/ui/macros/auxiliary/use-macro-self.rs
@@ -0,0 +1,6 @@
+pub mod foobarius {}
+
+#[macro_export]
+macro_rules! foobarius {
+ () => { () }
+}