From 0d9c871736092fa804e1edf4e2d198cf2fe659df Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 23 Jul 2023 10:09:43 +0000 Subject: [PATCH] add proc macro test --- .../auxiliary/count.rs | 14 ++++++++++++++ .../rfc-3348-c-string-literals/edition-spans.rs | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/count.rs create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/edition-spans.rs diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/count.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/count.rs new file mode 100644 index 00000000000..0907061d64a --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/count.rs @@ -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() +} diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/edition-spans.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-spans.rs new file mode 100644 index 00000000000..b3557c71b74 --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-spans.rs @@ -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() {}