Call clone explicitly to avoid deref recursion when cloning traits
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:28:18 +0000 (18:28 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:42:40 +0000 (18:42 +0000)
c-bindings-gen/src/blocks.rs

index fab69f6e922f8b71e33bd804401af29f4cc01f51..b214445584b6f6439413f8e5c7e277b5d4af6ad1 100644 (file)
@@ -200,7 +200,7 @@ pub fn write_result_block<W: std::io::Write>(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: std::io::Write>(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: std::io::Write>(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: std::io::Write>(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();
        }
 }