From 427d203dfcd5a62267ac5e37d52760b166507247 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Fri, 27 Mar 2026 14:32:50 -0700 Subject: [PATCH] Don't emit empty namespaces. PiperOrigin-RevId: 890639061 --- bazel/llvm.bzl | 2 +- cc_bindings_from_rs/generate_bindings/lib.rs | 3 +++ cc_bindings_from_rs/test/enums/cpp_enums_cc_api.h | 6 ------ .../test/golden/type_aliases_cc_api.h | 2 -- cc_bindings_from_rs/test/modules/modules_cc_api.h | 12 ------------ cc_bindings_from_rs/test/structs/structs_cc_api.h | 2 -- 6 files changed, 4 insertions(+), 23 deletions(-) diff --git a/bazel/llvm.bzl b/bazel/llvm.bzl index 03ddda0ae..e3ac59ed1 100644 --- a/bazel/llvm.bzl +++ b/bazel/llvm.bzl @@ -53,7 +53,7 @@ def _llvm_loader_repository(repository_ctx): executable = False, ) -LLVM_COMMIT_SHA = "5a403150b468a5de7ddf9f1e295643c9c518aee8" +LLVM_COMMIT_SHA = "9a0b003dde83d46f2ed6d95d85d1d9de3c1fe908" def llvm_loader_repository_dependencies(): # This *declares* the dependency, but it won't actually be *downloaded* unless it's used. diff --git a/cc_bindings_from_rs/generate_bindings/lib.rs b/cc_bindings_from_rs/generate_bindings/lib.rs index 0b80a4cca..4b88d5372 100644 --- a/cc_bindings_from_rs/generate_bindings/lib.rs +++ b/cc_bindings_from_rs/generate_bindings/lib.rs @@ -367,6 +367,9 @@ fn format_with_cc_body( mut tokens: TokenStream, attributes: Vec, ) -> Result { + if tokens.is_empty() { + return Ok(quote! {}); + } let mut namespaces = ns.parts().map(|s| format_cc_ident(db, s)).collect::>>()?; // Nested namespace syntax does not accept attributes (see b/445613694), so we have to split out diff --git a/cc_bindings_from_rs/test/enums/cpp_enums_cc_api.h b/cc_bindings_from_rs/test/enums/cpp_enums_cc_api.h index c33048abe..8da94a7ae 100644 --- a/cc_bindings_from_rs/test/enums/cpp_enums_cc_api.h +++ b/cc_bindings_from_rs/test/enums/cpp_enums_cc_api.h @@ -83,12 +83,6 @@ enum class CRUBIT_INTERNAL_RUST_TYPE( } // namespace cpp_enums::forward_declared_enum -namespace cpp_enums::classless_enum {} - -namespace cpp_enums::cpp_enum {} - -namespace cpp_enums::deprecated_enum {} - namespace cpp_enums::forward_declared_enum { namespace __crubit_internal { diff --git a/cc_bindings_from_rs/test/golden/type_aliases_cc_api.h b/cc_bindings_from_rs/test/golden/type_aliases_cc_api.h index 2c8c8392a..8b8028a72 100644 --- a/cc_bindings_from_rs/test/golden/type_aliases_cc_api.h +++ b/cc_bindings_from_rs/test/golden/type_aliases_cc_api.h @@ -48,8 +48,6 @@ std::int32_t func_using_alias(); } // namespace type_aliases_rust::test_type_aliases -namespace type_aliases_rust::test_deprecated_type_alias {} - namespace type_aliases_rust::test_type_aliases { namespace __crubit_internal { diff --git a/cc_bindings_from_rs/test/modules/modules_cc_api.h b/cc_bindings_from_rs/test/modules/modules_cc_api.h index 5e2e0571b..61f9b380d 100644 --- a/cc_bindings_from_rs/test/modules/modules_cc_api.h +++ b/cc_bindings_from_rs/test/modules/modules_cc_api.h @@ -183,17 +183,5 @@ inline void Foo::__crubit_field_offset_assertions() { } } // namespace modules::impl_in_separate_private_module -namespace modules::outer { - -namespace [[deprecated]] inner_deprecated {} - -} // namespace modules::outer - -namespace modules::outer::middle { - -namespace [[deprecated]] innermost_deprecated {} - -} // namespace modules::outer::middle - #pragma clang diagnostic pop #endif // THIRD_PARTY_CRUBIT_CC_BINDINGS_FROM_RS_TEST_MODULES_MODULES_GOLDEN diff --git a/cc_bindings_from_rs/test/structs/structs_cc_api.h b/cc_bindings_from_rs/test/structs/structs_cc_api.h index a34c24a43..ee8e16f71 100644 --- a/cc_bindings_from_rs/test/structs/structs_cc_api.h +++ b/cc_bindings_from_rs/test/structs/structs_cc_api.h @@ -959,8 +959,6 @@ inline std::int32_t get_x(::structs::default_repr::Point p) { } // namespace structs::default_repr -namespace structs::dynamically_sized_type {} - namespace structs::interior_mutability { static_assert(