Don't generate trait `impl`s for pointers.
Without `#pragma clang lifetime_elision` we won't infer Rust lifetime of
`this` and will attempt to represent it as a Rust pointer (rather than
as a Rust reference). We should not generate trait `impl`s for such
pointers. One major reason is that pointers are considered foreign
and violate Rust's orphan rule.
PiperOrigin-RevId: 471862340
diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs
index f96b863..6021221 100644
--- a/rs_bindings_from_cc/src_code_gen.rs
+++ b/rs_bindings_from_cc/src_code_gen.rs
@@ -687,23 +687,19 @@
..
}) => {
materialize_ctor_in_caller(func, param_types);
- let (record, impl_for) = if let Some(record) = maybe_record {
- (&**record, ImplFor::RefT)
- } else {
- match ¶m_types[0] {
- RsTypeKind::Record { record, .. } => (&**record, ImplFor::T),
- RsTypeKind::Reference { referent, .. } => (
- match &**referent {
- RsTypeKind::Record { record, .. } => &**record,
- _ => bail!("Expected first parameter referent to be a record"),
- },
- ImplFor::RefT,
- ),
- RsTypeKind::RvalueReference { .. } => {
- bail!("Not yet supported for rvalue references (b/219826128)")
- }
- _ => bail!("Expected first parameter to be a record or reference"),
+ let (record, impl_for) = match ¶m_types[0] {
+ RsTypeKind::Record { record, .. } => (&**record, ImplFor::T),
+ RsTypeKind::Reference { referent, .. } => (
+ match &**referent {
+ RsTypeKind::Record { record, .. } => &**record,
+ _ => bail!("Expected first parameter referent to be a record"),
+ },
+ ImplFor::RefT,
+ ),
+ RsTypeKind::RvalueReference { .. } => {
+ bail!("Not yet supported for rvalue references (b/219826128)")
}
+ _ => bail!("Expected first parameter to be a record or reference"),
};
let trait_name = make_rs_ident(trait_name);