summaryrefslogtreecommitdiffstats
path: root/tests/ui/parser/macro
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/parser/macro
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/parser/macro')
-rw-r--r--tests/ui/parser/macro/bad-macro-argument.rs4
-rw-r--r--tests/ui/parser/macro/bad-macro-argument.stderr8
-rw-r--r--tests/ui/parser/macro/issue-33569.rs12
-rw-r--r--tests/ui/parser/macro/issue-33569.stderr30
-rw-r--r--tests/ui/parser/macro/issue-37113.rs11
-rw-r--r--tests/ui/parser/macro/issue-37113.stderr16
-rw-r--r--tests/ui/parser/macro/issue-37234.rs9
-rw-r--r--tests/ui/parser/macro/issue-37234.stderr13
-rw-r--r--tests/ui/parser/macro/literals-are-validated-before-expansion.rs10
-rw-r--r--tests/ui/parser/macro/literals-are-validated-before-expansion.stderr18
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-1.rs9
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-1.stderr20
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-2.rs9
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-2.stderr20
-rw-r--r--tests/ui/parser/macro/macro-incomplete-parse.rs27
-rw-r--r--tests/ui/parser/macro/macro-incomplete-parse.stderr35
-rw-r--r--tests/ui/parser/macro/macro-repeat.rs12
-rw-r--r--tests/ui/parser/macro/macro-repeat.stderr14
-rw-r--r--tests/ui/parser/macro/pub-item-macro.rs21
-rw-r--r--tests/ui/parser/macro/pub-item-macro.stderr31
-rw-r--r--tests/ui/parser/macro/trait-non-item-macros.rs13
-rw-r--r--tests/ui/parser/macro/trait-non-item-macros.stderr22
-rw-r--r--tests/ui/parser/macro/trait-object-macro-matcher.rs14
-rw-r--r--tests/ui/parser/macro/trait-object-macro-matcher.stderr15
24 files changed, 393 insertions, 0 deletions
diff --git a/tests/ui/parser/macro/bad-macro-argument.rs b/tests/ui/parser/macro/bad-macro-argument.rs
new file mode 100644
index 000000000..4b6d23890
--- /dev/null
+++ b/tests/ui/parser/macro/bad-macro-argument.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let message = "world";
+ println!("Hello, {}", message/); //~ ERROR expected expression
+}
diff --git a/tests/ui/parser/macro/bad-macro-argument.stderr b/tests/ui/parser/macro/bad-macro-argument.stderr
new file mode 100644
index 000000000..3cd8accb6
--- /dev/null
+++ b/tests/ui/parser/macro/bad-macro-argument.stderr
@@ -0,0 +1,8 @@
+error: expected expression, found end of macro arguments
+ --> $DIR/bad-macro-argument.rs:3:35
+ |
+LL | println!("Hello, {}", message/);
+ | ^ expected expression
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/macro/issue-33569.rs b/tests/ui/parser/macro/issue-33569.rs
new file mode 100644
index 000000000..069d181e9
--- /dev/null
+++ b/tests/ui/parser/macro/issue-33569.rs
@@ -0,0 +1,12 @@
+macro_rules! foo {
+ { $+ } => { //~ ERROR expected identifier, found `+`
+ //~^ ERROR missing fragment specifier
+ //~| ERROR missing fragment specifier
+ //~| WARN this was previously accepted
+ $(x)(y) //~ ERROR expected one of: `*`, `+`, or `?`
+ }
+}
+
+foo!();
+
+fn main() {}
diff --git a/tests/ui/parser/macro/issue-33569.stderr b/tests/ui/parser/macro/issue-33569.stderr
new file mode 100644
index 000000000..0dca090fb
--- /dev/null
+++ b/tests/ui/parser/macro/issue-33569.stderr
@@ -0,0 +1,30 @@
+error: expected identifier, found `+`
+ --> $DIR/issue-33569.rs:2:8
+ |
+LL | { $+ } => {
+ | ^
+
+error: expected one of: `*`, `+`, or `?`
+ --> $DIR/issue-33569.rs:6:13
+ |
+LL | $(x)(y)
+ | ^^^
+
+error: missing fragment specifier
+ --> $DIR/issue-33569.rs:2:8
+ |
+LL | { $+ } => {
+ | ^
+
+error: missing fragment specifier
+ --> $DIR/issue-33569.rs:2:8
+ |
+LL | { $+ } => {
+ | ^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
+ = note: `#[deny(missing_fragment_specifier)]` on by default
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/parser/macro/issue-37113.rs b/tests/ui/parser/macro/issue-37113.rs
new file mode 100644
index 000000000..0044aa561
--- /dev/null
+++ b/tests/ui/parser/macro/issue-37113.rs
@@ -0,0 +1,11 @@
+macro_rules! test_macro {
+ ( $( $t:ty ),* $(),*) => {
+ enum SomeEnum {
+ $( $t, )* //~ ERROR expected identifier, found `String`
+ };
+ };
+}
+
+fn main() {
+ test_macro!(String,);
+}
diff --git a/tests/ui/parser/macro/issue-37113.stderr b/tests/ui/parser/macro/issue-37113.stderr
new file mode 100644
index 000000000..da9e743a0
--- /dev/null
+++ b/tests/ui/parser/macro/issue-37113.stderr
@@ -0,0 +1,16 @@
+error: expected identifier, found `String`
+ --> $DIR/issue-37113.rs:4:16
+ |
+LL | enum SomeEnum {
+ | -------- while parsing this enum
+LL | $( $t, )*
+ | ^^ expected identifier
+...
+LL | test_macro!(String,);
+ | -------------------- in this macro invocation
+ |
+ = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
+ = note: this error originates in the macro `test_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/macro/issue-37234.rs b/tests/ui/parser/macro/issue-37234.rs
new file mode 100644
index 000000000..4debc7479
--- /dev/null
+++ b/tests/ui/parser/macro/issue-37234.rs
@@ -0,0 +1,9 @@
+macro_rules! failed {
+ () => {{
+ let x = 5 ""; //~ ERROR found `""`
+ }}
+}
+
+fn main() {
+ failed!();
+}
diff --git a/tests/ui/parser/macro/issue-37234.stderr b/tests/ui/parser/macro/issue-37234.stderr
new file mode 100644
index 000000000..d79196204
--- /dev/null
+++ b/tests/ui/parser/macro/issue-37234.stderr
@@ -0,0 +1,13 @@
+error: expected one of `.`, `;`, `?`, `else`, or an operator, found `""`
+ --> $DIR/issue-37234.rs:3:19
+ |
+LL | let x = 5 "";
+ | ^^ expected one of `.`, `;`, `?`, `else`, or an operator
+...
+LL | failed!();
+ | --------- in this macro invocation
+ |
+ = note: this error originates in the macro `failed` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/macro/literals-are-validated-before-expansion.rs b/tests/ui/parser/macro/literals-are-validated-before-expansion.rs
new file mode 100644
index 000000000..c3fc754b5
--- /dev/null
+++ b/tests/ui/parser/macro/literals-are-validated-before-expansion.rs
@@ -0,0 +1,10 @@
+macro_rules! black_hole {
+ ($($tt:tt)*) => {}
+}
+
+fn main() {
+ black_hole! { '\u{FFFFFF}' }
+ //~^ ERROR: invalid unicode character escape
+ black_hole! { "this is surrogate: \u{DAAA}" }
+ //~^ ERROR: invalid unicode character escape
+}
diff --git a/tests/ui/parser/macro/literals-are-validated-before-expansion.stderr b/tests/ui/parser/macro/literals-are-validated-before-expansion.stderr
new file mode 100644
index 000000000..e874f6249
--- /dev/null
+++ b/tests/ui/parser/macro/literals-are-validated-before-expansion.stderr
@@ -0,0 +1,18 @@
+error: invalid unicode character escape
+ --> $DIR/literals-are-validated-before-expansion.rs:6:20
+ |
+LL | black_hole! { '\u{FFFFFF}' }
+ | ^^^^^^^^^^ invalid escape
+ |
+ = help: unicode escape must be at most 10FFFF
+
+error: invalid unicode character escape
+ --> $DIR/literals-are-validated-before-expansion.rs:8:39
+ |
+LL | black_hole! { "this is surrogate: \u{DAAA}" }
+ | ^^^^^^^^ invalid escape
+ |
+ = help: unicode escape must not be a surrogate
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/parser/macro/macro-doc-comments-1.rs b/tests/ui/parser/macro/macro-doc-comments-1.rs
new file mode 100644
index 000000000..8d8103bb1
--- /dev/null
+++ b/tests/ui/parser/macro/macro-doc-comments-1.rs
@@ -0,0 +1,9 @@
+macro_rules! outer {
+ (#[$outer:meta]) => ()
+}
+
+outer! {
+ //! Inner
+} //~^ ERROR no rules expected the token `!`
+
+fn main() { }
diff --git a/tests/ui/parser/macro/macro-doc-comments-1.stderr b/tests/ui/parser/macro/macro-doc-comments-1.stderr
new file mode 100644
index 000000000..eaeb62d2c
--- /dev/null
+++ b/tests/ui/parser/macro/macro-doc-comments-1.stderr
@@ -0,0 +1,20 @@
+error: no rules expected the token `!`
+ --> $DIR/macro-doc-comments-1.rs:6:5
+ |
+LL | macro_rules! outer {
+ | ------------------ when calling this macro
+...
+LL | //! Inner
+ | ^^^^^^^^^
+ | |
+ | no rules expected this token in macro call
+ | inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
+ |
+note: while trying to match `[`
+ --> $DIR/macro-doc-comments-1.rs:2:7
+ |
+LL | (#[$outer:meta]) => ()
+ | ^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/macro/macro-doc-comments-2.rs b/tests/ui/parser/macro/macro-doc-comments-2.rs
new file mode 100644
index 000000000..8f33720ae
--- /dev/null
+++ b/tests/ui/parser/macro/macro-doc-comments-2.rs
@@ -0,0 +1,9 @@
+macro_rules! inner {
+ (#![$inner:meta]) => ()
+}
+
+inner! {
+ /// Outer
+} //~^ ERROR no rules expected the token `[`
+
+fn main() { }
diff --git a/tests/ui/parser/macro/macro-doc-comments-2.stderr b/tests/ui/parser/macro/macro-doc-comments-2.stderr
new file mode 100644
index 000000000..1dcd95f6f
--- /dev/null
+++ b/tests/ui/parser/macro/macro-doc-comments-2.stderr
@@ -0,0 +1,20 @@
+error: no rules expected the token `[`
+ --> $DIR/macro-doc-comments-2.rs:6:5
+ |
+LL | macro_rules! inner {
+ | ------------------ when calling this macro
+...
+LL | /// Outer
+ | ^^^^^^^^^
+ | |
+ | no rules expected this token in macro call
+ | outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
+ |
+note: while trying to match `!`
+ --> $DIR/macro-doc-comments-2.rs:2:7
+ |
+LL | (#![$inner:meta]) => ()
+ | ^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/macro/macro-incomplete-parse.rs b/tests/ui/parser/macro/macro-incomplete-parse.rs
new file mode 100644
index 000000000..544e4aa7b
--- /dev/null
+++ b/tests/ui/parser/macro/macro-incomplete-parse.rs
@@ -0,0 +1,27 @@
+macro_rules! ignored_item {
+ () => {
+ fn foo() {}
+ fn bar() {}
+ , //~ ERROR macro expansion ignores token `,`
+ }
+}
+
+macro_rules! ignored_expr {
+ () => ( 1, //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
+
+ 2 )
+}
+
+macro_rules! ignored_pat {
+ () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
+}
+
+ignored_item!();
+
+fn main() {
+ ignored_expr!();
+ match 1 {
+ ignored_pat!() => (),
+ _ => (),
+ }
+}
diff --git a/tests/ui/parser/macro/macro-incomplete-parse.stderr b/tests/ui/parser/macro/macro-incomplete-parse.stderr
new file mode 100644
index 000000000..707417b72
--- /dev/null
+++ b/tests/ui/parser/macro/macro-incomplete-parse.stderr
@@ -0,0 +1,35 @@
+error: macro expansion ignores token `,` and any following
+ --> $DIR/macro-incomplete-parse.rs:5:9
+ |
+LL | ,
+ | ^
+...
+LL | ignored_item!();
+ | --------------- caused by the macro expansion here
+ |
+ = note: the usage of `ignored_item!` is likely invalid in item context
+
+error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
+ --> $DIR/macro-incomplete-parse.rs:10:14
+ |
+LL | () => ( 1,
+ | ^ expected one of `.`, `;`, `?`, `}`, or an operator
+...
+LL | ignored_expr!();
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `ignored_expr` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: macro expansion ignores token `,` and any following
+ --> $DIR/macro-incomplete-parse.rs:16:14
+ |
+LL | () => ( 1, 2 )
+ | ^
+...
+LL | ignored_pat!() => (),
+ | -------------- caused by the macro expansion here
+ |
+ = note: the usage of `ignored_pat!` is likely invalid in pattern context
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/parser/macro/macro-repeat.rs b/tests/ui/parser/macro/macro-repeat.rs
new file mode 100644
index 000000000..3ffbea217
--- /dev/null
+++ b/tests/ui/parser/macro/macro-repeat.rs
@@ -0,0 +1,12 @@
+macro_rules! mac {
+ ( $($v:tt)* ) => {
+ $v
+ //~^ ERROR still repeating at this depth
+ //~| ERROR still repeating at this depth
+ };
+}
+
+fn main() {
+ mac!(0);
+ mac!(1);
+}
diff --git a/tests/ui/parser/macro/macro-repeat.stderr b/tests/ui/parser/macro/macro-repeat.stderr
new file mode 100644
index 000000000..63554b197
--- /dev/null
+++ b/tests/ui/parser/macro/macro-repeat.stderr
@@ -0,0 +1,14 @@
+error: variable 'v' is still repeating at this depth
+ --> $DIR/macro-repeat.rs:3:9
+ |
+LL | $v
+ | ^^
+
+error: variable 'v' is still repeating at this depth
+ --> $DIR/macro-repeat.rs:3:9
+ |
+LL | $v
+ | ^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/parser/macro/pub-item-macro.rs b/tests/ui/parser/macro/pub-item-macro.rs
new file mode 100644
index 000000000..f5f8a01e6
--- /dev/null
+++ b/tests/ui/parser/macro/pub-item-macro.rs
@@ -0,0 +1,21 @@
+// Issue #14660
+
+macro_rules! priv_x {
+ () => {
+ static x: u32 = 0;
+ };
+}
+
+macro_rules! pub_x { () => {
+ pub priv_x!(); //~ ERROR can't qualify macro invocation with `pub`
+ //~^ HELP remove the visibility
+ //~| HELP try adjusting the macro to put `pub` inside the invocation
+}}
+
+mod foo {
+ pub_x!();
+}
+
+fn main() {
+ let y: u32 = foo::x; //~ ERROR static `x` is private
+}
diff --git a/tests/ui/parser/macro/pub-item-macro.stderr b/tests/ui/parser/macro/pub-item-macro.stderr
new file mode 100644
index 000000000..9a2fffcce
--- /dev/null
+++ b/tests/ui/parser/macro/pub-item-macro.stderr
@@ -0,0 +1,31 @@
+error: can't qualify macro invocation with `pub`
+ --> $DIR/pub-item-macro.rs:10:5
+ |
+LL | pub priv_x!();
+ | ^^^ help: remove the visibility
+...
+LL | pub_x!();
+ | -------- in this macro invocation
+ |
+ = help: try adjusting the macro to put `pub` inside the invocation
+ = note: this error originates in the macro `pub_x` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0603]: static `x` is private
+ --> $DIR/pub-item-macro.rs:20:23
+ |
+LL | let y: u32 = foo::x;
+ | ^ private static
+ |
+note: the static `x` is defined here
+ --> $DIR/pub-item-macro.rs:5:9
+ |
+LL | static x: u32 = 0;
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | pub_x!();
+ | -------- in this macro invocation
+ = note: this error originates in the macro `priv_x` which comes from the expansion of the macro `pub_x` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0603`.
diff --git a/tests/ui/parser/macro/trait-non-item-macros.rs b/tests/ui/parser/macro/trait-non-item-macros.rs
new file mode 100644
index 000000000..97fb564bf
--- /dev/null
+++ b/tests/ui/parser/macro/trait-non-item-macros.rs
@@ -0,0 +1,13 @@
+macro_rules! bah {
+ ($a:expr) => {
+ $a
+ }; //~^ ERROR macro expansion ignores token `2` and any following
+}
+
+trait Bar {
+ bah!(2);
+}
+
+fn main() {
+ let _recovery_witness: () = 0; //~ ERROR mismatched types
+}
diff --git a/tests/ui/parser/macro/trait-non-item-macros.stderr b/tests/ui/parser/macro/trait-non-item-macros.stderr
new file mode 100644
index 000000000..db20e6b24
--- /dev/null
+++ b/tests/ui/parser/macro/trait-non-item-macros.stderr
@@ -0,0 +1,22 @@
+error: macro expansion ignores token `2` and any following
+ --> $DIR/trait-non-item-macros.rs:3:9
+ |
+LL | $a
+ | ^^
+...
+LL | bah!(2);
+ | ------- caused by the macro expansion here
+ |
+ = note: the usage of `bah!` is likely invalid in trait item context
+
+error[E0308]: mismatched types
+ --> $DIR/trait-non-item-macros.rs:12:33
+ |
+LL | let _recovery_witness: () = 0;
+ | -- ^ expected `()`, found integer
+ | |
+ | expected due to this
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/parser/macro/trait-object-macro-matcher.rs b/tests/ui/parser/macro/trait-object-macro-matcher.rs
new file mode 100644
index 000000000..560195977
--- /dev/null
+++ b/tests/ui/parser/macro/trait-object-macro-matcher.rs
@@ -0,0 +1,14 @@
+// A single lifetime is not parsed as a type.
+// `ty` matcher in particular doesn't accept a single lifetime
+
+macro_rules! m {
+ ($t: ty) => {
+ let _: $t;
+ };
+}
+
+fn main() {
+ m!('static);
+ //~^ ERROR lifetime in trait object type must be followed by `+`
+ //~| ERROR at least one trait is required for an object type
+}
diff --git a/tests/ui/parser/macro/trait-object-macro-matcher.stderr b/tests/ui/parser/macro/trait-object-macro-matcher.stderr
new file mode 100644
index 000000000..40082564b
--- /dev/null
+++ b/tests/ui/parser/macro/trait-object-macro-matcher.stderr
@@ -0,0 +1,15 @@
+error: lifetime in trait object type must be followed by `+`
+ --> $DIR/trait-object-macro-matcher.rs:11:8
+ |
+LL | m!('static);
+ | ^^^^^^^
+
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/trait-object-macro-matcher.rs:11:8
+ |
+LL | m!('static);
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0224`.