Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotmelon committed Aug 18, 2024
1 parent 1577251 commit 833d020
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
38 changes: 22 additions & 16 deletions rivets-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use lazy_regex::regex;
use proc_macro::{self, Diagnostic, Level, Span, TokenStream};
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::{parse_macro_input, Abi, DeriveInput, Error, Expr, FnArg, Ident, ItemFn, Variant};
use std::sync::{atomic::AtomicBool, LazyLock, Mutex};
use syn::{parse_macro_input, Abi, DeriveInput, Error, Expr, FnArg, Ident, ItemFn, Variant};

static IS_FINALIZED: AtomicBool = AtomicBool::new(false);
static MANGLED_NAMES: LazyLock<Mutex<Vec<(String, String)>>> = LazyLock::new(|| Mutex::new(vec![]));
Expand Down Expand Up @@ -166,7 +166,10 @@ pub fn detour(attr: TokenStream, item: TokenStream) -> TokenStream {
}
};

MANGLED_NAMES.lock().expect("Failed to lock mangled names").push((mangled_name.clone(), name.to_string()));
MANGLED_NAMES
.lock()
.expect("Failed to lock mangled names")
.push((mangled_name.clone(), name.to_string()));

Diagnostic::spanned(Span::call_site(), Level::Note, unmangled_name.clone()).emit();

Expand Down Expand Up @@ -223,16 +226,14 @@ pub fn summon(attr: TokenStream, item: TokenStream) -> TokenStream {
Ok(calling_convention) => Some(calling_convention),
Err(e) => return failure(quote! { #input }, &e.to_string()),
};

let arg_types = input.sig.inputs.iter().map(|arg| {
match arg {
FnArg::Receiver(_) => {
quote! {compile_error!("Summoned functions cannot use the self parameter.")}
}
FnArg::Typed(pat) => {
let ty = &pat.ty;
quote! { #ty }
}

let arg_types = input.sig.inputs.iter().map(|arg| match arg {
FnArg::Receiver(_) => {
quote! {compile_error!("Summoned functions cannot use the self parameter.")}
}
FnArg::Typed(pat) => {
let ty = &pat.ty;
quote! { #ty }
}
});

Expand All @@ -242,10 +243,13 @@ pub fn summon(attr: TokenStream, item: TokenStream) -> TokenStream {
let attr = quote! { #(#attr)* };

let name = &input.sig.ident;
let function_type = quote! { #attr #vis unsafe #calling_convention fn(#(#arg_types),*) #return_type };
let function_type =
quote! { #attr #vis unsafe #calling_convention fn(#(#arg_types),*) #return_type };

CPP_IMPORTS.lock().expect("Failed to lock cpp imports"
).push((mangled_name.clone(), name.to_string()));
CPP_IMPORTS
.lock()
.expect("Failed to lock cpp imports")
.push((mangled_name.clone(), name.to_string()));

Diagnostic::spanned(Span::call_site(), Level::Note, unmangled_name.clone()).emit();

Expand All @@ -256,7 +260,9 @@ pub fn summon(attr: TokenStream, item: TokenStream) -> TokenStream {
}

fn get_hooks() -> Vec<proc_macro2::TokenStream> {
MANGLED_NAMES.lock().expect("Failed to lock mangled names")
MANGLED_NAMES
.lock()
.expect("Failed to lock mangled names")
.iter()
.map(|(mangled_name, module_name)| {
let module_name = Ident::new(module_name, proc_macro2::Span::call_site());
Expand Down
5 changes: 3 additions & 2 deletions rivets-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl SymbolCache {
/// Invariant: If the function is not initialized, it is UB to dereference it.
/// The rivets::finalize!() macro should be used to ensure that the function is initialized.
pub enum UnsafeSummonedFunction<T>
where T: 'static + Sized
where
T: 'static + Sized,
{
Function(T),
Uninitialized,
Expand All @@ -177,4 +178,4 @@ impl<T> Deref for UnsafeSummonedFunction<T> {
Self::Uninitialized => unsafe { std::hint::unreachable_unchecked() },
}
}
}
}

0 comments on commit 833d020

Please sign in to comment.