(Correctly) implement upcasting to a base class from another library.
PiperOrigin-RevId: 446690705
diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs
index ae7f3d9..7610ba8 100644
--- a/rs_bindings_from_cc/src_code_gen.rs
+++ b/rs_bindings_from_cc/src_code_gen.rs
@@ -2138,7 +2138,6 @@
/// Returns the implementation of base class conversions, for converting a type
/// to its unambiguous public base classes.
-// TODO(b/216195042): Correctly handle imported records.
fn cc_struct_upcast_impl(record: &Record, ir: &IR) -> Result<GeneratedItem> {
let mut impls = Vec::with_capacity(record.unambiguous_public_bases.len());
let mut thunks = vec![];
@@ -2147,7 +2146,7 @@
let base_record: &Record = ir
.find_decl(base.base_record_id)
.with_context(|| format!("Can't find a base record of {:?}", record))?;
- let base_name = make_rs_ident(&base_record.rs_name);
+ let base_name = RsTypeKind::new_record(base_record, ir).into_token_stream();
let derived_name = make_rs_ident(&record.rs_name);
let body;
if let Some(offset) = base.offset {
diff --git a/rs_bindings_from_cc/test/golden/BUILD b/rs_bindings_from_cc/test/golden/BUILD
index 8925d9b..feebe4a 100644
--- a/rs_bindings_from_cc/test/golden/BUILD
+++ b/rs_bindings_from_cc/test/golden/BUILD
@@ -66,7 +66,6 @@
"namespace",
"polymorphic",
"types",
- "user_of_base_class",
]]
# Only there so build-cleaner doesn't try to add separate targets for generated files.
diff --git a/rs_bindings_from_cc/test/golden/user_of_base_class_rs_api.rs b/rs_bindings_from_cc/test/golden/user_of_base_class_rs_api.rs
index 7272bd8..79f3510 100644
--- a/rs_bindings_from_cc/test/golden/user_of_base_class_rs_api.rs
+++ b/rs_bindings_from_cc/test/golden/user_of_base_class_rs_api.rs
@@ -50,19 +50,19 @@
// Error while generating bindings for item 'Derived2::operator=':
// Parameter #0 is not supported: Unsupported type 'struct Derived2 &&': Unsupported type: && without lifetime
-unsafe impl oops::Inherits<Base0> for Derived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const Base0 {
+unsafe impl oops::Inherits<inheritance_cc::Base0> for Derived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::Base0 {
detail::__crubit_dynamic_upcast__Derived2__to__Base0(derived)
}
}
-unsafe impl oops::Inherits<Base1> for Derived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const Base1 {
- (derived as *const _ as *const u8).offset(8) as *const Base1
+unsafe impl oops::Inherits<inheritance_cc::Base1> for Derived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::Base1 {
+ (derived as *const _ as *const u8).offset(8) as *const inheritance_cc::Base1
}
}
-unsafe impl oops::Inherits<Base2> for Derived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const Base2 {
- (derived as *const _ as *const u8).offset(18) as *const Base2
+unsafe impl oops::Inherits<inheritance_cc::Base2> for Derived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::Base2 {
+ (derived as *const _ as *const u8).offset(18) as *const inheritance_cc::Base2
}
}
@@ -94,18 +94,18 @@
// Error while generating bindings for item 'VirtualDerived2::operator=':
// Parameter #0 is not supported: Unsupported type 'class VirtualDerived2 &&': Unsupported type: && without lifetime
-unsafe impl oops::Inherits<VirtualBase1> for VirtualDerived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const VirtualBase1 {
+unsafe impl oops::Inherits<inheritance_cc::VirtualBase1> for VirtualDerived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::VirtualBase1 {
detail::__crubit_dynamic_upcast__VirtualDerived2__to__VirtualBase1(derived)
}
}
-unsafe impl oops::Inherits<Base1> for VirtualDerived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const Base1 {
+unsafe impl oops::Inherits<inheritance_cc::Base1> for VirtualDerived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::Base1 {
detail::__crubit_dynamic_upcast__VirtualDerived2__to__Base1(derived)
}
}
-unsafe impl oops::Inherits<VirtualBase2> for VirtualDerived2 {
- unsafe fn upcast_ptr(derived: *const Self) -> *const VirtualBase2 {
+unsafe impl oops::Inherits<inheritance_cc::VirtualBase2> for VirtualDerived2 {
+ unsafe fn upcast_ptr(derived: *const Self) -> *const inheritance_cc::VirtualBase2 {
detail::__crubit_dynamic_upcast__VirtualDerived2__to__VirtualBase2(derived)
}
}
@@ -116,16 +116,18 @@
#[allow(unused_imports)]
use super::*;
extern "C" {
- pub fn __crubit_dynamic_upcast__Derived2__to__Base0(from: *const Derived2) -> *const Base0;
+ pub fn __crubit_dynamic_upcast__Derived2__to__Base0(
+ from: *const Derived2,
+ ) -> *const inheritance_cc::Base0;
pub fn __crubit_dynamic_upcast__VirtualDerived2__to__VirtualBase1(
from: *const VirtualDerived2,
- ) -> *const VirtualBase1;
+ ) -> *const inheritance_cc::VirtualBase1;
pub fn __crubit_dynamic_upcast__VirtualDerived2__to__Base1(
from: *const VirtualDerived2,
- ) -> *const Base1;
+ ) -> *const inheritance_cc::Base1;
pub fn __crubit_dynamic_upcast__VirtualDerived2__to__VirtualBase2(
from: *const VirtualDerived2,
- ) -> *const VirtualBase2;
+ ) -> *const inheritance_cc::VirtualBase2;
}
}