Skip to content

Commit

Permalink
Migrate check-fail tests for proc_macro::quote! from quote crate
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jan 9, 2025
1 parent e9063c3 commit 2ab9db5
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/ui/proc-macro/quote/auxiliary/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn run_tests(_: TokenStream) -> TokenStream {
// - quote_spanned:
// - fn test_quote_spanned_impl
// - fn test_type_inference_for_span
// - wrong-type-span.rs
// - format_ident:
// - fn test_format_ident
// - fn test_format_ident_strip_raw
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter-interpolated-dup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// FIXME(quote): `proc_macro::quote!` doesn't support repetition at the moment, so the stderr is
// expected to be incorrect.
//@ known-bug: #54722

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

fn main() {
let nonrep = "";

// Without some protection against repetitions with no iterator somewhere
// inside, this would loop infinitely.
quote!($($nonrep $nonrep)*);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/does-not-have-iter-interpolated-dup.rs:16:5
|
LL | quote!($($nonrep $nonrep)*);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: `$` must be followed by an ident or `$` in `quote!`

error: aborting due to 1 previous error

17 changes: 17 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter-interpolated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// FIXME(quote): `proc_macro::quote!` doesn't support repetition at the moment, so the stderr is
// expected to be incorrect.
//@ known-bug: #54722

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

fn main() {
let nonrep = "";

// Without some protection against repetitions with no iterator somewhere
// inside, this would loop infinitely.
quote!($($nonrep)*);
}
10 changes: 10 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter-interpolated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/does-not-have-iter-interpolated.rs:16:5
|
LL | quote!($($nonrep)*);
| ^^^^^^^^^^^^^^^^^^^
|
= help: message: `$` must be followed by an ident or `$` in `quote!`

error: aborting due to 1 previous error

13 changes: 13 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter-separated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// FIXME(quote): `proc_macro::quote!` doesn't support repetition at the moment, so the stderr is
// expected to be incorrect.
//@ known-bug: #54722

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

fn main() {
quote!($(a b),*);
}
10 changes: 10 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter-separated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/does-not-have-iter-separated.rs:12:5
|
LL | quote!($(a b),*);
| ^^^^^^^^^^^^^^^^
|
= help: message: `$` must be followed by an ident or `$` in `quote!`

error: aborting due to 1 previous error

13 changes: 13 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// FIXME(quote): `proc_macro::quote!` doesn't support repetition at the moment, so the stderr is
// expected to be incorrect.
//@ known-bug: #54722

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

fn main() {
quote!($(a b)*);
}
10 changes: 10 additions & 0 deletions tests/ui/proc-macro/quote/does-not-have-iter.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/does-not-have-iter.rs:12:5
|
LL | quote!($(a b)*);
| ^^^^^^^^^^^^^^^
|
= help: message: `$` must be followed by an ident or `$` in `quote!`

error: aborting due to 1 previous error

12 changes: 12 additions & 0 deletions tests/ui/proc-macro/quote/not-quotable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;

use std::net::Ipv4Addr;

use proc_macro::quote;

fn main() {
let ip = Ipv4Addr::LOCALHOST;
let _ = quote! { $ip }; //~ ERROR the trait bound `Ipv4Addr: ToTokens` is not satisfied
}
24 changes: 24 additions & 0 deletions tests/ui/proc-macro/quote/not-quotable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error[E0277]: the trait bound `Ipv4Addr: ToTokens` is not satisfied
--> $DIR/not-quotable.rs:11:13
|
LL | let _ = quote! { $ip };
| ^^^^^^^^^^^^^^
| |
| the trait `ToTokens` is not implemented for `Ipv4Addr`
| required by a bound introduced by this call
|
= help: the following other types implement trait `ToTokens`:
&T
&mut T
Box<T>
CString
Cow<'_, T>
Option<T>
Rc<T>
bool
and 24 others
= note: this error originates in the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
16 changes: 16 additions & 0 deletions tests/ui/proc-macro/quote/not-repeatable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// FIXME(quote): `proc_macro::quote!` doesn't support repetition at the moment, so the stderr is
// expected to be incorrect.
//@ known-bug: #54722

#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::quote;

struct Ipv4Addr;

fn main() {
let ip = Ipv4Addr;
let _ = quote! { $($ip)* };
}
10 changes: 10 additions & 0 deletions tests/ui/proc-macro/quote/not-repeatable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/not-repeatable.rs:15:13
|
LL | let _ = quote! { $($ip)* };
| ^^^^^^^^^^^^^^^^^^
|
= help: message: `$` must be followed by an ident or `$` in `quote!`

error: aborting due to 1 previous error

0 comments on commit 2ab9db5

Please sign in to comment.