You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use miette::{Diagnostic,IntoDiagnostic};use thiserror::Error;#[derive(Debug,Error,Diagnostic)]#[error("Just another diagnostic")]structAnotherDiagnostic;#[derive(Debug,Error,Diagnostic)]#[error("Diagnostic with a related error")]structDiagnosticWithRelated{#[diagnostic(related)]rel:Vec<AnotherDiagnostic>,}#[test]fntest_diagnostic_not_losing_related(){let dwr:Result<(),_> = Err(DiagnosticWithRelated{rel:vec![AnotherDiagnostic],});let dwr = dwr.into_diagnostic();assert!(
dwr.err().expect("Contain an error").related().expect("To have related if wrapping another diagnostic").count()
> 0);}
Which is because IntoDiagnostic wraps a std::error::Error and then puts that into a miette::Report which then has no idea whether the wrapped type might implement Diagnostic.
This can cause confusion as one might expect that any T: Diagnostic when called into_diagnostic on would keep its original implementation (or atleast be forwarded to).
I understand that this currently cannot be resolved without specialization due to overlapping impl with the Error implementation. (Although I am not 100% sure this can be solved with it either).
Either way, I think that there are steps one could take to alleviate this problem somewhat:
Add a warning that you should only call it on types that only implement Error and not Diagnostic
Deprecate the current name (or even doc(hide) it) and call it something else that makes it clear it shouldn't be used on Diagnostics (although I don't think this is particularly effective)
The text was updated successfully, but these errors were encountered:
The following test fails:
Which is because
IntoDiagnostic
wraps astd::error::Error
and then puts that into amiette::Report
which then has no idea whether the wrapped type might implementDiagnostic
.This can cause confusion as one might expect that any
T: Diagnostic
when calledinto_diagnostic
on would keep its original implementation (or atleast be forwarded to).I understand that this currently cannot be resolved without specialization due to overlapping impl with the
Error
implementation. (Although I am not 100% sure this can be solved with it either).Either way, I think that there are steps one could take to alleviate this problem somewhat:
Error
and notDiagnostic
Diagnostic
s (although I don't think this is particularly effective)The text was updated successfully, but these errors were encountered: