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
Sometimes, I want to construct a bigger error from several related ones.
It happens either from convenience reasons, or from technical ones (part of the error may be located in another file)
There is an example from my code:
/// Show type in diagnostic#[derive(Error,Diagnostic,Debug,Clone,PartialEq)]#[error("{ty}")]pubstructTypeWithSpan{/// Type to showpubty:Type,/// Span of expected type#[label("this has `{ty}` type")]pubat:SourceSpan,// TODO: change to `Option<SourceFile>`/// Source code of the module, this type is located at#[source_code]pubsource_code:Option<String>,}/// Diagnostic for not convertible types#[derive(Error,Diagnostic,Debug,Clone,PartialEq)]#[error("expected `{expected}` type, got `{got}`")]#[diagnostic(code(semantics::type_mismatch))]pubstructTypeMismatch{/// Expected typepubexpected:TypeWithSpan,/// Real typepubgot:TypeWithSpan,}
Declaration of type and its usage may be splited in different files, so there should be two errors. However, logically it's a single TypeMismatch error.
I could use:
#[related]
errors:Vec<TypeWithSpan>
But this will decrease type safety, as I know beforehand that this error consist from exactly two errors.
Hence I propose syntax like this to merge labels from another diagnostics:
#[derive(Error,Diagnostic,Debug,Clone,PartialEq)]#[error("expected `{expected}` type, got `{got}`")]#[diagnostic(code(semantics::type_mismatch))]pubstructTypeMismatch{#[related]// or #[labels]pubexpected:TypeWithSpan,#[related]// or #[labels]pubgot:TypeWithSpan,}
The text was updated successfully, but these errors were encountered:
Sometimes, I want to construct a bigger error from several related ones.
It happens either from convenience reasons, or from technical ones (part of the error may be located in another file)
There is an example from my code:
Declaration of type and its usage may be splited in different files, so there should be two errors. However, logically it's a single
TypeMismatch
error.I could use:
But this will decrease type safety, as I know beforehand that this error consist from exactly two errors.
Hence I propose syntax like this to merge labels from another diagnostics:
The text was updated successfully, but these errors were encountered: