Move __runtime into __internal::runtime

Clarify the rustdoc on __internal

PiperOrigin-RevId: 703541883
diff --git a/rust/internal.rs b/rust/internal.rs
index afb169a..5b08dc5 100644
--- a/rust/internal.rs
+++ b/rust/internal.rs
@@ -19,10 +19,17 @@
 use crate::Proxied;
 pub use std::fmt::Debug;
 
+#[cfg(all(bzl, cpp_kernel))]
+#[path = "cpp.rs"]
+pub mod runtime;
+#[cfg(any(not(bzl), upb_kernel))]
+#[path = "upb.rs"]
+pub mod runtime;
+
 // TODO: Temporarily re-export these symbols which are now under
-// __runtime under __internal since some external callers using it through
-// __internal.
-pub use crate::__runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField};
+// runtime under __internal directly since some external callers using it
+// through __internal.
+pub use runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField};
 
 /// Used to protect internal-only items from being used accidentally.
 #[derive(Debug)]
diff --git a/rust/map.rs b/rust/map.rs
index 9df11f5..612210b 100644
--- a/rust/map.rs
+++ b/rust/map.rs
@@ -8,8 +8,8 @@
 use crate::{
     AsMut, AsView, IntoMut, IntoProxied, IntoView, MutProxied, MutProxy, Proxied, Proxy, View,
     ViewProxy,
+    __internal::runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter},
     __internal::{Private, SealedInternal},
-    __runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter},
 };
 use std::marker::PhantomData;
 
@@ -104,7 +104,11 @@
 }
 
 impl<K: Proxied, V: ProxiedInMapValue<K>> Proxied for Map<K, V> {
-    type View<'msg> = MapView<'msg, K, V> where K: 'msg, V: 'msg;
+    type View<'msg>
+        = MapView<'msg, K, V>
+    where
+        K: 'msg,
+        V: 'msg;
 }
 
 impl<K: Proxied, V: ProxiedInMapValue<K>> AsView for Map<K, V> {
@@ -116,7 +120,11 @@
 }
 
 impl<K: Proxied, V: ProxiedInMapValue<K>> MutProxied for Map<K, V> {
-    type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg;
+    type Mut<'msg>
+        = MapMut<'msg, K, V>
+    where
+        K: 'msg,
+        V: 'msg;
 }
 
 impl<K: Proxied, V: ProxiedInMapValue<K>> AsMut for Map<K, V> {
diff --git a/rust/protobuf.rs b/rust/protobuf.rs
index 172739a..d7f9bff 100644
--- a/rust/protobuf.rs
+++ b/rust/protobuf.rs
@@ -11,9 +11,9 @@
 //! is a thin re-export of the `shared.rs` file but is needed for two reasons:
 //! - To create a single `protobuf` crate name for either cpp and upb kernels
 //!   from user code (toggled at compile time).
-//! - Blocks the __internal and __runtime modules from being re-exported to
-//!   application code, unless they use one of our visibility-restricted targets
-//!   (gencode does have access to them).
+//! - Blocks the __internal module from being re-exported to application code,
+//!   unless they use one of our visibility-restricted targets (gencode does
+//!   have access to them).
 
 #[cfg(cpp_kernel)]
 use protobuf_cpp as kernel;
@@ -31,8 +31,4 @@
 #[allow(non_upper_case_globals)]
 pub const __internal: () = ();
 
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-pub const __runtime: () = ();
-
 pub use kernel::*;
diff --git a/rust/repeated.rs b/rust/repeated.rs
index 9d14faa..479acb7 100644
--- a/rust/repeated.rs
+++ b/rust/repeated.rs
@@ -5,6 +5,7 @@
 // license that can be found in the LICENSE file or at
 // https://developers.google.com/open-source/licenses/bsd
 
+use std::fmt::{self, Debug};
 use std::iter;
 use std::iter::FusedIterator;
 /// Repeated scalar fields are implemented around the runtime-specific
@@ -12,13 +13,12 @@
 /// runtime-specific representation of a repeated scalar (`upb_Array*` on upb,
 /// and `RepeatedField<T>*` on cpp).
 use std::marker::PhantomData;
-use std::fmt::{self, Debug};
 
 use crate::{
     AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View,
     ViewProxy,
+    __internal::runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField},
     __internal::{Private, SealedInternal},
-    __runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField},
 };
 
 /// Views the elements in a `repeated` field of `T`.
@@ -379,7 +379,10 @@
 where
     T: ProxiedInRepeated,
 {
-    type View<'msg> = RepeatedView<'msg, T> where Repeated<T>: 'msg;
+    type View<'msg>
+        = RepeatedView<'msg, T>
+    where
+        Repeated<T>: 'msg;
 }
 
 impl<T> SealedInternal for Repeated<T> where T: ProxiedInRepeated {}
@@ -399,7 +402,10 @@
 where
     T: ProxiedInRepeated,
 {
-    type Mut<'msg> = RepeatedMut<'msg, T> where Repeated<T>: 'msg;
+    type Mut<'msg>
+        = RepeatedMut<'msg, T>
+    where
+        Repeated<T>: 'msg;
 }
 
 impl<T> AsMut for Repeated<T>
