From bfa95cd289574e37d95519114f9dd2e3d3983053 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 1 Mar 2021 17:06:25 -0500 Subject: [PATCH] [bindings] Avoid double-use'ing traits by writing out the path --- c-bindings-gen/src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 5b99cd681..f2f684fd6 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -808,10 +808,10 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ } } ) ); - write!(w, "\t}}\n}}\nuse {}::{} as {}TraitImport;\n", types.orig_crate, full_trait_path, trait_obj.ident).unwrap(); + writeln!(w, "\t}}\n}}\n").unwrap(); macro_rules! impl_meth { - ($m: expr, $trait: expr, $indent: expr) => { + ($m: expr, $trait_path: expr, $trait: expr, $indent: expr) => { let trait_method = $trait.items.iter().filter_map(|item| { if let syn::TraitItem::Method(t_m) = item { Some(t_m) } else { None } }).find(|trait_meth| trait_meth.sig.ident == $m.sig.ident).unwrap(); @@ -842,9 +842,9 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ t_gen_args += "_" } if takes_self { - write!(w, ">::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait.ident, t_gen_args, $m.sig.ident, ident).unwrap(); + write!(w, ">::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap(); } else { - write!(w, ">::{}(", ident, $trait.ident, t_gen_args, $m.sig.ident).unwrap(); + write!(w, ">::{}(", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident).unwrap(); } let mut real_type = "".to_string(); @@ -881,20 +881,19 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ for item in i.items.iter() { match item { syn::ImplItem::Method(m) => { - impl_meth!(m, trait_obj, ""); + impl_meth!(m, full_trait_path, trait_obj, ""); }, syn::ImplItem::Type(_) => {}, _ => unimplemented!(), } } walk_supertraits!(trait_obj, Some(&types), ( - (s, t) => { + (s, _) => { if let Some(supertrait_obj) = types.crate_types.traits.get(s).cloned() { - writeln!(w, "use {}::{} as native{}Trait;", types.orig_crate, s, t).unwrap(); for item in supertrait_obj.items.iter() { match item { syn::TraitItem::Method(m) => { - impl_meth!(m, supertrait_obj, "\t"); + impl_meth!(m, s, supertrait_obj, "\t"); }, _ => {}, } -- 2.39.5