From 2068f6543a76156d3b8c0f8cf00df7100c294419 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:58:13 +0200 Subject: [PATCH] chore(cheatcodes): reduce generated code (#8912) --- crates/cheatcodes/spec/src/vm.rs | 5 +++++ crates/macros/src/cheatcodes.rs | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index 9c19196c82095..9be2e5f6f2b9a 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -2365,3 +2365,8 @@ impl PartialEq for ForgeContext { } } } + +#[track_caller] +const fn panic_unknown_safety() -> ! { + panic!("cannot determine safety from the group, add a `#[cheatcode(safety = ...)]` attribute") +} diff --git a/crates/macros/src/cheatcodes.rs b/crates/macros/src/cheatcodes.rs index b38186e57732d..4fbe6cfa79cde 100644 --- a/crates/macros/src/cheatcodes.rs +++ b/crates/macros/src/cheatcodes.rs @@ -1,5 +1,5 @@ use proc_macro2::{Ident, Span, TokenStream}; -use quote::{quote, quote_spanned}; +use quote::quote; use syn::{Attribute, Data, DataStruct, DeriveInput, Error, Result}; pub fn derive_cheatcode(input: &DeriveInput) -> Result { @@ -42,13 +42,10 @@ fn derive_call(name: &Ident, data: &DataStruct, attrs: &[Attribute]) -> Result - panic!("cannot determine safety from the group, add a `#[cheatcode(safety = ...)]` attribute") - }; quote! { match Group::#group.safety() { Some(s) => s, - None => #panic, + None => panic_unknown_safety(), } } };