mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 20:43:03 +00:00
4cfdbd328b
This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec<u32> = vec![];) ``` goes from this: ``` let a: Vec<u32> = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![]; ```
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
// force-host
|
|
// no-prefer-dynamic
|
|
|
|
#![crate_type = "proc-macro"]
|
|
|
|
extern crate proc_macro;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
|
|
item
|
|
}
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert_eq!(item.to_string(), "println!(\"{}\", string);");
|
|
item
|
|
}
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert_eq!(item.to_string(), "print_str(\"string\")");
|
|
item
|
|
}
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert_eq!(item.to_string(), "println!(\"{}\", string)");
|
|
item
|
|
}
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn no_output(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert!(!item.to_string().is_empty());
|
|
"".parse().unwrap()
|
|
}
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn noop(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
assert!(attr.to_string().is_empty());
|
|
assert!(!item.to_string().is_empty());
|
|
item
|
|
}
|