Diagnostic

Struct Diagnostic 

Source
pub struct Diagnostic {
    pub code: DiagnosticCode,
    pub severity: Severity,
    pub message: String,
    pub file: Option<PathBuf>,
    pub span: Option<SourceSpan>,
    pub secondary_spans: Vec<SourceSpan>,
    pub notes: Vec<String>,
    pub hints: Vec<String>,
}
Expand description

A diagnostic message emitted during analysis or scheduling

Diagnostics are structured data representing errors, warnings, hints, or informational messages. The message text is fully rendered at emission time according to the specification in DIAGNOSTICS.md.

§Example

use utf8proj_core::{Diagnostic, DiagnosticCode, Severity};

let diagnostic = Diagnostic::new(
    DiagnosticCode::W001AbstractAssignment,
    "task 'api_dev' is assigned to abstract profile 'developer'"
);

assert_eq!(diagnostic.severity, Severity::Warning);
assert_eq!(diagnostic.code.as_str(), "W001");

Fields§

§code: DiagnosticCode

The diagnostic code

§severity: Severity

Severity level (derived from code by default)

§message: String

The primary message (fully rendered)

§file: Option<PathBuf>

Source file path (if applicable)

§span: Option<SourceSpan>

Primary source span (if applicable)

§secondary_spans: Vec<SourceSpan>

Additional spans for related locations

§notes: Vec<String>

Additional notes (displayed after the main message)

§hints: Vec<String>

Hints for fixing the issue

Implementations§

Source§

impl Diagnostic

Source

pub fn new(code: DiagnosticCode, message: impl Into<String>) -> Self

Create a new diagnostic with the given code and message

Severity is derived from the diagnostic code’s default.

Source

pub fn error(code: DiagnosticCode, message: impl Into<String>) -> Self

Create an error diagnostic

Source

pub fn warning(code: DiagnosticCode, message: impl Into<String>) -> Self

Create a warning diagnostic

Source

pub fn with_file(self, file: impl Into<PathBuf>) -> Self

Set the source file

Source

pub fn with_span(self, span: SourceSpan) -> Self

Set the primary source span

Source

pub fn with_secondary_span(self, span: SourceSpan) -> Self

Add a secondary span

Source

pub fn with_note(self, note: impl Into<String>) -> Self

Add a note

Source

pub fn with_hint(self, hint: impl Into<String>) -> Self

Add a hint

Source

pub fn is_error(&self) -> bool

Returns true if this is an error-level diagnostic

Source

pub fn is_warning(&self) -> bool

Returns true if this is a warning-level diagnostic

Trait Implementations§

Source§

impl Clone for Diagnostic

Source§

fn clone(&self) -> Diagnostic

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Diagnostic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.