Repository: actix/actix-web
File: actix-http/src/error.rs (Rust)

Code before:
pub trait ResponseError: fmt::Debug + fmt::Display {
    /// Response's status code
    ///
    /// Internal server error is generated by default.
    fn status_code(&self) -> StatusCode {
        StatusCode::INTERNAL_SERVER_ERROR
    }

    /// Create response for error
    ///
    /// Internal server error is generated by default.
    fn error_response(&self) -> Response {
        let mut resp = Response::new(self.status_code());
        let mut buf = BytesMut::new();
        let _ = write!(Writer(&mut buf), "{}", self);
        resp.headers_mut().insert(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain; charset=utf-8"),
        );
        resp.set_body(Body::from(buf))
    }

    /// A helper method to get the type ID of the type
    /// this trait is implemented on.
    /// This method is unsafe to *implement*, since `downcast_ref` relies
    /// on the returned `TypeId` to perform an cast.
    ///
    /// Unfortunately, Rust has no notion of a trait method that is
    /// unsafe to implement (marking it as `unsafe` makes it unsafe
    /// to *call*). As a workaround, we require this method
    /// to return a private type along with the `TypeId`. This
    /// private type (`PrivateHelper`) has a private constructor,
    /// making it impossible for safe code to construct outside of
    /// this module. This ensures that safe code cannot violate
    /// type-safety by implementing this method.
    #[doc(hidden)]
    fn __private_get_type_id__(&self) -> (TypeId, PrivateHelper)
    where
        Self: 'static,
    {
        (TypeId::of::<Self>(), PrivateHelper(()))
    }
}

impl dyn ResponseError + 'static {
    /// Downcasts a response error to a specific type.
    pub fn downcast_ref<T: ResponseError + 'static>(&self) -> Option<&T> {
        if self.__private_get_type_id__().0 == TypeId::of::<T>() {
            // Safety: external crates cannot override the default
            // implementation of `__private_get_type_id__`, since
            // it requires returning a private type. We can therefore

Review comment (suggestion):
```suggestion
    /// on the returned `TypeId` to perform a cast.
```

Code after:
pub trait ResponseError: fmt::Debug + fmt::Display {
    /// Response's status code
    ///
    /// Internal server error is generated by default.
    fn status_code(&self) -> StatusCode {
        StatusCode::INTERNAL_SERVER_ERROR
    }

    /// Create response for error
    ///
    /// Internal server error is generated by default.
    fn error_response(&self) -> Response {
        let mut resp = Response::new(self.status_code());
        let mut buf = BytesMut::new();
        let _ = write!(Writer(&mut buf), "{}", self);
        resp.headers_mut().insert(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain; charset=utf-8"),
        );
        resp.set_body(Body::from(buf))
    }

    /// A helper method to get the type ID of the type
    /// this trait is implemented on.
    /// This method is unsafe to *implement*, since `downcast_ref` relies
    /// on the returned `TypeId` to perform a cast.
    ///
    /// Unfortunately, Rust has no notion of a trait method that is
    /// unsafe to implement (marking it as `unsafe` makes it unsafe
    /// to *call*). As a workaround, we require this method
    /// to return a private type along with the `TypeId`. This
    /// private type (`PrivateHelper`) has a private constructor,
    /// making it impossible for safe code to construct outside of
    /// this module. This ensures that safe code cannot violate
    /// type-safety by implementing this method.
    #[doc(hidden)]
    fn __private_get_type_id__(&self) -> (TypeId, PrivateHelper)
    where
        Self: 'static,
    {
        (TypeId::of::<Self>(), PrivateHelper(()))
    }
}

impl dyn ResponseError + 'static {
    /// Downcasts a response error to a specific type.
    pub fn downcast_ref<T: ResponseError + 'static>(&self) -> Option<&T> {
        if self.__private_get_type_id__().0 == TypeId::of::<T>() {
            // Safety: external crates cannot override the default
            // implementation of `__private_get_type_id__`, since
            // it requires returning a private type. We can therefore