summaryrefslogtreecommitdiffstats
path: root/src/test/ui/parser/macro
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/parser/macro')
-rw-r--r--src/test/ui/parser/macro/bad-macro-argument.rs4
-rw-r--r--src/test/ui/parser/macro/bad-macro-argument.stderr8
-rw-r--r--src/test/ui/parser/macro/issue-33569.rs12
-rw-r--r--src/test/ui/parser/macro/issue-33569.stderr30
-rw-r--r--src/test/ui/parser/macro/issue-37113.rs11
-rw-r--r--src/test/ui/parser/macro/issue-37113.stderr13
-rw-r--r--src/test/ui/parser/macro/issue-37234.rs9
-rw-r--r--src/test/ui/parser/macro/issue-37234.stderr13
-rw-r--r--src/test/ui/parser/macro/literals-are-validated-before-expansion.rs10
-rw-r--r--src/test/ui/parser/macro/literals-are-validated-before-expansion.stderr18
-rw-r--r--src/test/ui/parser/macro/macro-doc-comments-1.rs9
-rw-r--r--src/test/ui/parser/macro/macro-doc-comments-1.stderr14
-rw-r--r--src/test/ui/parser/macro/macro-doc-comments-2.rs9
-rw-r--r--src/test/ui/parser/macro/macro-doc-comments-2.stderr14
-rw-r--r--src/test/ui/parser/macro/macro-incomplete-parse.rs27
-rw-r--r--src/test/ui/parser/macro/macro-incomplete-parse.stderr35
-rw-r--r--src/test/ui/parser/macro/macro-repeat.rs12
-rw-r--r--src/test/ui/parser/macro/macro-repeat.stderr14
-rw-r--r--src/test/ui/parser/macro/pub-item-macro.rs21
-rw-r--r--src/test/ui/parser/macro/pub-item-macro.stderr31
-rw-r--r--src/test/ui/parser/macro/trait-non-item-macros.rs13
-rw-r--r--src/test/ui/parser/macro/trait-non-item-macros.stderr22
-rw-r--r--src/test/ui/parser/macro/trait-object-macro-matcher.rs14
-rw-r--r--src/test/ui/parser/macro/trait-object-macro-matcher.stderr15
24 files changed, 378 insertions, 0 deletions
diff --git a/src/test/ui/parser/macro/bad-macro-argument.rs b/src/test/ui/parser/macro/bad-macro-argument.rs
new file mode 100644
index 000000000..4b6d23890
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/bad-macro-argument.stderr b/src/test/ui/parser/macro/bad-macro-argument.stderr
new file mode 100644
index 000000000..3cd8accb6
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/issue-33569.rs b/src/test/ui/parser/macro/issue-33569.rs
new file mode 100644
index 000000000..069d181e9
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/issue-33569.stderr b/src/test/ui/parser/macro/issue-33569.stderr
new file mode 100644
index 000000000..39d49fd03
--- /dev/null
+++ b/src/test/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 | { $+ } => {
+ | ^
+ |
+ = note: `#[deny(missing_fragment_specifier)]` on by default
+ = 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>
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/parser/macro/issue-37113.rs b/src/test/ui/parser/macro/issue-37113.rs
new file mode 100644
index 000000000..0044aa561
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/issue-37113.stderr b/src/test/ui/parser/macro/issue-37113.stderr
new file mode 100644
index 000000000..0912858dd
--- /dev/null
+++ b/src/test/ui/parser/macro/issue-37113.stderr
@@ -0,0 +1,13 @@
+error: expected identifier, found `String`
+ --> $DIR/issue-37113.rs:4:16
+ |
+LL | $( $t, )*
+ | ^^ expected identifier
+...
+LL | test_macro!(String,);
+ | -------------------- in this macro invocation
+ |
+ = 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/src/test/ui/parser/macro/issue-37234.rs b/src/test/ui/parser/macro/issue-37234.rs
new file mode 100644
index 000000000..4debc7479
--- /dev/null
+++ b/src/test/ui/parser/macro/issue-37234.rs
@@ -0,0 +1,9 @@
+macro_rules! failed {
+ () => {{
+ let x = 5 ""; //~ ERROR found `""`
+ }}
+}
+
+fn main() {
+ failed!();
+}
diff --git a/src/test/ui/parser/macro/issue-37234.stderr b/src/test/ui/parser/macro/issue-37234.stderr
new file mode 100644
index 000000000..d79196204
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/literals-are-validated-before-expansion.rs b/src/test/ui/parser/macro/literals-are-validated-before-expansion.rs
new file mode 100644
index 000000000..c3fc754b5
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/literals-are-validated-before-expansion.stderr b/src/test/ui/parser/macro/literals-are-validated-before-expansion.stderr
new file mode 100644
index 000000000..e874f6249
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-doc-comments-1.rs b/src/test/ui/parser/macro/macro-doc-comments-1.rs
new file mode 100644
index 000000000..8d8103bb1
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-doc-comments-1.stderr b/src/test/ui/parser/macro/macro-doc-comments-1.stderr
new file mode 100644
index 000000000..0ebf3d52b
--- /dev/null
+++ b/src/test/ui/parser/macro/macro-doc-comments-1.stderr
@@ -0,0 +1,14 @@
+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
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/macro/macro-doc-comments-2.rs b/src/test/ui/parser/macro/macro-doc-comments-2.rs
new file mode 100644
index 000000000..8f33720ae
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-doc-comments-2.stderr b/src/test/ui/parser/macro/macro-doc-comments-2.stderr
new file mode 100644
index 000000000..346d86586
--- /dev/null
+++ b/src/test/ui/parser/macro/macro-doc-comments-2.stderr
@@ -0,0 +1,14 @@
+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
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/macro/macro-incomplete-parse.rs b/src/test/ui/parser/macro/macro-incomplete-parse.rs
new file mode 100644
index 000000000..544e4aa7b
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-incomplete-parse.stderr b/src/test/ui/parser/macro/macro-incomplete-parse.stderr
new file mode 100644
index 000000000..707417b72
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-repeat.rs b/src/test/ui/parser/macro/macro-repeat.rs
new file mode 100644
index 000000000..3ffbea217
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/macro-repeat.stderr b/src/test/ui/parser/macro/macro-repeat.stderr
new file mode 100644
index 000000000..63554b197
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/pub-item-macro.rs b/src/test/ui/parser/macro/pub-item-macro.rs
new file mode 100644
index 000000000..f5f8a01e6
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/pub-item-macro.stderr b/src/test/ui/parser/macro/pub-item-macro.stderr
new file mode 100644
index 000000000..9a2fffcce
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/trait-non-item-macros.rs b/src/test/ui/parser/macro/trait-non-item-macros.rs
new file mode 100644
index 000000000..97fb564bf
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/trait-non-item-macros.stderr b/src/test/ui/parser/macro/trait-non-item-macros.stderr
new file mode 100644
index 000000000..db20e6b24
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/trait-object-macro-matcher.rs b/src/test/ui/parser/macro/trait-object-macro-matcher.rs
new file mode 100644
index 000000000..560195977
--- /dev/null
+++ b/src/test/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/src/test/ui/parser/macro/trait-object-macro-matcher.stderr b/src/test/ui/parser/macro/trait-object-macro-matcher.stderr
new file mode 100644
index 000000000..40082564b
--- /dev/null
+++ b/src/test/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`.