pub struct Diagnostic {
pub severity: Severity,
pub code: DiagnosticCode,
pub message: String,
pub span: Option<SourceSpan>,
pub notes: Vec<DiagnosticNote>,
pub suggestions: Vec<Suggestion>,
}Expand description
A user-facing diagnostic (manifest §16, §31).
§Examples
use mos_core::{Diagnostic, DiagnosticCode, Severity};
let diagnostic = Diagnostic::error(DiagnosticCode("E001"), "boom");
assert_eq!(diagnostic.severity, Severity::Error);Fields§
§severity: Severity§code: DiagnosticCode§message: String§span: Option<SourceSpan>§notes: Vec<DiagnosticNote>§suggestions: Vec<Suggestion>Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn error(code: DiagnosticCode, message: impl Into<String>) -> Self
pub fn error(code: DiagnosticCode, message: impl Into<String>) -> Self
Construct an error diagnostic without a span.
§Examples
use mos_core::{Diagnostic, DiagnosticCode, Severity};
let diagnostic = Diagnostic::error(DiagnosticCode("E001"), "boom");
assert_eq!(diagnostic.severity, Severity::Error);Sourcepub fn with_span(self, span: SourceSpan) -> Self
pub fn with_span(self, span: SourceSpan) -> Self
Attach a span to a diagnostic.
§Examples
use std::path::PathBuf;
use mos_core::{Diagnostic, DiagnosticCode, SourceSpan};
let diagnostic = Diagnostic::error(DiagnosticCode("E001"), "boom")
.with_span(SourceSpan::placeholder(PathBuf::from("main.mos")));
assert!(diagnostic.span.is_some());Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl Display for Diagnostic
impl Display for Diagnostic
Source§impl Error for Diagnostic
impl Error for Diagnostic
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnsafeUnpin for Diagnostic
impl UnwindSafe for Diagnostic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more