Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use crate::proc_macro::Span;
use proc_macro2::TokenStream as TokenStream2;
use quote::{ToTokens, TokenStreamExt};
use syn::{
FnArg, Ident, ItemTrait, Lifetime, MethodSig, Pat, PatIdent, TraitItem, TraitItemMethod,
TraitItemType, TraitItemConst,
FnArg, Ident, ItemTrait, Lifetime, MethodSig, Pat, PatIdent, TraitItem, TraitItemConst,
TraitItemMethod, TraitItemType,
};

use crate::{
analyze::find_suitable_param_names,
attr::{OurAttr, is_our_attr, parse_our_attr},
attr::{is_our_attr, parse_our_attr, OurAttr},
diag::{DiagnosticExt, SpanExt},
proxy::ProxyType,
spanned::Spanned
spanned::Spanned,
};


Expand Down Expand Up @@ -430,6 +430,10 @@ fn gen_method_item(
// Generate the list of argument used to call the method.
let args = get_arg_list(sig.decl.inputs.iter())?;

// Builds turbofish with generic types
let (_, generic_types, _) = sig.decl.generics.split_for_impl();
let generic_types = generic_types.as_turbofish();

// Generate the body of the function. This mainly depends on the self type,
// but also on the proxy type.
let name = &sig.ident;
Expand All @@ -442,20 +446,20 @@ fn gen_method_item(
// No receiver
SelfType::None => {
// The proxy type is a reference, smartpointer or Box.
quote! { #proxy_ty_param::#name(#args) }
quote! { #proxy_ty_param::#name #generic_types(#args) }
}

// Receiver `self` (by value)
SelfType::Value => {
// The proxy type is a Box.
quote! { (*self).#name(#args) }
quote! { (*self).#name#generic_types(#args) }
}

// `&self` or `&mut self` receiver
SelfType::Ref | SelfType::Mut => {
// The proxy type could be anything in the `Ref` case, and `&mut`
// or Box in the `Mut` case.
quote! { (**self).#name(#args) }
quote! { (*self).#name#generic_types(#args) }
}
};

Expand Down
7 changes: 7 additions & 0 deletions tests/compile-pass/non_inferred_generic_types_for_all_refs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use auto_impl::auto_impl;

#[auto_impl(&)]
trait Foo {
fn foo<T>();
fn bar<U>(&self);
}
9 changes: 9 additions & 0 deletions tests/compile-pass/non_inferred_generic_types_for_box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use auto_impl::auto_impl;

#[auto_impl(Box)]
trait Foo {
fn foo<T>();
fn bar<U>(&self);
fn baz<V>(&mut self);
fn qux<W>(self);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use auto_impl::auto_impl;

#[auto_impl(&)]
trait Foo {
fn foo<T>();
fn bar<U>(&self);
fn baz<'a, U>() -> &'a str;
fn qux<'a, 'b, 'c, U, V, T>(&self) -> (&'a str, &'b str, &'c str);
}