From 06cc796c85a4a317e55d315da9dd932d155f9f55 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 24 Sep 2021 18:28:18 +0000 Subject: [PATCH] Call clone explicitly to avoid deref recursion when cloning traits --- c-bindings-gen/src/blocks.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs index fab69f6..b214445 100644 --- a/c-bindings-gen/src/blocks.rs +++ b/c-bindings-gen/src/blocks.rs @@ -200,7 +200,7 @@ pub fn write_result_block(w: &mut W, mangled_container: &str, writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "/// Creates a new {} which has the same data as `orig`", mangled_container).unwrap(); writeln!(w, "/// but with all dynamically-allocated buffers duplicated in new buffers.").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap(); + writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ Clone::clone(&orig) }}", mangled_container, mangled_container, mangled_container).unwrap(); } } @@ -301,7 +301,7 @@ pub fn write_tuple_block(w: &mut W, mangled_container: &str, writeln!(w, "\tfn clone(&self) -> Self {{").unwrap(); writeln!(w, "\t\tSelf {{").unwrap(); for idx in 0..types.len() { - writeln!(w, "\t\t\t{}: self.{}.clone(),", ('a' as u8 + idx as u8) as char, ('a' as u8 + idx as u8) as char).unwrap(); + writeln!(w, "\t\t\t{}: Clone::clone(&self.{}),", ('a' as u8 + idx as u8) as char, ('a' as u8 + idx as u8) as char).unwrap(); } writeln!(w, "\t\t}}").unwrap(); writeln!(w, "\t}}").unwrap(); @@ -309,7 +309,7 @@ pub fn write_tuple_block(w: &mut W, mangled_container: &str, writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "/// Creates a new tuple which has the same data as `orig`").unwrap(); writeln!(w, "/// but with all dynamically-allocated buffers duplicated in new buffers.").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap(); + writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ Clone::clone(&orig) }}", mangled_container, mangled_container, mangled_container).unwrap(); } writeln!(w, "/// Creates a new {} from the contained elements.", mangled_container).unwrap(); @@ -376,7 +376,7 @@ pub fn write_option_block(w: &mut W, mangled_container: &str, writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "/// Creates a new {} which has the same data as `orig`", mangled_container).unwrap(); writeln!(w, "/// but with all dynamically-allocated buffers duplicated in new buffers.").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap(); + writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ Clone::clone(&orig) }}", mangled_container, mangled_container, mangled_container).unwrap(); } } -- 2.30.2