diff --git a/rust/shared.rs b/rust/shared.rs
index ff8c88a..8e49f75 100644
--- a/rust/shared.rs
+++ b/rust/shared.rs
@@ -5,10 +5,6 @@
 // license that can be found in the LICENSE file or at
 // https://developers.google.com/open-source/licenses/bsd
 
-//! Kernel-agnostic logic for the Rust Protobuf Runtime.
-//!
-//! For kernel-specific logic this crate delegates to the respective `__runtime`
-//! crate.
 #![deny(unsafe_op_in_unsafe_fn)]
 
 use std::fmt;
@@ -38,22 +34,24 @@
 
 pub mod prelude;
 
-/// Everything in `__internal` is allowed to change without it being considered
-/// a breaking change for the protobuf library. Nothing in here should be
-/// exported in `protobuf.rs`.
+/// The `__internal` module is for necessary encapsulation breaks between
+/// generated code and the runtime.
+///
+/// These symbols are never intended to be used by application code under any
+/// circumstances.
+///
+/// In blaze/bazel builds, this symbol is actively hidden from application
+/// code by having a shim crate in front that does not re-export this symbol,
+/// and a different BUILD visibility-restricted target that is used by the
+/// generated code.
+///
+/// In Cargo builds we have no good way to technically hide this
+/// symbol while still allowing it from codegen, so it is only by private by
+/// convention. As application code should never use this module, anything
+/// changes under `__internal` is not considered a semver breaking change.
 #[path = "internal.rs"]
 pub mod __internal;
 
-/// Everything in `__runtime` is allowed to change without it being considered
-/// a breaking change for the protobuf library. Nothing in here should be
-/// exported in `protobuf.rs`.
-#[cfg(all(bzl, cpp_kernel))]
-#[path = "cpp.rs"]
-pub mod __runtime;
-#[cfg(any(not(bzl), upb_kernel))]
-#[path = "upb.rs"]
-pub mod __runtime;
-
 mod codegen_traits;
 mod cord;
 #[path = "enum.rs"]
diff --git a/rust/string.rs b/rust/string.rs
index 9ff9847..bddbdde 100644
--- a/rust/string.rs
+++ b/rust/string.rs
@@ -9,8 +9,8 @@
 #![allow(dead_code)]
 #![allow(unused)]
 
+use crate::__internal::runtime::{InnerProtoString, PtrAndLen, RawMessage};
 use crate::__internal::{Private, SealedInternal};
-use crate::__runtime::{InnerProtoString, PtrAndLen, RawMessage};
 use crate::{
     utf8::Utf8Chunks, AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied,
     Proxy, View, ViewProxy,
diff --git a/rust/test/cpp/interop/main.rs b/rust/test/cpp/interop/main.rs
index 4376311..5751a0a 100644
--- a/rust/test/cpp/interop/main.rs
+++ b/rust/test/cpp/interop/main.rs
@@ -8,7 +8,7 @@
 use googletest::prelude::*;
 use protobuf_cpp::prelude::*;
 
-use protobuf_cpp::__runtime::PtrAndLen;
+use protobuf_cpp::__internal::runtime::PtrAndLen;
 use protobuf_cpp::{MessageMutInterop, MessageViewInterop, OwnedMessageInterop};
 use std::ffi::c_void;
 
@@ -31,7 +31,9 @@
     fn TakeOwnershipAndGetOptionalInt64(msg: *mut c_void) -> i64;
     fn DeserializeInteropTestMessage(data: *const u8, len: usize) -> *mut c_void;
     fn MutateInteropTestMessage(msg: *mut c_void);
-    fn SerializeInteropTestMessage(msg: *const c_void) -> protobuf_cpp::__runtime::SerializedData;
+    fn SerializeInteropTestMessage(
+        msg: *const c_void,
+    ) -> protobuf_cpp::__internal::runtime::SerializedData;
     fn DeleteInteropTestMessage(msg: *mut c_void);
 
     fn NewWithExtension() -> *mut c_void;
diff --git a/rust/test/shared/no_internal_access_test.rs b/rust/test/shared/no_internal_access_test.rs
index 4470faf..10f05fc 100644
--- a/rust/test/shared/no_internal_access_test.rs
+++ b/rust/test/shared/no_internal_access_test.rs
@@ -1,11 +1,10 @@
 
-use protobuf::{__internal, __runtime};
+use protobuf::__internal;
 
 #[googletest::test]
 #[allow(clippy::unit_cmp)]
 fn test_no_internal_access() {
-    // This test is to ensure that the `__internal` and `__runtime` mods are
-    // 'blocked' by instead being a unit type instead of a module.
+    // This test is to ensure that the `__internal` is 'blocked' by instead being a
+    // unit type instead of a module.
     assert_eq!(__internal, ());
-    assert_eq!(__runtime, ());
 }
diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc
index c12a7fa..21c608b 100644
--- a/src/google/protobuf/compiler/rust/generator.cc
+++ b/src/google/protobuf/compiler/rust/generator.cc
@@ -150,7 +150,7 @@
       {"std", "::std"},
       {"pb", "::protobuf"},
       {"pbi", "::protobuf::__internal"},
-      {"pbr", "::protobuf::__runtime"},
+      {"pbr", "::protobuf::__internal::runtime"},
       {"NonNull", "::std::ptr::NonNull"},
       {"Phantom", "::std::marker::PhantomData"},
       {"Result", "::std::result::Result"},