From cfcadcb2959d2dbaf7d95e8b9a33c48b75480e9f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 31 May 2021 17:32:56 +0200 Subject: Simplify proc_macro_srv tests --- crates/proc_macro_test/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'crates/proc_macro_test/src') diff --git a/crates/proc_macro_test/src/lib.rs b/crates/proc_macro_test/src/lib.rs index ec2a114a3..4b26d2472 100644 --- a/crates/proc_macro_test/src/lib.rs +++ b/crates/proc_macro_test/src/lib.rs @@ -3,16 +3,46 @@ use proc_macro::TokenStream; #[proc_macro] -pub fn function_like_macro(args: TokenStream) -> TokenStream { +pub fn fn_like_noop(args: TokenStream) -> TokenStream { args } +#[proc_macro] +pub fn fn_like_panic(args: TokenStream) -> TokenStream { + panic!("fn_like_panic!({})", args); +} + +#[proc_macro] +pub fn fn_like_error(args: TokenStream) -> TokenStream { + format!("compile_error!(\"fn_like_error!({})\");", args).parse().unwrap() +} + #[proc_macro_attribute] -pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream { +pub fn attr_noop(_args: TokenStream, item: TokenStream) -> TokenStream { item } -#[proc_macro_derive(DummyTrait)] -pub fn derive_macro(_item: TokenStream) -> TokenStream { +#[proc_macro_attribute] +pub fn attr_panic(args: TokenStream, item: TokenStream) -> TokenStream { + panic!("#[attr_panic {}] {}", args, item); +} + +#[proc_macro_attribute] +pub fn attr_error(args: TokenStream, item: TokenStream) -> TokenStream { + format!("compile_error!(\"#[attr_error({})] {}\");", args, item).parse().unwrap() +} + +#[proc_macro_derive(DeriveEmpty)] +pub fn derive_empty(_item: TokenStream) -> TokenStream { TokenStream::new() } + +#[proc_macro_derive(DerivePanic)] +pub fn derive_panic(item: TokenStream) -> TokenStream { + panic!("#[derive(DerivePanic)] {}", item); +} + +#[proc_macro_derive(DeriveError)] +pub fn derive_error(item: TokenStream) -> TokenStream { + format!("compile_error!(\"#[derive(DeriveError)] {}\");", item).parse().unwrap() +} -- cgit v1.2.3