summaryrefslogtreecommitdiffstats
path: root/tests/ui/proc-macro
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/proc-macro')
-rw-r--r--tests/ui/proc-macro/allowed-signatures.rs26
-rw-r--r--tests/ui/proc-macro/break-token-spans.stderr2
-rw-r--r--tests/ui/proc-macro/crt-static.rs3
-rw-r--r--tests/ui/proc-macro/issue-37788.stderr2
-rw-r--r--tests/ui/proc-macro/proc-macro-abi.rs31
-rw-r--r--tests/ui/proc-macro/proc-macro-abi.stderr20
-rw-r--r--tests/ui/proc-macro/resolved-located-at.stderr2
-rw-r--r--tests/ui/proc-macro/signature-proc-macro-attribute.rs32
-rw-r--r--tests/ui/proc-macro/signature-proc-macro-attribute.stderr42
-rw-r--r--tests/ui/proc-macro/signature-proc-macro-derive.rs31
-rw-r--r--tests/ui/proc-macro/signature-proc-macro-derive.stderr40
-rw-r--r--tests/ui/proc-macro/signature-proc-macro.rs31
-rw-r--r--tests/ui/proc-macro/signature-proc-macro.stderr40
-rw-r--r--tests/ui/proc-macro/signature.rs6
-rw-r--r--tests/ui/proc-macro/signature.stderr46
15 files changed, 335 insertions, 19 deletions
diff --git a/tests/ui/proc-macro/allowed-signatures.rs b/tests/ui/proc-macro/allowed-signatures.rs
new file mode 100644
index 000000000..868508761
--- /dev/null
+++ b/tests/ui/proc-macro/allowed-signatures.rs
@@ -0,0 +1,26 @@
+// check-pass
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![allow(private_in_public)]
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn foo<T>(t: T) -> TokenStream {
+ TokenStream::new()
+}
+
+trait Project {
+ type Assoc;
+}
+
+impl Project for () {
+ type Assoc = TokenStream;
+}
+
+#[proc_macro]
+pub fn uwu(_input: <() as Project>::Assoc) -> <() as Project>::Assoc {
+ TokenStream::new()
+}
diff --git a/tests/ui/proc-macro/break-token-spans.stderr b/tests/ui/proc-macro/break-token-spans.stderr
index 0a0322b8a..e69cc3b8c 100644
--- a/tests/ui/proc-macro/break-token-spans.stderr
+++ b/tests/ui/proc-macro/break-token-spans.stderr
@@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/break-token-spans.rs:14:32
|
LL | let a: Option<Option<u8>>= true;
- | ------------------ ^^^^ expected enum `Option`, found `bool`
+ | ------------------ ^^^^ expected `Option<Option<u8>>`, found `bool`
| |
| expected due to this
|
diff --git a/tests/ui/proc-macro/crt-static.rs b/tests/ui/proc-macro/crt-static.rs
index 6103acb7b..020128fa2 100644
--- a/tests/ui/proc-macro/crt-static.rs
+++ b/tests/ui/proc-macro/crt-static.rs
@@ -5,6 +5,9 @@
// ignore-wasm32
// ignore-sgx no support for proc-macro crate type
// build-pass
+// force-host
+// no-prefer-dynamic
+
#![crate_type = "proc-macro"]
// FIXME: This don't work when crate-type is specified by attribute
diff --git a/tests/ui/proc-macro/issue-37788.stderr b/tests/ui/proc-macro/issue-37788.stderr
index 345520d48..e437bb90b 100644
--- a/tests/ui/proc-macro/issue-37788.stderr
+++ b/tests/ui/proc-macro/issue-37788.stderr
@@ -7,7 +7,7 @@ LL | // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`
LL | std::cell::Cell::new(0)
| ^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
| |
- | expected `()`, found struct `Cell`
+ | expected `()`, found `Cell<{integer}>`
|
= note: expected unit type `()`
found struct `Cell<{integer}>`
diff --git a/tests/ui/proc-macro/proc-macro-abi.rs b/tests/ui/proc-macro/proc-macro-abi.rs
new file mode 100644
index 000000000..873660a5b
--- /dev/null
+++ b/tests/ui/proc-macro/proc-macro-abi.rs
@@ -0,0 +1,31 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+#![allow(warnings)]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub extern "C" fn abi(a: TokenStream) -> TokenStream {
+ //~^ ERROR proc macro functions may not be `extern "C"`
+ a
+}
+
+#[proc_macro]
+pub extern "system" fn abi2(a: TokenStream) -> TokenStream {
+ //~^ ERROR proc macro functions may not be `extern "system"`
+ a
+}
+
+#[proc_macro]
+pub extern fn abi3(a: TokenStream) -> TokenStream {
+ //~^ ERROR proc macro functions may not be `extern "C"`
+ a
+}
+
+#[proc_macro]
+pub extern "Rust" fn abi4(a: TokenStream) -> TokenStream {
+ a
+}
diff --git a/tests/ui/proc-macro/proc-macro-abi.stderr b/tests/ui/proc-macro/proc-macro-abi.stderr
new file mode 100644
index 000000000..9a781be09
--- /dev/null
+++ b/tests/ui/proc-macro/proc-macro-abi.stderr
@@ -0,0 +1,20 @@
+error: proc macro functions may not be `extern "C"`
+ --> $DIR/proc-macro-abi.rs:11:1
+ |
+LL | pub extern "C" fn abi(a: TokenStream) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: proc macro functions may not be `extern "system"`
+ --> $DIR/proc-macro-abi.rs:17:1
+ |
+LL | pub extern "system" fn abi2(a: TokenStream) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: proc macro functions may not be `extern "C"`
+ --> $DIR/proc-macro-abi.rs:23:1
+ |
+LL | pub extern fn abi3(a: TokenStream) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/proc-macro/resolved-located-at.stderr b/tests/ui/proc-macro/resolved-located-at.stderr
index 422820e9d..0b4dbcba6 100644
--- a/tests/ui/proc-macro/resolved-located-at.stderr
+++ b/tests/ui/proc-macro/resolved-located-at.stderr
@@ -12,7 +12,7 @@ error[E0308]: mismatched types
LL | fn main() {
| - expected `()` because of default return type
LL | resolve_located_at!(a b)
- | ^ expected `()`, found struct `S`
+ | ^ expected `()`, found `S`
|
= note: this error originates in the macro `resolve_located_at` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui/proc-macro/signature-proc-macro-attribute.rs b/tests/ui/proc-macro/signature-proc-macro-attribute.rs
new file mode 100644
index 000000000..51abc8e7d
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro-attribute.rs
@@ -0,0 +1,32 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn bad_input(input: String) -> TokenStream {
+ //~^ ERROR mismatched attribute proc macro signature
+ ::proc_macro::TokenStream::new()
+}
+
+#[proc_macro_attribute]
+pub fn bad_output(input: TokenStream) -> String {
+ //~^ ERROR mismatched attribute proc macro signature
+ //~| ERROR mismatched attribute proc macro signature
+ String::from("blah")
+}
+
+#[proc_macro_attribute]
+pub fn bad_everything(input: String) -> String {
+ //~^ ERROR mismatched attribute proc macro signature
+ //~| ERROR mismatched attribute proc macro signature
+ input
+}
+
+#[proc_macro_attribute]
+pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ //~^ ERROR mismatched attribute proc macro signature
+}
diff --git a/tests/ui/proc-macro/signature-proc-macro-attribute.stderr b/tests/ui/proc-macro/signature-proc-macro-attribute.stderr
new file mode 100644
index 000000000..abf7a6f3c
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro-attribute.stderr
@@ -0,0 +1,42 @@
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:10:1
+ |
+LL | pub fn bad_input(input: String) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attribute proc macro must have two arguments of type `proc_macro::TokenStream`
+
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:16:42
+ |
+LL | pub fn bad_output(input: TokenStream) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: attribute proc macros must have a signature of `fn(TokenStream, TokenStream) -> TokenStream`
+
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:16:1
+ |
+LL | pub fn bad_output(input: TokenStream) -> String {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attribute proc macro must have two arguments of type `proc_macro::TokenStream`
+
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:23:41
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: attribute proc macros must have a signature of `fn(TokenStream, TokenStream) -> TokenStream`
+
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:23:1
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attribute proc macro must have two arguments of type `proc_macro::TokenStream`
+
+error: mismatched attribute proc macro signature
+ --> $DIR/signature-proc-macro-attribute.rs:30:49
+ |
+LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ | ^^^^^^^^^ found unexpected argument
+
+error: aborting due to 6 previous errors
+
diff --git a/tests/ui/proc-macro/signature-proc-macro-derive.rs b/tests/ui/proc-macro/signature-proc-macro-derive.rs
new file mode 100644
index 000000000..f2fd824b6
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro-derive.rs
@@ -0,0 +1,31 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Blah)]
+pub fn bad_input(input: String) -> TokenStream {
+ //~^ ERROR mismatched derive proc macro signature
+ TokenStream::new()
+}
+
+#[proc_macro_derive(Bleh)]
+pub fn bad_output(input: TokenStream) -> String {
+ //~^ ERROR mismatched derive proc macro signature
+ String::from("blah")
+}
+
+#[proc_macro_derive(Bluh)]
+pub fn bad_everything(input: String) -> String {
+ //~^ ERROR mismatched derive proc macro signature
+ //~| ERROR mismatched derive proc macro signature
+ input
+}
+
+#[proc_macro_derive(Blih)]
+pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ //~^ ERROR mismatched derive proc macro signature
+}
diff --git a/tests/ui/proc-macro/signature-proc-macro-derive.stderr b/tests/ui/proc-macro/signature-proc-macro-derive.stderr
new file mode 100644
index 000000000..a358ae277
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro-derive.stderr
@@ -0,0 +1,40 @@
+error: mismatched derive proc macro signature
+ --> $DIR/signature-proc-macro-derive.rs:10:25
+ |
+LL | pub fn bad_input(input: String) -> TokenStream {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature-proc-macro-derive.rs:16:42
+ |
+LL | pub fn bad_output(input: TokenStream) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature-proc-macro-derive.rs:22:41
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature-proc-macro-derive.rs:22:30
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature-proc-macro-derive.rs:29:33
+ |
+LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ found unexpected arguments
+
+error: aborting due to 5 previous errors
+
diff --git a/tests/ui/proc-macro/signature-proc-macro.rs b/tests/ui/proc-macro/signature-proc-macro.rs
new file mode 100644
index 000000000..54770aacd
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro.rs
@@ -0,0 +1,31 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn bad_input(input: String) -> TokenStream {
+ //~^ ERROR mismatched function-like proc macro signature
+ ::proc_macro::TokenStream::new()
+}
+
+#[proc_macro]
+pub fn bad_output(input: TokenStream) -> String {
+ //~^ ERROR mismatched function-like proc macro signature
+ String::from("blah")
+}
+
+#[proc_macro]
+pub fn bad_everything(input: String) -> String {
+ //~^ ERROR mismatched function-like proc macro signature
+ //~| ERROR mismatched function-like proc macro signature
+ input
+}
+
+#[proc_macro]
+pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ //~^ ERROR mismatched function-like proc macro signature
+}
diff --git a/tests/ui/proc-macro/signature-proc-macro.stderr b/tests/ui/proc-macro/signature-proc-macro.stderr
new file mode 100644
index 000000000..4b14a54e6
--- /dev/null
+++ b/tests/ui/proc-macro/signature-proc-macro.stderr
@@ -0,0 +1,40 @@
+error: mismatched function-like proc macro signature
+ --> $DIR/signature-proc-macro.rs:10:25
+ |
+LL | pub fn bad_input(input: String) -> TokenStream {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: function-like proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched function-like proc macro signature
+ --> $DIR/signature-proc-macro.rs:16:42
+ |
+LL | pub fn bad_output(input: TokenStream) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: function-like proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched function-like proc macro signature
+ --> $DIR/signature-proc-macro.rs:22:41
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: function-like proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched function-like proc macro signature
+ --> $DIR/signature-proc-macro.rs:22:30
+ |
+LL | pub fn bad_everything(input: String) -> String {
+ | ^^^^^^ found std::string::String, expected type `proc_macro::TokenStream`
+ |
+ = note: function-like proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched function-like proc macro signature
+ --> $DIR/signature-proc-macro.rs:29:33
+ |
+LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ found unexpected arguments
+
+error: aborting due to 5 previous errors
+
diff --git a/tests/ui/proc-macro/signature.rs b/tests/ui/proc-macro/signature.rs
index 230223825..11187aa31 100644
--- a/tests/ui/proc-macro/signature.rs
+++ b/tests/ui/proc-macro/signature.rs
@@ -8,6 +8,10 @@ extern crate proc_macro;
#[proc_macro_derive(A)]
pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
- //~^ ERROR: expected a `Fn<(proc_macro::TokenStream,)>` closure, found `unsafe extern "C" fn
+ //~^ ERROR: mismatched derive proc macro signature
+ //~| mismatched derive proc macro signature
+ //~| mismatched derive proc macro signature
+ //~| proc macro functions may not be `extern
+ //~| proc macro functions may not be `unsafe
loop {}
}
diff --git a/tests/ui/proc-macro/signature.stderr b/tests/ui/proc-macro/signature.stderr
index 79f2001da..3dbe3f22a 100644
--- a/tests/ui/proc-macro/signature.stderr
+++ b/tests/ui/proc-macro/signature.stderr
@@ -1,20 +1,36 @@
-error[E0277]: expected a `Fn<(proc_macro::TokenStream,)>` closure, found `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
+error: proc macro functions may not be `extern "C"`
--> $DIR/signature.rs:10:1
|
-LL | / pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
-LL | |
-LL | | loop {}
-LL | | }
- | | ^
- | | |
- | |_call the function in a closure: `|| unsafe { /* code */ }`
- | required by a bound introduced by this call
+LL | pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: proc macro functions may not be `unsafe`
+ --> $DIR/signature.rs:10:1
+ |
+LL | pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature.rs:10:49
+ |
+LL | pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
+ | ^^^ found u32, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature.rs:10:33
+ |
+LL | pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
+ | ^^^ found i32, expected type `proc_macro::TokenStream`
+ |
+ = note: derive proc macros must have a signature of `fn(TokenStream) -> TokenStream`
+
+error: mismatched derive proc macro signature
+ --> $DIR/signature.rs:10:38
|
- = help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for fn item `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
- = note: unsafe function cannot be called generically without an unsafe block
-note: required by a bound in `ProcMacro::custom_derive`
- --> $SRC_DIR/proc_macro/src/bridge/client.rs:LL:COL
+LL | pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
+ | ^^^^^^ found unexpected argument
-error: aborting due to previous error
+error: aborting due to 5 previous errors
-For more information about this error, try `rustc --explain E0277`.