| Crates.io | set-span |
| lib.rs | set-span |
| version | 0.1.4 |
| created_at | 2025-05-07 00:57:12.2477+00 |
| updated_at | 2025-05-19 10:31:54.78699+00 |
| description | Like proc-macro, set some tokens span |
| homepage | |
| repository | https://github.com/A4-Tacks/set-span-rs |
| max_upload_size | |
| id | 1663236 |
| size | 11,526 |
The set_span in the simulation process macro
This macro can be used to improve error messages, etc
Incorrect use may cause some damage to hygiene
macro_rules! foo {
($t:tt) => {
foo! { ($t) ($t) }
};
($t:tt (0)) => {
set_span::set_span_all! {$t[0], {
compile_error! {"input by zero"}
}}
};
($_:tt ($lit:literal)) => { /*...*/ };
}
foo!(0);
Output:
error: input by zero
--> src/lib.rs:25:6
|
16 | foo!(0);
| ^
set_span is not used:macro_rules! foo {
($t:tt) => {
foo! { ($t) ($t) }
};
($t:tt (0)) => {
compile_error! {"input by zero"}
};
($_:tt ($lit:literal)) => { /*...*/ };
}
foo!(0);
Output:
error: input by zero
--> src/lib.rs:45:9
|
8 | compile_error! {"input by zero"}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
12 | foo!(0);
| ------- in this macro invocation
|