Library: Rename "object safe" to "dyn compatible"
This commit is contained in:
@@ -335,16 +335,17 @@ impl dyn Error {
|
||||
#[unstable(feature = "error_iter", issue = "58520")]
|
||||
#[inline]
|
||||
pub fn sources(&self) -> Source<'_> {
|
||||
// You may think this method would be better in the Error trait, and you'd be right.
|
||||
// Unfortunately that doesn't work, not because of the object safety rules but because we
|
||||
// save a reference to self in Sources below as a trait object. If this method was
|
||||
// declared in Error, then self would have the type &T where T is some concrete type which
|
||||
// implements Error. We would need to coerce self to have type &dyn Error, but that requires
|
||||
// that Self has a known size (i.e., Self: Sized). We can't put that bound on Error
|
||||
// since that would forbid Error trait objects, and we can't put that bound on the method
|
||||
// because that means the method can't be called on trait objects (we'd also need the
|
||||
// 'static bound, but that isn't allowed because methods with bounds on Self other than
|
||||
// Sized are not object-safe). Requiring an Unsize bound is not backwards compatible.
|
||||
// You may think this method would be better in the `Error` trait, and you'd be right.
|
||||
// Unfortunately that doesn't work, not because of the dyn-incompatibility rules but
|
||||
// because we save a reference to `self` in `Source`s below as a trait object.
|
||||
// If this method was declared in `Error`, then `self` would have the type `&T` where
|
||||
// `T` is some concrete type which implements `Error`. We would need to coerce `self`
|
||||
// to have type `&dyn Error`, but that requires that `Self` has a known size
|
||||
// (i.e., `Self: Sized`). We can't put that bound on `Error` since that would forbid
|
||||
// `Error` trait objects, and we can't put that bound on the method because that means
|
||||
// the method can't be called on trait objects (we'd also need the `'static` bound,
|
||||
// but that isn't allowed because methods with bounds on `Self` other than `Sized` are
|
||||
// dyn-incompatible). Requiring an `Unsize` bound is not backwards compatible.
|
||||
|
||||
Source { current: Some(self) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user