Skip to content

Commit 885e3d1

Browse files
committed
Library: Rename "object safe" to "dyn compatible"
1 parent bab810c commit 885e3d1

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

core/src/cell.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ impl<T: Default> Cell<T> {
661661
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
662662

663663
// Allow types that wrap `Cell` to also implement `DispatchFromDyn`
664-
// and become object safe method receivers.
664+
// and become dyn-compatible method receivers.
665665
// Note that currently `Cell` itself cannot be a method receiver
666666
// because it does not implement Deref.
667667
// In other words:
@@ -2236,7 +2236,7 @@ impl<T> From<T> for UnsafeCell<T> {
22362236
impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22372237

22382238
// Allow types that wrap `UnsafeCell` to also implement `DispatchFromDyn`
2239-
// and become object safe method receivers.
2239+
// and become dyn-compatible method receivers.
22402240
// Note that currently `UnsafeCell` itself cannot be a method receiver
22412241
// because it does not implement Deref.
22422242
// In other words:
@@ -2379,7 +2379,7 @@ impl<T> From<T> for SyncUnsafeCell<T> {
23792379
impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
23802380

23812381
// Allow types that wrap `SyncUnsafeCell` to also implement `DispatchFromDyn`
2382-
// and become object safe method receivers.
2382+
// and become dyn-compatible method receivers.
23832383
// Note that currently `SyncUnsafeCell` itself cannot be a method receiver
23842384
// because it does not implement Deref.
23852385
// In other words:

core/src/error.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,17 @@ impl dyn Error {
335335
#[unstable(feature = "error_iter", issue = "58520")]
336336
#[inline]
337337
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.
348349

349350
Source { current: Some(self) }
350351
}

core/src/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::cmp::{self, Ordering};
99
use crate::num::NonZero;
1010
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};
1111

12-
fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
12+
fn _assert_is_dyn_compatible(_: &dyn Iterator<Item = ()>) {}
1313

1414
/// A trait for dealing with iterators.
1515
///

core/src/marker.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub trait Sized {
158158
/// - Arrays `[T; N]` implement `Unsize<[T]>`.
159159
/// - A type implements `Unsize<dyn Trait + 'a>` if all of these conditions are met:
160160
/// - The type implements `Trait`.
161-
/// - `Trait` is object safe.
161+
/// - `Trait` is dyn-compatible[^1].
162162
/// - The type is sized.
163163
/// - The type outlives `'a`.
164164
/// - Structs `Foo<..., T1, ..., Tn, ...>` implement `Unsize<Foo<..., U1, ..., Un, ...>>`
@@ -178,6 +178,7 @@ pub trait Sized {
178178
/// [`Rc`]: ../../std/rc/struct.Rc.html
179179
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
180180
/// [nomicon-coerce]: ../../nomicon/coercions.html
181+
/// [^1]: Formerly known as *object safe*.
181182
#[unstable(feature = "unsize", issue = "18598")]
182183
#[lang = "unsize"]
183184
#[rustc_deny_explicit_impl(implement_via_object = false)]

core/src/ops/unsize.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
6868
#[unstable(feature = "coerce_unsized", issue = "18598")]
6969
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
7070

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.
7373
///
7474
/// Note: `DispatchFromDyn` was briefly named `CoerceSized` (and had a slightly different
7575
/// interpretation).
@@ -80,7 +80,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
8080
/// type). The compiler must generate an implicit conversion from the trait object/wide pointer to
8181
/// the concrete reference/narrow pointer. Implementing `DispatchFromDyn` indicates that that
8282
/// 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
8484
/// `DispatchFromDyn` is implemented for `&'a U`).
8585
///
8686
/// `DispatchFromDyn` does not specify the conversion from wide pointer to narrow pointer; the
@@ -112,6 +112,8 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
112112
/// T: Unsize<U>,
113113
/// {}
114114
/// ```
115+
///
116+
/// [^1]: Formerly known as *object safety*.
115117
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
116118
#[lang = "dispatch_from_dyn"]
117119
pub trait DispatchFromDyn<T> {

core/tests/hash/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn test_indirect_hasher() {
164164
}
165165

166166
#[test]
167-
fn test_build_hasher_object_safe() {
167+
fn test_build_hasher_dyn_compatible() {
168168
use std::hash::{DefaultHasher, RandomState};
169169

170170
let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();

std/src/keyword_docs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2349,12 +2349,13 @@ mod async_keyword {}
23492349
/// [`async`]: ../std/keyword.async.html
23502350
mod await_keyword {}
23512351

2352+
// FIXME(dyn_compat_renaming): Update URL and link text.
23522353
#[doc(keyword = "dyn")]
23532354
//
23542355
/// `dyn` is a prefix of a [trait object]'s type.
23552356
///
23562357
/// 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].
23582359
///
23592360
/// Unlike generic parameters or `impl Trait`, the compiler does not know the concrete type that
23602361
/// is being passed. That is, the type has been [erased].
@@ -2382,6 +2383,7 @@ mod await_keyword {}
23822383
/// [ref-trait-obj]: ../reference/types/trait-object.html
23832384
/// [ref-obj-safety]: ../reference/items/traits.html#object-safety
23842385
/// [erased]: https://en.wikipedia.org/wiki/Type_erasure
2386+
/// [^1]: Formerly known as 'object safe'.
23852387
mod dyn_keyword {}
23862388

23872389
#[doc(keyword = "union")]

0 commit comments

Comments
 (0)