pub struct TypeError {
pub kind: TypeErrorKind,
pub span: Option<Span>,
pub context: Vec<String>,
}Expand description
Type error with context and location information.
Fields§
§kind: TypeErrorKindThe kind of type error
span: Option<Span>Source location where the error occurred
context: Vec<String>Context stack for nested errors
Implementations§
Source§impl TypeError
impl TypeError
Sourcepub fn new(kind: TypeErrorKind) -> Self
pub fn new(kind: TypeErrorKind) -> Self
Create a new type error without location information.
Sourcepub fn with_span(kind: TypeErrorKind, span: Span) -> Self
pub fn with_span(kind: TypeErrorKind, span: Span) -> Self
Create a new type error with span information.
Sourcepub fn add_context(&mut self, ctx: String)
pub fn add_context(&mut self, ctx: String)
Add context to the error (e.g., “in function application”, “in let binding”).
Sourcepub fn with_context(self, ctx: String) -> Self
pub fn with_context(self, ctx: String) -> Self
Add context and return self (builder pattern).
Sourcepub fn format(&self, source: &str) -> String
pub fn format(&self, source: &str) -> String
Format the error with source code highlighting.
Produces a beautiful error message with:
- Error description
- Source location
- Source code excerpt with highlighting
- Context stack
- Helpful suggestions
Sourcepub fn suggest_fix(&self) -> Option<String>
pub fn suggest_fix(&self) -> Option<String>
Suggest a fix for common error patterns.
Trait Implementations§
Source§impl Error for TypeError
impl Error for TypeError
1.30.0§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for TypeError
impl RefUnwindSafe for TypeError
impl Send for TypeError
impl Sync for TypeError
impl Unpin for TypeError
impl UnwindSafe for TypeError
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)