Skip to main content

Diagnostic

Struct Diagnostic 

Source
pub struct Diagnostic {
    pub headline: String,
    pub path: String,
    pub line: u32,
    pub col: u32,
    pub source_line: String,
    pub message: String,
    pub hint: Option<String>,
}
Expand description

A single compile error. The front end stops at the first one (docs/ERRORS.md: “one issue at a time”), so a failed compile yields exactly one Diagnostic.

Fields§

§headline: String

The meme framing line, e.g. very error. much confuse.. A more specific headline is used when one fits (very tab. much confuse.).

§path: String

Path of the source file, shown above the offending line.

§line: u32

1-based line the error points at.

§col: u32

1-based column the caret sits under.

§source_line: String

The offending source line, verbatim (no trailing newline).

§message: String

The precise, plain-language explanation printed after the caret.

§hint: Option<String>

An optional concrete fix, rendered as such fix: ….

Implementations§

Source§

impl Diagnostic

Source

pub fn new( path: impl Into<String>, line: u32, col: u32, source_line: impl Into<String>, message: impl Into<String>, ) -> Diagnostic

Build a diagnostic with the default headline.

Source

pub fn with_headline(self, headline: impl Into<String>) -> Diagnostic

Replace the default headline with a specific meme framing.

Source

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

Attach a such fix: … hint.

Source

pub fn render(&self) -> String

Render the diagnostic in the exact docs/ERRORS.md shape:

very error. much confuse.

  examples/hello.doge:4
    bark "hello" + 5
                 ^ cannot + a Str and an Int

such fix: turn the Int into a Str first, e.g. str(5)

The code line is indented four spaces; the caret sits under col (1-based), so its leading padding is 4 + (col - 1) spaces.

Trait Implementations§

Source§

impl Clone for Diagnostic

Source§

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)

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
Source§

impl PartialEq for Diagnostic

Source§

fn eq(&self, other: &Diagnostic) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Diagnostic

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.