Ensure an option always unwraps to a non-reference type
authorMatt Corallo <git@bluematt.me>
Tue, 25 Apr 2023 22:13:38 +0000 (22:13 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Apr 2023 00:08:07 +0000 (00:08 +0000)
c-bindings-gen/src/types.rs

index 8cc7d1eaa501f3bfcf16d80ae15a655999a631ab..f47bf9ed146397cfe80ec0e67fe8c83fb4140a4b 100644 (file)
@@ -1624,7 +1624,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                                        let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap();
                                                        return Some(("if ", vec![
                                                                (format!(".is_none() {{ {}::None }} else {{ {}::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */", inner_name, inner_name),
-                                                                format!("{}.clone().unwrap()", var_access))
+                                                                format!("(*{}.as_ref().unwrap()).clone()", var_access))
                                                                ], ") }", ContainerPrefixLocation::PerConv));
                                                }
                                        } else {