self_ty: Option<(String, &'a syn::Path)>,
parent: Option<&'b GenericTypes<'b, 'b>>,
typed_generics: HashMap<&'a syn::Ident, (String, Option<&'a syn::Path>)>,
- default_generics: HashMap<&'a syn::Ident, (&'a syn::Type, syn::Type)>,
+ default_generics: HashMap<&'a syn::Ident, (syn::Type, syn::Type)>,
}
impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
pub fn new(self_ty: Option<(String, &'a syn::Path)>) -> Self {
match generic {
syn::GenericParam::Type(type_param) => {
let mut non_lifetimes_processed = false;
- for bound in type_param.bounds.iter() {
+ 'bound_loop: for bound in type_param.bounds.iter() {
if let syn::TypeParamBound::Trait(trait_bound) = bound {
if let Some(ident) = single_ident_generic_path_to_ident(&trait_bound.path) {
match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, _ => {} }
let new_ident = if path != "std::ops::Deref" && path != "core::ops::Deref" {
path = "crate::".to_string() + &path;
Some(&trait_bound.path)
+ } else if trait_bound.path.segments.len() == 1 {
+ // If we're templated on Deref<Target = ConcreteThing>, store
+ // the reference type in `default_generics` which handles full
+ // types and not just paths.
+ if let syn::PathArguments::AngleBracketed(ref args) =
+ trait_bound.path.segments[0].arguments {
+ for subargument in args.args.iter() {
+ match subargument {
+ syn::GenericArgument::Lifetime(_) => {},
+ syn::GenericArgument::Binding(ref b) => {
+ if &format!("{}", b.ident) != "Target" { return false; }
+ let default = &b.ty;
+ self.default_generics.insert(&type_param.ident, (parse_quote!(&#default), parse_quote!(&#default)));
+ break 'bound_loop;
+ },
+ _ => unimplemented!(),
+ }
+ }
+ None
+ } else { None }
} else { None };
self.typed_generics.insert(&type_param.ident, (path, new_ident));
} else { return false; }
}
if let Some(default) = type_param.default.as_ref() {
assert!(type_param.bounds.is_empty());
- self.default_generics.insert(&type_param.ident, (default, parse_quote!(&#default)));
+ self.default_generics.insert(&type_param.ident, (default.clone(), parse_quote!(&#default)));
}
},
_ => {},