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: StringThe 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
impl IceContext
Sourcepub fn new(message: impl Into<String>) -> Self
pub fn new(message: impl Into<String>) -> Self
Create a new ICE context with the given error message.
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Set the compiler version.
Sourcepub fn with_target(self, target: impl Into<String>) -> Self
pub fn with_target(self, target: impl Into<String>) -> Self
Set the target architecture.
Sourcepub fn with_phase(self, phase: impl Into<String>) -> Self
pub fn with_phase(self, phase: impl Into<String>) -> Self
Set the compilation phase.
Sourcepub fn with_detail(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
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.
Sourcepub fn with_backtrace(self) -> Self
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.
Sourcepub fn format_details(&self) -> String
pub fn format_details(&self) -> String
Format the ICE context for display.
This produces a user-friendly representation suitable for error messages.
Sourcepub fn format_backtrace(&self) -> Option<String>
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.