Skip to main content

DriverError

Struct DriverError 

Source
pub struct DriverError { /* private fields */ }
Expand description

The error that stops a compilation run.

A Stage returns a DriverError from Stage::run when it cannot produce its output: a phase that hit an unrecoverable condition, or a call to Session::abort_if_errors that found the session already holds errors. It is the control-flow failure that ends the pipeline, as distinct from a Diagnostic, which is a record a stage emits and may keep going after.

The error carries the message describing what went wrong and the stage it came from. A stage does not name itself: it returns DriverError::new(reason) with an empty stage, and the Pipeline stamps in the name of the stage that failed as it propagates the error. Stamping only fills an empty name, so in a chain the innermost stage — the one that actually failed — keeps the attribution.

The reason is stored as a Cow<'static, str>, so a static message costs no allocation and a computed one is owned only when built.

§Examples

A stage failing with a static reason:

use driver_lang::DriverError;

let err = DriverError::new("unresolved import");
assert_eq!(err.message(), "unresolved import");
assert_eq!(err.stage(), ""); // not stamped until it flows through a Pipeline

A computed reason:

use driver_lang::DriverError;

let path = "src/main";
let err = DriverError::new(format!("cannot read `{path}.rs`"));
assert_eq!(err.message(), "cannot read `src/main.rs`");

Implementations§

Source§

impl DriverError

Source

pub fn new(message: impl Into<Cow<'static, str>>) -> Self

Create an error describing why a stage could not complete.

Call this from inside Stage::run. The message accepts a string literal (no allocation) or an owned String (a computed reason). The failing stage’s name is filled in by the Pipeline — you do not repeat it here.

§Examples
use driver_lang::DriverError;

let from_literal = DriverError::new("boom");
let from_owned = DriverError::new(String::from("boom"));
assert_eq!(from_literal, from_owned);
Source

pub fn stage(&self) -> &str

The name of the stage that failed, or "" if the error has not yet propagated through a Pipeline.

§Examples
use driver_lang::DriverError;

assert_eq!(DriverError::new("boom").stage(), "");
Source

pub fn message(&self) -> &str

The reason the stage could not complete.

§Examples
use driver_lang::DriverError;

assert_eq!(DriverError::new("type error").message(), "type error");

Trait Implementations§

Source§

impl Clone for DriverError

Source§

fn clone(&self) -> DriverError

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 DriverError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for DriverError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for DriverError

Source§

impl Error for DriverError

1.30.0 · Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for DriverError

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DriverError

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.