Rollup merge of #64203 - alexreg:rush-pr-2, r=centril
A few cosmetic improvements to code & comments in liballoc and libcore Factored out from hacking on rustc for work on the REPL. r? @Centril
This commit is contained in:
@@ -197,10 +197,10 @@ pub trait Error: Debug + Display {
|
||||
#[stable(feature = "error_source", since = "1.30.0")]
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> { None }
|
||||
|
||||
/// Gets the `TypeId` of `self`
|
||||
/// Gets the `TypeId` of `self`.
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "error_type_id",
|
||||
reason = "this is memory unsafe to override in user code",
|
||||
reason = "this is memory-unsafe to override in user code",
|
||||
issue = "60784")]
|
||||
fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static {
|
||||
TypeId::of::<Self>()
|
||||
@@ -616,19 +616,19 @@ impl Error for char::ParseCharError {
|
||||
}
|
||||
}
|
||||
|
||||
// copied from any.rs
|
||||
// Copied from `any.rs`.
|
||||
impl dyn Error + 'static {
|
||||
/// Returns `true` if the boxed type is the same as `T`
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
// Get TypeId of the type this function is instantiated with
|
||||
// Get `TypeId` of the type this function is instantiated with.
|
||||
let t = TypeId::of::<T>();
|
||||
|
||||
// Get TypeId of the type in the trait object
|
||||
// Get `TypeId` of the type in the trait object.
|
||||
let boxed = self.type_id(private::Internal);
|
||||
|
||||
// Compare both TypeIds on equality
|
||||
// Compare both `TypeId`s on equality.
|
||||
t == boxed
|
||||
}
|
||||
|
||||
@@ -662,21 +662,21 @@ impl dyn Error + 'static {
|
||||
}
|
||||
|
||||
impl dyn Error + 'static + Send {
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
<dyn Error + 'static>::is::<T>(self)
|
||||
}
|
||||
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
|
||||
<dyn Error + 'static>::downcast_ref::<T>(self)
|
||||
}
|
||||
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
|
||||
@@ -685,21 +685,21 @@ impl dyn Error + 'static + Send {
|
||||
}
|
||||
|
||||
impl dyn Error + 'static + Send + Sync {
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
<dyn Error + 'static>::is::<T>(self)
|
||||
}
|
||||
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
|
||||
<dyn Error + 'static>::downcast_ref::<T>(self)
|
||||
}
|
||||
|
||||
/// Forwards to the method defined on the type `Any`.
|
||||
/// Forwards to the method defined on the type `dyn Error`.
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
#[inline]
|
||||
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
|
||||
@@ -710,7 +710,7 @@ impl dyn Error + 'static + Send + Sync {
|
||||
impl dyn Error {
|
||||
#[inline]
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
/// Attempt to downcast the box to a concrete type.
|
||||
/// Attempts to downcast the box to a concrete type.
|
||||
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> {
|
||||
if self.is::<T>() {
|
||||
unsafe {
|
||||
@@ -878,12 +878,12 @@ impl<'a> Iterator for ErrorIter<'a> {
|
||||
impl dyn Error + Send {
|
||||
#[inline]
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
/// Attempt to downcast the box to a concrete type.
|
||||
/// Attempts to downcast the box to a concrete type.
|
||||
pub fn downcast<T: Error + 'static>(self: Box<Self>)
|
||||
-> Result<Box<T>, Box<dyn Error + Send>> {
|
||||
let err: Box<dyn Error> = self;
|
||||
<dyn Error>::downcast(err).map_err(|s| unsafe {
|
||||
// reapply the Send marker
|
||||
// Reapply the `Send` marker.
|
||||
transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
|
||||
})
|
||||
}
|
||||
@@ -892,12 +892,12 @@ impl dyn Error + Send {
|
||||
impl dyn Error + Send + Sync {
|
||||
#[inline]
|
||||
#[stable(feature = "error_downcast", since = "1.3.0")]
|
||||
/// Attempt to downcast the box to a concrete type.
|
||||
/// Attempts to downcast the box to a concrete type.
|
||||
pub fn downcast<T: Error + 'static>(self: Box<Self>)
|
||||
-> Result<Box<T>, Box<Self>> {
|
||||
let err: Box<dyn Error> = self;
|
||||
<dyn Error>::downcast(err).map_err(|s| unsafe {
|
||||
// reapply the Send+Sync marker
|
||||
// Reapply the `Send + Sync` marker.
|
||||
transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user