IceContext

Struct IceContext 

Source
pub struct IceContext {
    pub message: String,
    pub version: Option<String>,
    pub target: Option<String>,
    pub phase: Option<String>,
    pub details: Vec<(String, String)>,
    pub backtrace: Option<Backtrace>,
}
Expand description

Context information for an Internal Compiler Error (ICE).

This struct captures detailed information about the compiler state when an ICE occurs, making it easier to diagnose and fix compiler bugs.

§Example

let ice = IceContext::new("unexpected type in codegen")
    .with_version("0.1.0")
    .with_target("x86_64-unknown-linux-gnu")
    .with_phase("codegen/emit")
    .with_backtrace();

Fields§

§message: String

The error message describing what went wrong.

§version: Option<String>

Compiler version (from CARGO_PKG_VERSION).

§target: Option<String>

Target architecture (e.g., “x86_64-unknown-linux-gnu”).

§phase: Option<String>

Compilation phase (e.g., “codegen/emit”, “sema”, “cfg_builder”).

§details: Vec<(String, String)>

Additional context-specific details.

This can include things like:

  • Current function being compiled
  • Instruction that triggered the ICE
  • Type information
  • Any other relevant state
§backtrace: Option<Backtrace>

Backtrace captured at the ICE site.

Implementations§

Source§

impl IceContext

Source

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

Create a new ICE context with the given error message.

Source

pub fn with_version(self, version: impl Into<String>) -> Self

Set the compiler version.

Source

pub fn with_target(self, target: impl Into<String>) -> Self

Set the target architecture.

Source

pub fn with_phase(self, phase: impl Into<String>) -> Self

Set the compilation phase.

Source

pub fn with_detail( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add a detail key-value pair.

Details provide context-specific information about the compiler state.

Source

pub fn with_backtrace(self) -> Self

Capture a backtrace at the current call site.

This should be called at the point where the ICE is detected to capture the most relevant stack trace.

Source

pub fn format_details(&self) -> String

Format the ICE context for display.

This produces a user-friendly representation suitable for error messages.

Source

pub fn format_backtrace(&self) -> Option<String>

Format the backtrace for display.

Returns a formatted backtrace if one was captured, or None otherwise. The backtrace is formatted with frame numbers and source locations.

Trait Implementations§

Source§

impl Debug for IceContext

Source§

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

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

impl Display for IceContext

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> 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> 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.