+ let mut params = syn::punctuated::Punctuated::new();
+ let alias = string_path_to_syn_path(&alias_resolved);
+ let real_aliased =
+ if need_generics {
+ let alias_generics = types.crate_types.opaques.get(&alias_resolved).unwrap().1;
+
+ // If we need generics on the alias, create impl generic bounds...
+ assert_eq!(new_ty_generics.len() + new_ty_bounds.len(), i.generics.params.len());
+ let mut args = syn::punctuated::Punctuated::new();
+ for (ident, param) in new_ty_generics.drain(..) {
+ // TODO: We blindly assume that generics in the type alias and
+ // the aliased type have the same names, which we really shouldn't.
+ if alias_generics.params.iter().any(|generic|
+ if let syn::GenericParam::Type(t) = generic { t.ident == ident } else { false })
+ {
+ args.push(parse_quote!(#ident));
+ }
+ params.push(syn::GenericParam::Type(syn::TypeParam {
+ attrs: Vec::new(),
+ ident,
+ colon_token: None,
+ bounds: syn::punctuated::Punctuated::new(),
+ eq_token: Some(syn::token::Eq(Span::call_site())),
+ default: Some(param),
+ }));
+ }
+ for (ident, param) in new_ty_bounds.drain(..) {
+ // TODO: We blindly assume that generics in the type alias and
+ // the aliased type have the same names, which we really shouldn't.
+ if alias_generics.params.iter().any(|generic|
+ if let syn::GenericParam::Type(t) = generic { t.ident == ident } else { false })
+ {
+ args.push(parse_quote!(#ident));
+ }
+ params.push(syn::GenericParam::Type(syn::TypeParam {
+ attrs: Vec::new(),
+ ident,
+ colon_token: Some(syn::token::Colon(Span::call_site())),
+ bounds: syn::punctuated::Punctuated::from_iter(
+ Some(syn::TypeParamBound::Trait(syn::TraitBound {
+ path: param, paren_token: None, lifetimes: None,
+ modifier: syn::TraitBoundModifier::None,
+ }))
+ ),
+ eq_token: None,
+ default: None,
+ }));
+ }
+ // ... and swap the last segment of the impl self_ty to use the generic bounds.
+ let mut res = alias.clone();
+ res.segments.last_mut().unwrap().arguments = syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
+ colon2_token: None,
+ lt_token: syn::token::Lt(Span::call_site()),
+ args,
+ gt_token: syn::token::Gt(Span::call_site()),
+ });
+ res
+ } else { alias.clone() };