set_span!() { /* proc-macro */ }Expand description
Set the span of certain tokens in the code block to the span of the input token
- grammar := span
,{code*} - span :=
#mixed/ any-token index* - index :=
[num-literal] - code :=
#set_span{…}
/#set_index_span{index*{…}}
/ any-token
{, } is general bracket, contain () [] {}
set_span!((a, b, (c))[0], {...})setaspanset_span!((a, b, (c))[1], {...})setbspanset_span!((a, b, (c))[2], {...})set(c)spanset_span!((a, b, (c))[2][0], {...})setcspan
Similarly, there is also
set_span!((a), {#set_index_span([0]{...})}) set a span
§Example
macro_rules! foo {
($t:tt) => {
foo! { ($t) ($t) }
};
($t:tt (0)) => {
set_span::set_span! {$t[0], {
#set_span {
compile_error! {"input by zero"}
}
}}
};
($_:tt ($lit:literal)) => { /*...*/ };
}
// foo!(0); // test error msg