Skip to content

Commit 1a2dd94

Browse files
Additional explanation on the rule
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
1 parent e0eee5f commit 1a2dd94

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/core/src/ops/unsize.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *
113113
/// `DispatchFromDyn<FTarget>` where `FTarget` is the type of the corresponding coerced field in
114114
/// `T`.
115115
///
116+
/// Note that we do not support the case where multiple pointer narrowings or downcasting of trait
117+
/// objects into concrete objects are involved in coercing one type to another through
118+
/// the `DispatchFromDyn` trait.
119+
/// For instance, we do not support dispatch from `&Arc<dyn Tr>` to `&Arc<T>`.
120+
/// `&Arc<dyn Tr>` is already behind an immutable reference while the coercion would require a
121+
/// downcasting of the trait object `Arc<dyn Tr>` by chipping of the virtual table.
122+
/// This will break the invariant of an immutable reference that the place behind shall remain
123+
/// not mutated during the access.
124+
/// Similarly, the dispatch from `Box<Box<dyn Tr>>` to `Box<Box<T>>` also requires a similar memory
125+
/// layout change.
126+
/// Therefore, this category of coercion is not supported.
127+
///
116128
/// An example implementation of the trait:
117129
///
118130
/// ```

0 commit comments

Comments
 (0)