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 PipelineA 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
impl DriverError
Sourcepub fn new(message: impl Into<Cow<'static, str>>) -> Self
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);Trait Implementations§
Source§impl Clone for DriverError
impl Clone for DriverError
Source§fn clone(&self) -> DriverError
fn clone(&self) -> DriverError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DriverError
impl Debug for DriverError
Source§impl Display for DriverError
impl Display for DriverError
impl Eq for DriverError
Source§impl Error for DriverError
impl Error for DriverError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for DriverError
impl PartialEq for DriverError
Source§fn eq(&self, other: &DriverError) -> bool
fn eq(&self, other: &DriverError) -> bool
self and other values to be equal, and is used by ==.