diff --git a/naga/src/span.rs b/naga/src/span.rs index 7c1ce17dcab..0256e19dc48 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -314,7 +314,9 @@ impl WithSpan { /// Convenience trait for [`Error`] to be able to apply spans to anything. pub(crate) trait AddSpan: Sized { + /// The returned output type. type Output; + /// See [`WithSpan::new`]. fn with_span(self) -> Self::Output; /// See [`WithSpan::with_span`]. @@ -325,6 +327,30 @@ pub(crate) trait AddSpan: Sized { fn with_span_handle>(self, handle: Handle, arena: &A) -> Self::Output; } +impl AddSpan for E { + type Output = WithSpan; + + fn with_span(self) -> WithSpan { + WithSpan::new(self) + } + + fn with_span_static(self, span: Span, description: &'static str) -> WithSpan { + WithSpan::new(self).with_span(span, description) + } + + fn with_span_context(self, span_context: SpanContext) -> WithSpan { + WithSpan::new(self).with_context(span_context) + } + + fn with_span_handle>( + self, + handle: Handle, + arena: &A, + ) -> WithSpan { + WithSpan::new(self).with_handle(handle, arena) + } +} + /// Trait abstracting over getting a span from an [`Arena`] or a [`UniqueArena`]. pub(crate) trait SpanProvider { fn get_span(&self, handle: Handle) -> Span; @@ -351,36 +377,12 @@ impl SpanProvider for UniqueArena { } } -impl AddSpan for E -where - E: Error, -{ - type Output = WithSpan; - fn with_span(self) -> WithSpan { - WithSpan::new(self) - } - - fn with_span_static(self, span: Span, description: &'static str) -> WithSpan { - WithSpan::new(self).with_span(span, description) - } - - fn with_span_context(self, span_context: SpanContext) -> WithSpan { - WithSpan::new(self).with_context(span_context) - } - - fn with_span_handle>( - self, - handle: Handle, - arena: &A, - ) -> WithSpan { - WithSpan::new(self).with_handle(handle, arena) - } -} - /// Convenience trait for [`Result`], adding a [`MapErrWithSpan::map_err_inner`] /// mapping to [`WithSpan::and_then`]. -pub trait MapErrWithSpan: Sized { +pub(crate) trait MapErrWithSpan: Sized { + /// The returned output type. type Output: Sized; + fn map_err_inner(self, func: F) -> Self::Output where F: FnOnce(E) -> WithSpan, @@ -389,6 +391,7 @@ pub trait MapErrWithSpan: Sized { impl MapErrWithSpan for Result> { type Output = Result>; + fn map_err_inner(self, func: F) -> Result> where F: FnOnce(E) -> WithSpan,