google_protobuf/proxied.rs
1// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8//! Operating on borrowed data owned by a message is a central concept in
9//! Protobuf (and Rust in general). The way this is normally accomplished in
10//! Rust is to pass around references and operate on those. Unfortunately,
11//! references come with two major drawbacks:
12//!
13//! * We must store the value somewhere in the memory to create a reference to it. The value must be
14//! readable by a single load. However for Protobuf fields it happens that the actual memory
15//! representation of a value differs from what users expect and it is an implementation detail
16//! that can change as more optimizations are implemented. For example, rarely accessed `int64`
17//! fields can be represented in a packed format with 32 bits for the value in the common case.
18//! Or, a single logical value can be spread across multiple memory locations. For example,
19//! presence information for all the fields in a protobuf message is centralized in a bitset.
20//! * We cannot store extra data on the reference that might be necessary for correctly manipulating
21//! it (and custom-metadata DSTs do not exist yet in Rust). Concretely, messages, string, bytes,
22//! and repeated fields in UPB need to carry around an arena parameter separate from the data
23//! pointer to enable mutation (for example adding an element to a repeated field) or potentially
24//! to enable optimizations (for example referencing a string value using a Cord-like type instead
25//! of copying it if the source and target messages are on the same arena already). Mutable
26//! references to messages have one additional drawback: Rust allows users to indiscriminately run
27//! a bytewise swap() on mutable references, which could result in pointers to the wrong arena
28//! winding up on a message. For example, imagine swapping a submessage across two root messages
29//! allocated on distinct arenas A and B; after the swap, the message allocated in A may contain
30//! pointers from B by way of the submessage, because the swap does not know to fix up those
31//! pointers as needed. The C++ API uses message-owned arenas, and this ends up resembling
32//! self-referential types, which need `Pin` in order to be sound. However, `Pin` has much
33//! stronger guarantees than we need to uphold.
34//!
35//! These drawbacks put the "idiomatic Rust" goal in conflict with the
36//! "performance", "evolvability", and "safety" goals. Given the project design
37//! priorities we decided to not use plain Rust references. Instead, we
38//! implemented the concept of "proxy" types. Proxy types are a reference-like
39//! indirection between the user and the internal memory representation.
40
41use crate::__internal::{Private, SealedInternal};
42
43/// NOTE: This type is primarily an implementation detail in support of trait resolution, and
44/// application code should very rarely write this type.
45///
46/// An owned Protobuf entity or field type that can be accessed through reference-like proxies.
47///
48/// In standard Rust, shared and exclusive access to borrowed data is provided via native
49/// references (`&T` and `&mut T`). However, standard references don't provide sufficient power
50/// to hide implementation details that Protobuf wants to take advantage of: for example, handing
51/// out `&mut` always allows for `std::mem::swap`, which precludes certain optimizations across
52/// parenting relationships. It also prevents optimizations like root messages and child messages
53/// of the same type having different layouts.
54///
55/// To provide safe, ergonomic, and zero-cost or low-cost access across these representations,
56/// Protobuf uses "proxy" types:
57/// - [`View<'msg, T>`](View): A proxy type that provides shared, read-only access (analogous to
58/// `&'msg T`).
59/// - [`Mut<'msg, T>`](Mut): A proxy type that provides exclusive mutable access (analogous to
60/// `&'msg mut T`).
61///
62/// An implementor of `ProtoObject` represents the *owned* target type (for example, a generated
63/// message struct `MyMessage`, primitive types like `i32`, `Repeated<T>`, `Map<K, V>`,
64/// `ProtoBytes`, or `ProtoString`). It is **not** the proxy itself.
65///
66/// # Writing User Code
67///
68/// In general, application code should rarely ever need to write the type `ProtoObject`.
69///
70/// - **Concrete usage**: Work directly with the owned message types (e.g. `MyMessage`), concrete
71/// view types (e.g. `MyMessageView<'msg>`, `MyMessageMut<'msg>`), or the type aliases
72/// [`View<'msg, T>`](View) and [`Mut<'msg, T>`](Mut).
73/// - **Generic functions**: When writing functions that operate generically on messages or borrows
74/// of messages, prefer higher-level traits such as [`Message`](crate::Message), [`AsView`],
75/// [`IntoView`], [`AsMut`], or [`IntoMut`]. For example: ```ignore fn process_message(msg: impl
76/// AsView<Proxied = MyMessage>) { let view = msg.as_view(); // ... } ```
77///
78/// `ProtoObject` is primarily a foundational plumbing trait connecting owned types with their
79/// associated proxy representations for the Protobuf runtime and code generator.
80pub trait ProtoObject: SealedInternal + AsView<Proxied = Self> + Sized + 'static {
81 /// The proxy type that provides shared access to a `T`, like a `&'msg T`.
82 ///
83 /// Most code should use the type alias [`View`].
84 type View<'msg>: AsView<Proxied = Self> + IntoView<'msg>;
85}
86
87/// Deprecated alias for [`ProtoObject`].
88#[deprecated(note = "Use `ProtoObject` instead.")]
89pub use self::ProtoObject as Proxied;
90
91/// NOTE: This type is primarily an implementation detail in support of trait resolution, and
92/// application code should very rarely write this type.
93///
94/// A [`ProtoObject`] that can also be accessed mutably through a reference-like proxy.
95///
96/// An instance of a `MutProtoObject` can be accessed mutably via `MutProtoObject::Mut`
97/// and immutably via `ProtoObject::View`.
98///
99/// `MutProtoObject` is implemented by message, map and repeated field types.
100pub trait MutProtoObject:
101 SealedInternal + ProtoObject + AsMut<MutProxied = Self> + 'static
102{
103 /// The proxy type that provides exclusive mutable access to a `T`, like a
104 /// `&'msg mut T`.
105 ///
106 /// Most code should use the type alias [`Mut`].
107 type Mut<'msg>: AsMut<MutProxied = Self> + IntoMut<'msg> + IntoView<'msg>;
108}
109
110/// Deprecated alias for [`MutProtoObject`].
111#[deprecated(note = "Use `MutProtoObject` instead.")]
112pub use self::MutProtoObject as MutProxied;
113
114/// A proxy type that provides shared access to a `T`, like a `&'msg T`.
115///
116/// This is more concise than fully spelling the associated type.
117#[allow(dead_code)]
118pub type View<'msg, T> = <T as ProtoObject>::View<'msg>;
119
120/// A proxy type that provides exclusive mutable access to a `T`, like a
121/// `&'msg mut T`.
122///
123/// This is more concise than fully spelling the associated type.
124#[allow(dead_code)]
125pub type Mut<'msg, T> = <T as MutProtoObject>::Mut<'msg>;
126
127/// Used to semantically do a cheap "to-reference" conversion. This is
128/// implemented on both owned `ProtoObject` types as well as view and mut proxy
129/// types.
130///
131/// On a view proxy this will behave as a reborrow into a shorter lifetime.
132#[diagnostic::on_unimplemented(
133 message = "the trait `AsView` is not implemented for `{Self}`",
134 note = "consider calling `.as_view()`, or changing the fn to accept \
135 `impl AsView<Proxied = T>`"
136)]
137pub trait AsView: SealedInternal {
138 type Proxied: ProtoObject;
139
140 /// Converts a borrow into a `View` with the lifetime of that borrow.
141 ///
142 /// In non-generic code we don't need to use `as_view` because the proxy
143 /// types are covariant over `'msg`. However, generic code conservatively
144 /// treats `'msg` as [invariant], therefore we need to call
145 /// `as_view` to explicitly perform the operation that in concrete code
146 /// coercion would perform implicitly.
147 ///
148 /// For example, the call to `.as_view()` in the following snippet
149 /// wouldn't be necessary in concrete code:
150 /// ```ignore
151 /// fn reborrow<'a, 'b, T>(x: &'b View<'a, T>) -> View<'b, T>
152 /// where 'a: 'b, T: ProtoObject
153 /// {
154 /// x.as_view()
155 /// }
156 /// ```
157 ///
158 /// [invariant]: https://doc.rust-lang.org/nomicon/subtyping.html#variance
159 fn as_view(&self) -> View<'_, Self::Proxied>;
160}
161
162impl<T: ProtoObject> AsView for &T {
163 type Proxied = T::Proxied;
164 fn as_view(&self) -> View<'_, Self::Proxied> {
165 (**self).as_view()
166 }
167}
168
169impl<T: ProtoObject> AsView for &mut T {
170 type Proxied = T::Proxied;
171 fn as_view(&self) -> View<'_, Self::Proxied> {
172 (**self).as_view()
173 }
174}
175
176/// Used to turn another 'borrow' into a view proxy.
177///
178/// On a mut proxy this borrows to a View (semantically matching turning a `&mut
179/// T` into a `&T`).
180///
181/// On a view proxy this will behave as a reborrow into a shorter lifetime
182/// (semantically matching a `&'a T` into a `&'b T` where `'a: 'b`).
183#[diagnostic::on_unimplemented(
184 message = "the trait `IntoView` is not implemented for `{Self}` (consider calling `.as_view()` \
185 or borrowing)",
186 note = "consider calling `.as_view()` or `.into_view()`"
187)]
188pub trait IntoView<'msg>: SealedInternal + AsView {
189 /// Converts into a `View` with a potentially shorter lifetime.
190 ///
191 /// In non-generic code we don't need to use `into_view` because the proxy
192 /// types are covariant over `'msg`. However, generic code conservatively
193 /// treats `'msg` as [invariant], therefore we need to call
194 /// `into_view` to explicitly perform the operation that in concrete
195 /// code coercion would perform implicitly.
196 ///
197 /// ```ignore
198 /// fn reborrow_generic_view_into_view<'a, 'b, T>(
199 /// x: View<'a, T>,
200 /// y: View<'b, T>,
201 /// ) -> [View<'b, T>; 2]
202 /// where
203 /// T: MutProtoObject,
204 /// 'a: 'b,
205 /// {
206 /// // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `View`
207 /// // lifetime parameter is (conservatively) invariant.
208 /// // `[x.as_view(), y]` fails because that borrow cannot outlive `'b`.
209 /// [x.into_view(), y]
210 /// }
211 /// ```
212 ///
213 /// [invariant]: https://doc.rust-lang.org/nomicon/subtyping.html#variance
214 fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied>
215 where
216 'msg: 'shorter;
217}
218
219impl<'msg, T: ProtoObject> IntoView<'msg> for &'msg T {
220 fn into_view<'shorter>(self) -> View<'shorter, T>
221 where
222 'msg: 'shorter,
223 {
224 (*self).as_view()
225 }
226}
227
228impl<'msg, T: ProtoObject> IntoView<'msg> for &'msg mut T {
229 fn into_view<'shorter>(self) -> View<'shorter, T>
230 where
231 'msg: 'shorter,
232 {
233 (*self).as_view()
234 }
235}
236
237/// Used to semantically do a cheap "to-mut-reference" conversion. This is
238/// implemented on both owned `ProtoObject` types as well as mut proxy types.
239///
240/// On a mut proxy this will behave as a reborrow into a shorter lifetime.
241#[diagnostic::on_unimplemented(
242 message = "the trait `AsMut` is not implemented for `{Self}`",
243 note = "consider calling `.as_mut()`, or changing the fn to accept \
244 `impl AsMut<MutProxied = T>`"
245)]
246pub trait AsMut: SealedInternal + AsView<Proxied = Self::MutProxied> {
247 type MutProxied: MutProtoObject;
248
249 /// Converts a borrow into a `Mut` with the lifetime of that borrow.
250 fn as_mut(&mut self) -> Mut<'_, Self::MutProxied>;
251}
252
253impl<T: MutProtoObject> AsMut for &mut T {
254 type MutProxied = T::MutProxied;
255 fn as_mut(&mut self) -> Mut<'_, Self::MutProxied> {
256 (*self).as_mut()
257 }
258}
259
260/// Used to turn another 'borrow' into a mut proxy.
261///
262/// On a mut proxy this will behave as a reborrow into a shorter lifetime
263/// (semantically matching a `&mut 'a T` into a `&mut 'b T` where `'a: 'b`).
264#[diagnostic::on_unimplemented(
265 message = "the trait `IntoMut` is not implemented for `{Self}` (consider calling `.as_mut()` \
266 or mutably borrowing)",
267 note = "consider calling `.as_mut()` or `.into_mut()`"
268)]
269pub trait IntoMut<'msg>: SealedInternal + AsMut {
270 /// Converts into a `Mut` with a potentially shorter lifetime.
271 ///
272 /// In non-generic code we don't need to use `into_mut` because the proxy
273 /// types are covariant over `'msg`. However, generic code conservatively
274 /// treats `'msg` as [invariant], therefore we need to call
275 /// `into_mut` to explicitly perform the operation that in concrete code
276 /// coercion would perform implicitly.
277 ///
278 /// ```ignore
279 /// fn reborrow_generic_mut_into_mut<'a, 'b, T>(x: Mut<'a, T>, y: Mut<'b, T>) -> [Mut<'b, T>; 2]
280 /// where
281 /// T: ProtoObject,
282 /// 'a: 'b,
283 /// {
284 /// // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `Mut`
285 /// // lifetime parameter is (conservatively) invariant.
286 /// // `[x.as_mut(), y]` fails because that borrow cannot outlive `'b`.
287 /// [x.into_mut(), y]
288 /// }
289 /// ```
290 ///
291 /// [invariant]: https://doc.rust-lang.org/nomicon/subtyping.html#variance
292 fn into_mut<'shorter>(self) -> Mut<'shorter, Self::MutProxied>
293 where
294 'msg: 'shorter;
295}
296
297impl<'msg, T: MutProtoObject> IntoMut<'msg> for &'msg mut T {
298 fn into_mut<'shorter>(self) -> Mut<'shorter, T>
299 where
300 'msg: 'shorter,
301 {
302 (*self).as_mut()
303 }
304}
305
306/// A value to `ProtoObject`-value conversion that consumes the input value.
307///
308/// All setter functions accept types that implement `IntoProxied`. The purpose
309/// of `IntoProxied` is to allow setting arbitrary values on Protobuf fields
310/// with the minimal number of copies.
311///
312/// This trait must not be implemented on types outside the Protobuf codegen and
313/// runtime. We expect it to change in backwards incompatible ways in the
314/// future.
315pub trait IntoProxied<T: ProtoObject> {
316 #[doc(hidden)]
317 fn into_proxied(self, _private: Private) -> T;
318}
319
320impl<T: ProtoObject> IntoProxied<T> for T {
321 fn into_proxied(self, _private: Private) -> T {
322 self
323 }
324}
325
326#[cfg(test)]
327mod tests {
328 use super::*;
329 use googletest::prelude::*;
330
331 #[derive(Debug, Default, PartialEq)]
332 struct MyProxied {
333 val: String,
334 }
335
336 impl MyProxied {
337 fn as_view(&self) -> View<'_, Self> {
338 MyProxiedView { my_proxied_ref: self }
339 }
340
341 fn as_mut(&mut self) -> Mut<'_, Self> {
342 MyProxiedMut { my_proxied_ref: self }
343 }
344 }
345
346 impl SealedInternal for MyProxied {}
347
348 impl ProtoObject for MyProxied {
349 type View<'msg> = MyProxiedView<'msg>;
350 }
351
352 #[gtest]
353 #[allow(deprecated)]
354 fn test_deprecated_proxied_alias() {
355 fn check_proxied<T: Proxied>() {}
356 check_proxied::<MyProxied>();
357 fn check_mut_proxied<T: MutProxied>() {}
358 check_mut_proxied::<MyProxied>();
359 }
360
361 impl AsView for MyProxied {
362 type Proxied = Self;
363 fn as_view(&self) -> MyProxiedView<'_> {
364 self.as_view()
365 }
366 }
367
368 impl MutProtoObject for MyProxied {
369 type Mut<'msg> = MyProxiedMut<'msg>;
370 }
371
372 impl AsMut for MyProxied {
373 type MutProxied = Self;
374 fn as_mut(&mut self) -> MyProxiedMut<'_> {
375 self.as_mut()
376 }
377 }
378
379 #[derive(Debug, Clone, Copy)]
380 struct MyProxiedView<'msg> {
381 my_proxied_ref: &'msg MyProxied,
382 }
383
384 impl<'msg> SealedInternal for MyProxiedView<'msg> {}
385
386 impl MyProxiedView<'_> {
387 fn val(&self) -> &str {
388 &self.my_proxied_ref.val
389 }
390 }
391
392 impl<'msg> AsView for MyProxiedView<'msg> {
393 type Proxied = MyProxied;
394
395 fn as_view(&self) -> MyProxiedView<'msg> {
396 *self
397 }
398 }
399
400 impl<'msg> IntoView<'msg> for MyProxiedView<'msg> {
401 fn into_view<'shorter>(self) -> MyProxiedView<'shorter>
402 where
403 'msg: 'shorter,
404 {
405 self
406 }
407 }
408
409 #[derive(Debug)]
410 struct MyProxiedMut<'msg> {
411 my_proxied_ref: &'msg mut MyProxied,
412 }
413
414 impl<'msg> SealedInternal for MyProxiedMut<'msg> {}
415
416 impl<'msg> AsView for MyProxiedMut<'msg> {
417 type Proxied = MyProxied;
418
419 fn as_view(&self) -> MyProxiedView<'_> {
420 MyProxiedView { my_proxied_ref: self.my_proxied_ref }
421 }
422 }
423
424 impl<'msg> IntoView<'msg> for MyProxiedMut<'msg> {
425 fn into_view<'shorter>(self) -> View<'shorter, MyProxied>
426 where
427 'msg: 'shorter,
428 {
429 MyProxiedView { my_proxied_ref: self.my_proxied_ref }
430 }
431 }
432
433 impl<'msg> AsMut for MyProxiedMut<'msg> {
434 type MutProxied = MyProxied;
435
436 fn as_mut(&mut self) -> MyProxiedMut<'_> {
437 MyProxiedMut { my_proxied_ref: self.my_proxied_ref }
438 }
439 }
440
441 impl<'msg> IntoMut<'msg> for MyProxiedMut<'msg> {
442 fn into_mut<'shorter>(self) -> MyProxiedMut<'shorter>
443 where
444 'msg: 'shorter,
445 {
446 self
447 }
448 }
449
450 #[gtest]
451 fn test_as_view() {
452 let my_proxied = MyProxied { val: "Hello World".to_string() };
453
454 let my_view = my_proxied.as_view();
455
456 assert_that!(my_view.val(), eq(&my_proxied.val));
457 }
458
459 fn reborrow_mut_into_view<'msg>(x: Mut<'msg, MyProxied>) -> View<'msg, MyProxied> {
460 // x.as_view() fails to compile with:
461 // `ERROR: attempt to return function-local borrowed content`
462 x.into_view() // OK: we return the same lifetime as we got in.
463 }
464
465 #[gtest]
466 fn test_mut_into_view() {
467 let mut my_proxied = MyProxied { val: "Hello World".to_string() };
468 reborrow_mut_into_view(my_proxied.as_mut());
469 }
470
471 fn require_unified_lifetimes<'msg>(_x: Mut<'msg, MyProxied>, _y: View<'msg, MyProxied>) {}
472
473 #[gtest]
474 fn test_require_unified_lifetimes() {
475 let mut my_proxied = MyProxied { val: "Hello1".to_string() };
476 let my_mut = my_proxied.as_mut();
477
478 {
479 let other_proxied = MyProxied { val: "Hello2".to_string() };
480 let other_view = other_proxied.as_view();
481 require_unified_lifetimes(my_mut, other_view);
482 }
483 }
484
485 fn reborrow_generic_as_view<'a, 'b, T>(
486 x: &'b mut Mut<'a, T>,
487 y: &'b View<'a, T>,
488 ) -> [View<'b, T>; 2]
489 where
490 T: MutProtoObject,
491 'a: 'b,
492 {
493 // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `View`
494 // lifetime parameter is (conservatively) invariant.
495 [x.as_view(), y.as_view()]
496 }
497
498 #[gtest]
499 fn test_reborrow_generic_as_view() {
500 let mut my_proxied = MyProxied { val: "Hello1".to_string() };
501 let mut my_mut = my_proxied.as_mut();
502 let my_ref = &mut my_mut;
503
504 {
505 let other_proxied = MyProxied { val: "Hello2".to_string() };
506 let other_view = other_proxied.as_view();
507 reborrow_generic_as_view::<MyProxied>(my_ref, &other_view);
508 }
509 }
510
511 fn reborrow_generic_view_into_view<'a, 'b, T>(
512 x: View<'a, T>,
513 y: View<'b, T>,
514 ) -> [View<'b, T>; 2]
515 where
516 T: ProtoObject,
517 'a: 'b,
518 {
519 // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `View`
520 // lifetime parameter is (conservatively) invariant.
521 // `[x.as_view(), y]` fails because that borrow cannot outlive `'b`.
522 [x.into_view(), y]
523 }
524
525 #[gtest]
526 fn test_reborrow_generic_into_view() {
527 let my_proxied = MyProxied { val: "Hello1".to_string() };
528 let my_view = my_proxied.as_view();
529
530 {
531 let other_proxied = MyProxied { val: "Hello2".to_string() };
532 let other_view = other_proxied.as_view();
533 reborrow_generic_view_into_view::<MyProxied>(my_view, other_view);
534 }
535 }
536
537 fn reborrow_generic_mut_into_view<'a, 'b, T>(x: Mut<'a, T>, y: View<'b, T>) -> [View<'b, T>; 2]
538 where
539 T: MutProtoObject,
540 'a: 'b,
541 {
542 [x.into_view(), y]
543 }
544
545 #[gtest]
546 fn test_reborrow_generic_mut_into_view() {
547 let mut my_proxied = MyProxied { val: "Hello1".to_string() };
548 let my_mut = my_proxied.as_mut();
549
550 {
551 let other_proxied = MyProxied { val: "Hello2".to_string() };
552 let other_view = other_proxied.as_view();
553 reborrow_generic_mut_into_view::<MyProxied>(my_mut, other_view);
554 }
555 }
556
557 fn reborrow_generic_mut_into_mut<'a, 'b, T>(x: Mut<'a, T>, y: Mut<'b, T>) -> [Mut<'b, T>; 2]
558 where
559 T: MutProtoObject,
560 'a: 'b,
561 {
562 // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `Mut`
563 // lifetime parameter is (conservatively) invariant.
564 // `[x.as_mut(), y]` fails because that borrow cannot outlive `'b`.
565 let tmp: Mut<'b, T> = x.into_mut();
566 [tmp, y]
567 }
568
569 #[gtest]
570 fn test_reborrow_generic_mut_into_mut() {
571 let mut my_proxied = MyProxied { val: "Hello1".to_string() };
572 let my_mut = my_proxied.as_mut();
573
574 {
575 let mut other_proxied = MyProxied { val: "Hello2".to_string() };
576 let other_mut = other_proxied.as_mut();
577 // No need to reborrow, even though lifetime of &other_view is different
578 // than the lifetiem of my_ref. Rust references are covariant over their
579 // lifetime.
580 reborrow_generic_mut_into_mut::<MyProxied>(my_mut, other_mut);
581 }
582 }
583
584 // Functions written the way the `#[diagnostic::on_unimplemented]` notes suggest: accepting a
585 // generic proxy bound rather than a concrete view or mut proxy.
586 fn accepts_as_view(_: impl AsView<Proxied = MyProxied>) {}
587 fn accepts_as_mut(_: impl AsMut<MutProxied = MyProxied>) {}
588 fn accepts_into_view<'a>(_: impl IntoView<'a, Proxied = MyProxied>) {}
589 fn accepts_into_mut<'a>(_: impl IntoMut<'a, MutProxied = MyProxied>) {}
590
591 #[gtest]
592 fn test_suggested_conversions_satisfy_proxy_bounds() {
593 let mut my_proxied = MyProxied { val: "Hello".to_string() };
594
595 // Callers of an `impl AsView` / `impl AsMut` function don't need to write `.as_view()` or
596 // `.as_mut()` at all; a plain borrow suffices.
597 accepts_as_view(&my_proxied);
598 accepts_as_mut(&mut my_proxied);
599
600 // Explicitly converting, as the notes suggest at the call site, also satisfies the bounds.
601 accepts_as_view(my_proxied.as_view());
602 accepts_as_mut(my_proxied.as_mut());
603
604 // A view is not itself `AsMut`, but reborrowing a mut proxy is.
605 let mut my_mut = my_proxied.as_mut();
606 accepts_as_view(my_mut.as_view());
607 accepts_as_mut(my_mut.as_mut());
608
609 // The `IntoView` / `IntoMut` bounds additionally accept a borrow directly, which is what
610 // rustc suggests when an owned message is passed to them.
611 accepts_into_view(&my_proxied);
612 accepts_into_mut(&mut my_proxied);
613 accepts_into_view(my_proxied.as_view());
614 accepts_into_mut(my_proxied.as_mut());
615 }
616}