dtolnay / proc-macro-workshop

Learn to write Rust procedural macros  [Rust Latam conference, Montevideo Uruguay, March 2019]
Apache License 2.0
4k stars 1.01k forks source link

seq test case 03 fail #73

Closed apodemakeles closed 2 months ago

apodemakeles commented 2 months ago

Hi, my code failed when executing seq test case 03, the output is:

ACTUAL OUTPUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: error number 0
  --> tests/03-expand-four-errors.rs:19:1
   |
19 | / seq!(N in 0..4 {
20 | |     compile_error!(concat!("error number ", stringify!(N)));
21 | | });
   | |__^
   |
   = note: this error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: error number 1
  --> tests/03-expand-four-errors.rs:19:1
   |
19 | / seq!(N in 0..4 {
20 | |     compile_error!(concat!("error number ", stringify!(N)));
21 | | });
   | |__^
   |
   = note: this error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: error number 2
  --> tests/03-expand-four-errors.rs:19:1
   |
19 | / seq!(N in 0..4 {
20 | |     compile_error!(concat!("error number ", stringify!(N)));
21 | | });
   | |__^
   |
   = note: this error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: error number 3
  --> tests/03-expand-four-errors.rs:19:1
   |
19 | / seq!(N in 0..4 {
20 | |     compile_error!(concat!("error number ", stringify!(N)));
21 | | });
   | |__^
   |
   = note: this error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)

I even tried to print the result TokenStream before returning and it looks totally correct (begin with "compile_error" as ident). Download someone else's code from github and test, same output...

rust version: 1.75.0

dependencies:

proc-macro2 = "1.0.81" syn = { version = "2.0.59", features = ["full", "extra-traits"] } quote = "1.0.36" prettyplease = "0.2.1"

repository: https://github.com/apodemakeles/proc-macro-workshop/blob/seq/seq/src/lib.rs

dtolnay commented 2 months ago

This passes in the reference implementation, so it is definitely possible to implement as shown.

If you take this question to any of the resources shown in https://www.rust-lang.org/community, plenty of people have experience writing macros and should be able to help you sort it out.