Do not import static member functions when the record couldn't be imported

PiperOrigin-RevId: 424551340
diff --git a/rs_bindings_from_cc/ast_visitor.cc b/rs_bindings_from_cc/ast_visitor.cc
index c575cc9..2aebfe5 100644
--- a/rs_bindings_from_cc/ast_visitor.cc
+++ b/rs_bindings_from_cc/ast_visitor.cc
@@ -216,8 +216,16 @@
 
   std::vector<FuncParam> params;
   bool success = true;
-  // non-static member functions receive an implicit `this` parameter.
+
   if (auto* method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(function_decl)) {
+    if (!known_type_decls_.contains(
+            method_decl->getParent()->getCanonicalDecl())) {
+      PushUnsupportedItem(function_decl, "Couldn't import the parent",
+                          method_decl->getBeginLoc());
+      return true;
+    }
+
+    // non-static member functions receive an implicit `this` parameter.
     if (method_decl->isInstance()) {
       std::optional<devtools_rust::TypeLifetimes> this_lifetimes;
       if (lifetimes) {
diff --git a/rs_bindings_from_cc/ir_from_cc_test.rs b/rs_bindings_from_cc/ir_from_cc_test.rs
index 1921e91..7c7bbe0 100644
--- a/rs_bindings_from_cc/ir_from_cc_test.rs
+++ b/rs_bindings_from_cc/ir_from_cc_test.rs
@@ -618,6 +618,45 @@
         }}
     );
 }
+#[test]
+fn test_do_not_import_static_member_functions_when_record_not_supported_yet() {
+    // only using nested struct as an example of a record we cannot import yet.
+    let ir = ir_from_cc(
+        "
+        struct SomeStruct {
+          struct NestedStruct {
+            static void StaticMemberFunction();
+          };
+        };",
+    )
+    .unwrap();
+    assert_ir_matches!(
+        ir,
+        quote! { UnsupportedItem {
+          name: "SomeStruct::NestedStruct::StaticMemberFunction" ...
+        }}
+    );
+}
+
+#[test]
+fn test_do_not_import_nonstatic_member_functions_when_record_not_supported_yet() {
+    // only using nested struct as an example of a record we cannot import yet.
+    let ir = ir_from_cc(
+        "
+        struct SomeStruct {
+          struct NestedStruct {
+            void NonStaticMemberFunction();
+          };
+        };",
+    )
+    .unwrap();
+    assert_ir_matches!(
+        ir,
+        quote! { UnsupportedItem {
+          name: "SomeStruct::NestedStruct::NonStaticMemberFunction" ...
+        }}
+    );
+}
 
 #[test]
 fn test_dont_import_injected_class_name() {
diff --git a/rs_bindings_from_cc/test/golden/unsupported.h b/rs_bindings_from_cc/test/golden/unsupported.h
index 09f3a51..ccd8dac 100644
--- a/rs_bindings_from_cc/test/golden/unsupported.h
+++ b/rs_bindings_from_cc/test/golden/unsupported.h
@@ -20,11 +20,17 @@
 
 namespace ns {
 void FunctionInNamespace();
-struct StructInNamespace final {};
+struct StructInNamespace final {
+  void NonStaticMemberFunction();
+  void StaticMemberFunction();
+};
 }  // namespace ns
 
 struct ContainingStruct final {
-  struct NestedStruct final {};
+  struct NestedStruct final {
+    void NonStaticMemberFunction();
+    void StaticMemberFunction();
+  };
 };
 
 #endif  // CRUBIT_RS_BINDINGS_FROM_CC_TEST_GOLDEN_UNSUPPORTED_H_
diff --git a/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs b/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs
index 4839275..e6d3401 100644
--- a/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs
+++ b/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs
@@ -66,18 +66,26 @@
     }
 }
 
-// rs_bindings_from_cc/test/golden/unsupported.h;l=22
+// rs_bindings_from_cc/test/golden/unsupported.h;l=25
 // Error while generating bindings for item 'ContainingStruct::ContainingStruct':
 // Parameter type 'struct ContainingStruct &&' is not supported
 
-// rs_bindings_from_cc/test/golden/unsupported.h;l=22
+// rs_bindings_from_cc/test/golden/unsupported.h;l=25
 // Error while generating bindings for item 'ContainingStruct::operator=':
 // Parameter type 'struct ContainingStruct &&' is not supported
 
-// rs_bindings_from_cc/test/golden/unsupported.h;l=23
+// rs_bindings_from_cc/test/golden/unsupported.h;l=26
 // Error while generating bindings for item 'ContainingStruct::NestedStruct':
 // Nested classes are not supported yet
 
+// rs_bindings_from_cc/test/golden/unsupported.h;l=27
+// Error while generating bindings for item 'ContainingStruct::NestedStruct::NonStaticMemberFunction':
+// Couldn't import the parent
+
+// rs_bindings_from_cc/test/golden/unsupported.h;l=28
+// Error while generating bindings for item 'ContainingStruct::NestedStruct::StaticMemberFunction':
+// Couldn't import the parent
+
 // CRUBIT_RS_BINDINGS_FROM_CC_TEST_GOLDEN_UNSUPPORTED_H_
 
 mod detail {