Rollup merge of #130827 - fmease:library-mv-obj-save-dyn-compat, r=ib… · qinheping/verify-rust-std@136ec3a (original) (raw)
7 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -666,7 +666,7 @@ impl<T: Default> Cell { | ||
666 | 666 | impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {} |
667 | 667 | |
668 | 668 | // Allow types that wrap `Cell` to also implement `DispatchFromDyn` |
669 | -// and become object safe method receivers. | |
669 | +// and become dyn-compatible method receivers. | |
670 | 670 | // Note that currently `Cell` itself cannot be a method receiver |
671 | 671 | // because it does not implement Deref. |
672 | 672 | // In other words: |
@@ -2247,7 +2247,7 @@ impl From for UnsafeCell { | ||
2247 | 2247 | impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {} |
2248 | 2248 | |
2249 | 2249 | // Allow types that wrap `UnsafeCell` to also implement `DispatchFromDyn` |
2250 | -// and become object safe method receivers. | |
2250 | +// and become dyn-compatible method receivers. | |
2251 | 2251 | // Note that currently `UnsafeCell` itself cannot be a method receiver |
2252 | 2252 | // because it does not implement Deref. |
2253 | 2253 | // In other words: |
@@ -2349,7 +2349,7 @@ impl From for SyncUnsafeCell { | ||
2349 | 2349 | impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {} |
2350 | 2350 | |
2351 | 2351 | // Allow types that wrap `SyncUnsafeCell` to also implement `DispatchFromDyn` |
2352 | -// and become object safe method receivers. | |
2352 | +// and become dyn-compatible method receivers. | |
2353 | 2353 | // Note that currently `SyncUnsafeCell` itself cannot be a method receiver |
2354 | 2354 | // because it does not implement Deref. |
2355 | 2355 | // In other words: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -335,16 +335,17 @@ impl dyn Error { | ||
335 | 335 | #[unstable(feature = "error_iter", issue = "58520")] |
336 | 336 | #[inline] |
337 | 337 | pub fn sources(&self) -> Source<'_> { |
338 | -// You may think this method would be better in the Error trait, and you'd be right. | |
339 | -// Unfortunately that doesn't work, not because of the object safety rules but because we | |
340 | -// save a reference to self in Sources below as a trait object. If this method was | |
341 | -// declared in Error, then self would have the type &T where T is some concrete type which | |
342 | -// implements Error. We would need to coerce self to have type &dyn Error, but that requires | |
343 | -// that Self has a known size (i.e., Self: Sized). We can't put that bound on Error | |
344 | -// since that would forbid Error trait objects, and we can't put that bound on the method | |
345 | -// because that means the method can't be called on trait objects (we'd also need the | |
346 | -// 'static bound, but that isn't allowed because methods with bounds on Self other than | |
347 | -// Sized are not object-safe). Requiring an Unsize bound is not backwards compatible. | |
338 | +// You may think this method would be better in the `Error` trait, and you'd be right. | |
339 | +// Unfortunately that doesn't work, not because of the dyn-incompatibility rules but | |
340 | +// because we save a reference to `self` in `Source`s below as a trait object. | |
341 | +// If this method was declared in `Error`, then `self` would have the type `&T` where | |
342 | +// `T` is some concrete type which implements `Error`. We would need to coerce `self` | |
343 | +// to have type `&dyn Error`, but that requires that `Self` has a known size | |
344 | +// (i.e., `Self: Sized`). We can't put that bound on `Error` since that would forbid | |
345 | +// `Error` trait objects, and we can't put that bound on the method because that means | |
346 | +// the method can't be called on trait objects (we'd also need the `'static` bound, | |
347 | +// but that isn't allowed because methods with bounds on `Self` other than `Sized` are | |
348 | +// dyn-incompatible). Requiring an `Unsize` bound is not backwards compatible. | |
348 | 349 | |
349 | 350 | Source { current: Some(self) } |
350 | 351 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,7 +9,7 @@ use crate::cmp::{self, Ordering}; | ||
9 | 9 | use crate::num::NonZero; |
10 | 10 | use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try}; |
11 | 11 | |
12 | -fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {} | |
12 | +fn _assert_is_dyn_compatible(_: &dyn Iterator<Item = ()>) {} | |
13 | 13 | |
14 | 14 | /// A trait for dealing with iterators. |
15 | 15 | /// |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -158,7 +158,7 @@ pub trait Sized { | ||
158 | 158 | /// - Arrays `[T; N]` implement `Unsize<[T]>`. |
159 | 159 | /// - A type implements `Unsize<dyn Trait + 'a>` if all of these conditions are met: |
160 | 160 | /// - The type implements `Trait`. |
161 | -/// - `Trait` is object safe. | |
161 | +/// - `Trait` is dyn-compatible[^1]. | |
162 | 162 | /// - The type is sized. |
163 | 163 | /// - The type outlives `'a`. |
164 | 164 | /// - Structs `Foo<..., T1, ..., Tn, ...>` implement `Unsize<Foo<..., U1, ..., Un, ...>>` |
@@ -178,6 +178,7 @@ pub trait Sized { | ||
178 | 178 | /// [`Rc`]: ../../std/rc/struct.Rc.html |
179 | 179 | /// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md |
180 | 180 | /// [nomicon-coerce]: ../../nomicon/coercions.html |
181 | +/// [^1]: Formerly known as *object safe*. | |
181 | 182 | #[unstable(feature = "unsize", issue = "18598")] |
182 | 183 | #[lang = "unsize"] |
183 | 184 | #[rustc_deny_explicit_impl(implement_via_object = false)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -68,8 +68,8 @@ impl<T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*const U> for *mut T {} | ||
68 | 68 | #[unstable(feature = "coerce_unsized", issue = "18598")] |
69 | 69 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {} |
70 | 70 | |
71 | -/// `DispatchFromDyn` is used in the implementation of object safety checks (specifically allowing | |
72 | -/// arbitrary self types), to guarantee that a method's receiver type can be dispatched on. | |
71 | +/// `DispatchFromDyn` is used in the implementation of dyn-compatibility[^1] checks (specifically | |
72 | +/// allowing arbitrary self types), to guarantee that a method's receiver type can be dispatched on. | |
73 | 73 | /// |
74 | 74 | /// Note: `DispatchFromDyn` was briefly named `CoerceSized` (and had a slightly different |
75 | 75 | /// interpretation). |
@@ -80,7 +80,7 @@ impl<T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*const U> for *const T {} | ||
80 | 80 | /// type). The compiler must generate an implicit conversion from the trait object/wide pointer to |
81 | 81 | /// the concrete reference/narrow pointer. Implementing `DispatchFromDyn` indicates that that |
82 | 82 | /// conversion is allowed and thus that the type implementing `DispatchFromDyn` is safe to use as |
83 | -/// the self type in an object-safe method. (in the above example, the compiler will require | |
83 | +/// the self type in an dyn-compatible method. (in the above example, the compiler will require | |
84 | 84 | /// `DispatchFromDyn` is implemented for `&'a U`). |
85 | 85 | /// |
86 | 86 | /// `DispatchFromDyn` does not specify the conversion from wide pointer to narrow pointer; the |
@@ -112,6 +112,8 @@ impl<T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*const U> for *const T {} | ||
112 | 112 | /// T: Unsize, |
113 | 113 | /// {} |
114 | 114 | /// ``` |
115 | +/// | |
116 | +/// [^1]: Formerly known as *object safety*. | |
115 | 117 | #[unstable(feature = "dispatch_from_dyn", issue = "none")] |
116 | 118 | #[lang = "dispatch_from_dyn"] |
117 | 119 | pub trait DispatchFromDyn<T> { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -164,7 +164,7 @@ fn test_indirect_hasher() { | ||
164 | 164 | } |
165 | 165 | |
166 | 166 | #[test] |
167 | -fn test_build_hasher_object_safe() { | |
167 | +fn test_build_hasher_dyn_compatible() { | |
168 | 168 | use std::hash::{DefaultHasher, RandomState}; |
169 | 169 | |
170 | 170 | let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2349,12 +2349,13 @@ mod async_keyword {} | ||
2349 | 2349 | /// [`async`]: ../std/keyword.async.html |
2350 | 2350 | mod await_keyword {} |
2351 | 2351 | |
2352 | +// FIXME(dyn_compat_renaming): Update URL and link text. | |
2352 | 2353 | #[doc(keyword = "dyn")] |
2353 | 2354 | // |
2354 | 2355 | /// `dyn` is a prefix of a [trait object]'s type. |
2355 | 2356 | /// |
2356 | 2357 | /// The `dyn` keyword is used to highlight that calls to methods on the associated `Trait` |
2357 | -/// are [dynamically dispatched]. To use the trait this way, it must be 'object safe'. | |
2358 | +/// are [dynamically dispatched]. To use the trait this way, it must be 'dyn-compatible'[^1]. | |
2358 | 2359 | /// |
2359 | 2360 | /// Unlike generic parameters or `impl Trait`, the compiler does not know the concrete type that |
2360 | 2361 | /// is being passed. That is, the type has been [erased]. |
@@ -2382,6 +2383,7 @@ mod await_keyword {} | ||
2382 | 2383 | /// [ref-trait-obj]: ../reference/types/trait-object.html |
2383 | 2384 | /// [ref-obj-safety]: ../reference/items/traits.html#object-safety |
2384 | 2385 | /// [erased]: https://en.wikipedia.org/wiki/Type\_erasure |
2386 | +/// [^1]: Formerly known as 'object safe'. | |
2385 | 2387 | mod dyn_keyword {} |
2386 | 2388 | |
2387 | 2389 | #[doc(keyword = "union")] |