Skip to main content

PassError

Struct PassError 

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

The error a Pass returns when it cannot complete its work.

A pass produces a PassError from inside Pass::run when it hits a condition it cannot transform past — a construct it does not support, an invariant the input violates, an arithmetic operation that would overflow. The error carries a human-readable message explaining what went wrong; the PassManager then stamps in the name of the pass that failed before returning it, so the caller always knows which pass halted the pipeline and why.

The reason is stored as a Cow<'static, str>: a static message ("unsupported construct") costs no allocation, while a computed one (format!("overflow folding {a} * {b}")) is owned only when it is built.

§Examples

Failing a pass with a static reason:

use pass_lang::{Outcome, Pass, PassError};

struct RejectEmpty;
impl Pass<Vec<i64>> for RejectEmpty {
    fn name(&self) -> &'static str { "reject-empty" }
    fn run(&mut self, unit: &mut Vec<i64>) -> Result<Outcome, PassError> {
        if unit.is_empty() {
            return Err(PassError::new("the unit is empty"));
        }
        Ok(Outcome::Unchanged)
    }
}

Failing with a computed reason:

use pass_lang::PassError;

let (a, b) = (i64::MAX, 2);
let err = PassError::new(format!("overflow folding {a} * {b}"));
assert_eq!(err.message(), "overflow folding 9223372036854775807 * 2");

Implementations§

Source§

impl PassError

Source

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

Create an error describing why a pass could not complete.

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

§Examples
use pass_lang::PassError;

let from_literal = PassError::new("division by zero");
let from_owned = PassError::new(String::from("division by zero"));
assert_eq!(from_literal, from_owned);
Source

pub fn pass(&self) -> &str

The name of the pass that failed, or "" if the error has not yet been returned through a PassManager.

§Examples
use pass_lang::PassError;

// Before the manager stamps it in, the pass name is empty.
assert_eq!(PassError::new("boom").pass(), "");
Source

pub fn message(&self) -> &str

The reason the pass could not complete.

§Examples
use pass_lang::PassError;

assert_eq!(PassError::new("unsupported node").message(), "unsupported node");

Trait Implementations§

Source§

impl Clone for PassError

Source§

fn clone(&self) -> PassError

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 PassError

Source§

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

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

impl Display for PassError

Source§

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

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

impl Eq for PassError

Source§

impl Error for PassError

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 PassError

Source§

fn eq(&self, other: &PassError) -> 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 PassError

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.