Skip to content

Commit 4e0d15e

Browse files
committed
Extract self.output check to remove the need for 2 wrap_self functions
1 parent 72938e3 commit 4e0d15e

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

faux_macros/src/methods/morphed.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ impl<'a> Signature<'a> {
180180
if self.is_async {
181181
proxy_real.extend(quote! { .await })
182182
}
183-
if let Some(wrapped_self) = self.wrap_self(morphed_ty, real_self, &proxy_real)? {
184-
proxy_real = wrapped_self;
183+
184+
if let Some(output) = self.output {
185+
if let Some(wrapped_self) = Self::wrap_self(output, morphed_ty, real_self, &proxy_real)? {
186+
proxy_real = wrapped_self;
187+
}
185188
}
186189

187190
let ret = match &self.method_data {
@@ -255,21 +258,6 @@ impl<'a> Signature<'a> {
255258
}
256259

257260
fn wrap_self(
258-
&self,
259-
morphed_ty: &syn::TypePath,
260-
real_self: SelfType,
261-
block: &TokenStream,
262-
) -> darling::Result<Option<TokenStream>> {
263-
// TODO: use let-else once we bump MSRV to 1.65.0
264-
let output = match self.output {
265-
Some(output) => output,
266-
None => return Ok(None),
267-
};
268-
269-
Self::wrap_self_specific(output, morphed_ty, real_self, block)
270-
}
271-
272-
fn wrap_self_specific(
273261
ty: &Type,
274262
morphed_ty: &syn::TypePath,
275263
real_self: SelfType,
@@ -368,7 +356,7 @@ impl<'a> Signature<'a> {
368356
let ty = e.1;
369357

370358
let tuple_index = quote! { tuple.#index };
371-
let wrapped = Self::wrap_self_specific(ty, morphed_ty, real_self, &tuple_index)?;
359+
let wrapped = Self::wrap_self(ty, morphed_ty, real_self, &tuple_index)?;
372360

373361
Ok(wrapped.unwrap_or(tuple_index))
374362
})

0 commit comments

Comments
 (0)