Procedural Macro Utilities (tt_ident
, throw_diagnostics
, deref_span
).
// Experimental API
Manipulation of input names in macros, currently only name comparison is possible.
```rust
use macrottutils::ttident; use macrottutils::throwcompilewarning; use macrottutils::throwcompile_error;
macrorules! macrosgenerate { ( fn namechecker($i:ident) -> | $i2:ident | $b:block ) => { throwcompilewarning!(@root "We are testing warning."); ttident! { if ($i == $i2 || $i == "hiddena" || $i2 == "hiddena") { throwcompileerror!(@root "Perhaps undefined behavior"); } } } }
fn main() { macrosgenerate! { fn namechecker(a) -> |a| { ff } } }
/* warning: We are testing warning. --> src/main.rs:21:2 | 21 | macrosgenerate! { | ^ 22 | | fn namechecker(a) -> |a| { 23 | | ff 24 | | } 25 | | } | |^
error: Perhaps undefined behavior --> src/main.rs:21:2 | 21 | macrosgenerate! { | ^ 22 | | fn namechecker(a) -> |a| { 23 | | ff 24 | | } 25 | | } | |^ */ ```
Macros to throw compiler errors or warnings (throw_compile_error
, throw_compile_warning
, throw_compile_note
, throw_compile_help
).
```rust
use macrottutils::throwcompilewarning;
macrorules! macrosgenerate { { fn namechecker($i:ident) -> | $i2:ident | $b:block } => { throwcompilewarning!("#1 We are testing warning."); throwcompile_warning!(@root "#2 We are testing warning."); } }
fn main() { macrosgenerate! { fn namechecker(a) -> |a| {} } }
/* warning: #1 We are testing warning. --> src/main.rs:8:3 | 8 | throwcompilewarning!("#1 We are testing warning."); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 14 | macrosgenerate! { | - 15 | | fn namechecker(a) -> |a| {} 16 | | } | |- in this macro invocation
warning: #2 We are testing warning. --> src/main.rs:14:2 | 14 | macrosgenerate! { | ^ 15 | | fn namechecker(a) -> |a| {} 16 | | } | |^
*/ ```
Unpacks the current span.
```rust
use macrottutils::deref_span;
macrorules! macrosgenerate { { fn namechecker($i:ident) -> | $i2:ident | $b:block } => { compileerror!("#1 Test");
deref_span! {
compile_error!("#2 Test");
}
}
}
fn main() { macrosgenerate! { fn namechecker(a) -> |a| {} } }
/* error: #1 Test --> src/main.rs:8:3 | 8 | compileerror!("#1 Test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 17 | macrosgenerate! { | - 18 | | fn namechecker(a) -> |a| {} 19 | | } | |_- in this macro invocation
error: #2 Test --> src/main.rs:17:2 | 17 | macrosgenerate! { | ^ 18 | | fn namechecker(a) -> |a| {} 19 | | } | |^
error: aborting due to 2 previous errors */ ```
Copyright 2019 #UlinProject (Denis Kotlyarov) Денис Котляров
Licensed under the MIT License
Licensed under the Apache License, Version 2.0