Skip to content

Commit 7a5fa56

Browse files
committed
[bindings] Be explicit with take_ptr calls
If you try to call take_ptr on a pointer to an object which implements Deref, rustc hits the deref recursion limit. To avoid this, we can explicitly tell rustc that we want to treat the pointer as a pointer and call take_ptr on it directly.
1 parent 87df96b commit 7a5fa56

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

c-bindings-gen/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
786786
match full_path {
787787
"Result" if !is_ref => {
788788
Some(("match ",
789-
vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw({}.contents.result.take_ptr()) }})", var_name)),
790-
("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw({}.contents.err.take_ptr()) }})", var_name))],
789+
vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.result)) }})", var_name)),
790+
("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.err)) }})", var_name))],
791791
")}"))
792792
},
793793
"Vec"|"Slice" if !is_ref => {

0 commit comments

Comments
 (0)