add proc macro test

This commit is contained in:
Deadbeef 2023-07-23 10:09:43 +00:00
parent df9bd80d74
commit 0d9c871736
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// force-host
// edition: 2018
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::TokenStream;
use std::str::FromStr;
#[proc_macro]
pub fn number_of_tokens(_: TokenStream) -> TokenStream {
TokenStream::from_str("c\"\"").unwrap().into_iter().count().to_string().parse().unwrap()
}

View File

@ -0,0 +1,16 @@
// even if this crate is edition 2021, proc macros compiled using older
// editions should still be able to observe the pre-2021 token behavior
//
// adapted from tests/ui/rust-2021/reserved-prefixes-via-macro.rs
// edition: 2021
// check-pass
// aux-build: count.rs
extern crate count;
const _: () = {
assert!(count::number_of_tokens!() == 2);
};
fn main() {}