pub struct CompileErrors { /* private fields */ }Expand description
A collection of compilation errors.
This type supports collecting multiple errors during compilation to provide users with more comprehensive diagnostics. Instead of stopping at the first error, the compiler can continue and report multiple issues at once.
§Usage
Use CompileErrors when a compilation phase can detect multiple independent
errors. For example, semantic analysis can report multiple type errors in
different functions.
let mut errors = CompileErrors::new();
errors.push(CompileError::new(ErrorKind::TypeMismatch { ... }, span1));
errors.push(CompileError::new(ErrorKind::UndefinedVariable("x".into()), span2));
if !errors.is_empty() {
return Err(errors);
}§Error Semantics
- An empty
CompileErrorsrepresents no errors (not a failure) - A non-empty
CompileErrorsrepresents one or more compilation failures - When converted to a single
CompileError, the first error is used
Implementations§
Source§impl CompileErrors
impl CompileErrors
Sourcepub fn from_error(error: CompileError) -> Self
pub fn from_error(error: CompileError) -> Self
Create an error collection from a single error.
Sourcepub fn push(&mut self, error: CompileError)
pub fn push(&mut self, error: CompileError)
Add an error to the collection.
Sourcepub fn extend(&mut self, other: CompileErrors)
pub fn extend(&mut self, other: CompileErrors)
Extend this collection with errors from another collection.
Sourcepub fn first(&self) -> Option<&CompileError>
pub fn first(&self) -> Option<&CompileError>
Get the first error, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = &CompileError>
pub fn iter(&self) -> impl Iterator<Item = &CompileError>
Iterate over all errors.
Sourcepub fn as_slice(&self) -> &[CompileError] ⓘ
pub fn as_slice(&self) -> &[CompileError] ⓘ
Get all errors as a slice.
Sourcepub fn into_result(self) -> Result<(), CompileErrors>
pub fn into_result(self) -> Result<(), CompileErrors>
Check if the collection contains errors and return as a result.
Returns Ok(()) if empty, or Err(self) if there are errors.
Sourcepub fn into_result_with<T>(self, value: T) -> Result<T, CompileErrors>
pub fn into_result_with<T>(self, value: T) -> Result<T, CompileErrors>
Fail with these errors if non-empty, otherwise return the value.
This is useful for combining error checking with a result:
let output = SemaOutput { ... };
errors.into_result_with(output)Trait Implementations§
Source§impl Clone for CompileErrors
impl Clone for CompileErrors
Source§fn clone(&self) -> CompileErrors
fn clone(&self) -> CompileErrors
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompileErrors
impl Debug for CompileErrors
Source§impl Default for CompileErrors
impl Default for CompileErrors
Source§impl Display for CompileErrors
impl Display for CompileErrors
Source§impl Error for CompileErrors
impl Error for CompileErrors
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
Source§impl From<CompileErrors> for CompileError
impl From<CompileErrors> for CompileError
Source§fn from(errors: CompileErrors) -> Self
fn from(errors: CompileErrors) -> Self
Convert a collection to a single error.
Uses the first error in the collection. If the collection is empty, returns an internal error (this indicates a compiler bug).