mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
run-pass/attr-stmt-expr: expand test cases
This commit is contained in:
parent
7c0124dd35
commit
58217edd2f
@ -14,7 +14,8 @@
|
|||||||
#![feature(proc_macro, stmt_expr_attributes)]
|
#![feature(proc_macro, stmt_expr_attributes)]
|
||||||
|
|
||||||
extern crate attr_stmt_expr;
|
extern crate attr_stmt_expr;
|
||||||
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
|
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr,
|
||||||
|
no_output, noop};
|
||||||
|
|
||||||
fn print_str(string: &'static str) {
|
fn print_str(string: &'static str) {
|
||||||
// macros are handled a bit differently
|
// macros are handled a bit differently
|
||||||
@ -29,6 +30,17 @@ fn main() {
|
|||||||
#[expect_print_stmt]
|
#[expect_print_stmt]
|
||||||
println!("{}", string);
|
println!("{}", string);
|
||||||
|
|
||||||
|
let _: () = {
|
||||||
|
#[no_output]
|
||||||
|
"Hello, world!"
|
||||||
|
};
|
||||||
|
|
||||||
|
let _: &'static str = #[noop] "Hello, world!";
|
||||||
|
|
||||||
|
let _: &'static str = {
|
||||||
|
#[noop] "Hello, world!"
|
||||||
|
};
|
||||||
|
|
||||||
#[expect_expr]
|
#[expect_expr]
|
||||||
print_str("string")
|
print_str("string")
|
||||||
}
|
}
|
||||||
|
@ -44,3 +44,18 @@ pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
assert_eq!(item.to_string(), "println!(\"{}\" , string)");
|
assert_eq!(item.to_string(), "println!(\"{}\" , string)");
|
||||||
item
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user