Remove +?Sized bounds which simply aren't honored anyway.

When you have a `T: SomeTrait + ?Sized` and `trait SomeTrait:Sized`, the ?Sized has no effect (its not able to "remove" the requirement).

PiperOrigin-RevId: 654836513
pull/17558/head
Protobuf Team Bot 4 months ago committed by Copybara-Service
parent 9e38dce616
commit a1c53e4da2
  1. 4
      rust/cpp.rs
  2. 71
      rust/map.rs
  3. 2
      rust/proxied.rs
  4. 6
      rust/upb.rs

@ -691,8 +691,8 @@ impl UntypedMapIterator {
from_ffi_value: impl FnOnce(FfiValue) -> View<'a, V>,
) -> Option<(View<'a, K>, View<'a, V>)>
where
K: Proxied + ?Sized + 'a,
V: ProxiedInMapValue<K> + ?Sized + 'a,
K: Proxied + 'a,
V: ProxiedInMapValue<K> + 'a,
{
if self.at_end() {
return None;

@ -59,19 +59,19 @@ impl<'msg, K: ?Sized, V: ?Sized> std::fmt::Debug for MapMut<'msg, K, V> {
}
}
pub struct Map<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> {
pub struct Map<K: Proxied, V: ProxiedInMapValue<K>> {
inner: InnerMap,
_phantom: PhantomData<(PhantomData<K>, PhantomData<V>)>,
}
// SAFETY: `Map` is Sync because it does not implement interior mutability.
unsafe impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Sync for Map<K, V> {}
unsafe impl<K: Proxied, V: ProxiedInMapValue<K>> Sync for Map<K, V> {}
// SAFETY: `Map` is Send because it's not bound to a specific thread e.g.
// it does not use thread-local data or similar.
unsafe impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Send for Map<K, V> {}
unsafe impl<K: Proxied, V: ProxiedInMapValue<K>> Send for Map<K, V> {}
impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Drop for Map<K, V> {
impl<K: Proxied, V: ProxiedInMapValue<K>> Drop for Map<K, V> {
fn drop(&mut self) {
// SAFETY:
// - `drop` is only called once.
@ -82,7 +82,7 @@ impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Drop for Map<K, V> {
pub trait ProxiedInMapValue<K>: Proxied
where
K: Proxied + ?Sized,
K: Proxied,
{
fn map_new(_private: Private) -> Map<K, Self>;
@ -104,17 +104,15 @@ where
fn map_iter_next<'a>(iter: &mut MapIter<'a, K, Self>) -> Option<(View<'a, K>, View<'a, Self>)>;
}
impl<K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> Proxied for Map<K, V> {
impl<K: Proxied, V: ProxiedInMapValue<K>> Proxied for Map<K, V> {
type View<'msg> = MapView<'msg, K, V> where K: 'msg, V: 'msg;
}
impl<K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> MutProxied for Map<K, V> {
impl<K: Proxied, V: ProxiedInMapValue<K>> MutProxied for Map<K, V> {
type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg;
}
impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> Proxy<'msg>
for MapView<'msg, K, V>
{
impl<'msg, K: Proxied, V: ProxiedInMapValue<K>> Proxy<'msg> for MapView<'msg, K, V> {
type Proxied = Map<K, V>;
fn as_view(&self) -> View<'_, Self::Proxied> {
@ -129,14 +127,9 @@ impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> Proxy<'msg>
}
}
impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> ViewProxy<'msg>
for MapView<'msg, K, V>
{
}
impl<'msg, K: Proxied, V: ProxiedInMapValue<K>> ViewProxy<'msg> for MapView<'msg, K, V> {}
impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> Proxy<'msg>
for MapMut<'msg, K, V>
{
impl<'msg, K: Proxied, V: ProxiedInMapValue<K>> Proxy<'msg> for MapMut<'msg, K, V> {
type Proxied = Map<K, V>;
fn as_view(&self) -> View<'_, Self::Proxied> {
@ -151,9 +144,7 @@ impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> Proxy<'msg>
}
}
impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> MutProxy<'msg>
for MapMut<'msg, K, V>
{
impl<'msg, K: Proxied, V: ProxiedInMapValue<K>> MutProxy<'msg> for MapMut<'msg, K, V> {
fn as_mut(&mut self) -> Mut<'_, Self::Proxied> {
MapMut { inner: self.inner, _phantom: PhantomData }
}
@ -168,8 +159,8 @@ impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue<K> + ?Sized> MutProxy<'msg>
impl<K, V> Map<K, V>
where
K: Proxied + ?Sized,
V: ProxiedInMapValue<K> + ?Sized,
K: Proxied,
V: ProxiedInMapValue<K>,
{
pub fn new() -> Self {
V::map_new(Private)
@ -195,8 +186,8 @@ where
impl<K, V> Default for Map<K, V>
where
K: Proxied + ?Sized,
V: ProxiedInMapValue<K> + ?Sized,
K: Proxied,
V: ProxiedInMapValue<K>,
{
fn default() -> Self {
Map::new()
@ -220,8 +211,8 @@ impl<'msg, K: ?Sized, V: ?Sized> MapView<'msg, K, V> {
impl<'msg, K, V> MapView<'msg, K, V>
where
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
pub fn get<'a>(self, key: impl Into<View<'a, K>>) -> Option<View<'msg, V>>
where
@ -278,8 +269,8 @@ impl<'msg, K: ?Sized, V: ?Sized> MapMut<'msg, K, V> {
impl<'msg, K, V> MapMut<'msg, K, V>
where
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
pub fn len(&self) -> usize {
self.as_view().len()
@ -378,8 +369,8 @@ impl<'msg, K: ?Sized, V: ?Sized> MapIter<'msg, K, V> {
impl<'msg, K, V> Iterator for MapIter<'msg, K, V>
where
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
type Item = (View<'msg, K>, View<'msg, V>);
@ -390,8 +381,8 @@ where
impl<'msg, K, V> IntoIterator for MapView<'msg, K, V>
where
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
type IntoIter = MapIter<'msg, K, V>;
type Item = (View<'msg, K>, View<'msg, V>);
@ -403,8 +394,8 @@ where
impl<'msg, K, V> IntoIterator for &'msg Map<K, V>
where
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
type IntoIter = MapIter<'msg, K, V>;
type Item = (View<'msg, K>, View<'msg, V>);
@ -417,8 +408,8 @@ where
impl<'a, 'msg, K, V> IntoIterator for &'a MapView<'msg, K, V>
where
'msg: 'a,
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
type IntoIter = MapIter<'msg, K, V>;
type Item = (View<'msg, K>, View<'msg, V>);
@ -431,8 +422,8 @@ where
impl<'a, 'msg, K, V> IntoIterator for &'a MapMut<'msg, K, V>
where
'msg: 'a,
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
K: Proxied + 'msg,
V: ProxiedInMapValue<K> + 'msg,
{
type IntoIter = MapIter<'a, K, V>;
// The View's are valid for 'a instead of 'msg.
@ -446,8 +437,8 @@ where
impl<'msg, 'k, 'v, KView, VView, K, V> Extend<(KView, VView)> for MapMut<'msg, K, V>
where
K: Proxied + ?Sized + 'msg + 'k,
V: ProxiedInMapValue<K> + ?Sized + 'msg + 'v,
K: Proxied + 'msg + 'k,
V: ProxiedInMapValue<K> + 'msg + 'v,
KView: Into<View<'k, K>>,
VView: IntoProxied<V>,
{

@ -96,7 +96,7 @@ pub type Mut<'msg, T> = <T as MutProxied>::Mut<'msg>;
/// This trait is intentionally made non-object-safe to prevent a potential
/// future incompatible change.
pub trait Proxy<'msg>: 'msg + Sync + Unpin + Sized + Debug {
type Proxied: 'msg + Proxied + ?Sized;
type Proxied: 'msg + Proxied;
/// Converts a borrow into a `View` with the lifetime of that borrow.
///

@ -464,7 +464,7 @@ pub fn free_enum_repeated<E: Enum + ProxiedInRepeated>(
}
/// Returns a static empty RepeatedView.
pub fn empty_array<T: ?Sized + ProxiedInRepeated>() -> RepeatedView<'static, T> {
pub fn empty_array<T: ProxiedInRepeated>() -> RepeatedView<'static, T> {
// TODO: Consider creating a static empty array in C.
// Use `i32` for a shared empty repeated for all repeated types in the program.
@ -484,8 +484,8 @@ pub fn empty_array<T: ?Sized + ProxiedInRepeated>() -> RepeatedView<'static, T>
/// Returns a static empty MapView.
pub fn empty_map<K, V>() -> MapView<'static, K, V>
where
K: Proxied + ?Sized,
V: ProxiedInMapValue<K> + ?Sized,
K: Proxied,
V: ProxiedInMapValue<K>,
{
// TODO: Consider creating a static empty map in C.

Loading…
Cancel
Save