Last active
September 25, 2020 16:38
-
-
Save raphlinus/6127e08691cb1147d42efac6ac898b06 to your computer and use it in GitHub Desktop.
Test of whether attribute macros can emit attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate proc_macro; | |
use proc_macro::TokenStream; | |
#[proc_macro_attribute] | |
pub fn widget(attr: TokenStream, item: TokenStream) -> TokenStream { | |
r#" | |
#[track_caller] | |
fn answer() -> u32 { | |
println!("{:?}", std::panic::Location::caller()); | |
42 | |
}"#.parse().unwrap() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate attrib_derive; | |
use attrib_derive::widget; | |
#[widget] | |
fn answer() { | |
// Body isn't actually parsed. | |
} | |
fn main() { | |
println!("{}", answer()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment