dtolnay / proc-macro-workshop

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

Why span in `compile_error!` error message include the ending `;` ? #43

Closed minhuw closed 2 years ago

minhuw commented 2 years ago

I use rustc 1.54.0 (a178d0322 2021-07-26), in seq/tests/03-expand-four-errors.rs, span in the expected error message doesn't include the ending ; as shown below.

error: error number 0
  --> tests/03-expand-four-errors.rs:20:5
   |
20 |     compile_error!(concat!("error number ", stringify!(N)));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

However, my solution gives an almost equal version except that the span ^ includes the ending ';'.

error: error number 0
  --> tests/03-expand-four-errors.rs:20:5
   |
20 |     compile_error!(concat!("error number ", stringify!(N)));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I try to add compile_error! explicitly, and the error message also includes the ending ;.

error: error number 0
  --> main.rs:13:5
   |
13 |     compile_error!(concat!("error number ", stringify!(0)));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I wonder whether it's just an compiler version issue or it's intended to be so and I should figure out how to control the span in error meesage generated by compile_error!?

dtolnay commented 2 years ago

According to bf98356081b52ad3d74f04584c0d9d205ad52c18 any compiler newer than 2021-10-17 would not be including the semicolon in the span.

minhuw commented 2 years ago

Thank you for your help, I update my rustc to 2021-11-29 and it gives expected error message.