Skip to content

Commit

Permalink
chore(cheatcodes): reduce generated code (foundry-rs#8912)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored and rplusq committed Sep 25, 2024
1 parent 8d3e50e commit 2068f65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
7 changes: 2 additions & 5 deletions crates/macros/src/cheatcodes.rs
Original file line number Diff line number Diff line change
@@ -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<TokenStream> {
Expand Down Expand Up @@ -42,13 +42,10 @@ fn derive_call(name: &Ident, data: &DataStruct, attrs: &[Attribute]) -> Result<T
let safety = if let Some(safety) = safety {
quote!(Safety::#safety)
} else {
let panic = quote_spanned! {name.span()=>
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(),
}
}
};
Expand Down

0 comments on commit 2068f65

Please # to comment.