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 new() -> CompileErrors
pub fn new() -> CompileErrors
Create a new empty error collection.
Sourcepub fn from_error(error: DiagnosticWrapper<ErrorKind>) -> CompileErrors
pub fn from_error(error: DiagnosticWrapper<ErrorKind>) -> CompileErrors
Create an error collection from a single error.
Sourcepub fn push(&mut self, error: DiagnosticWrapper<ErrorKind>)
pub fn push(&mut self, error: DiagnosticWrapper<ErrorKind>)
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<&DiagnosticWrapper<ErrorKind>>
pub fn first(&self) -> Option<&DiagnosticWrapper<ErrorKind>>
Get the first error, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = &DiagnosticWrapper<ErrorKind>>
pub fn iter(&self) -> impl Iterator<Item = &DiagnosticWrapper<ErrorKind>>
Iterate over all errors.
Sourcepub fn as_slice(&self) -> &[DiagnosticWrapper<ErrorKind>]
pub fn as_slice(&self) -> &[DiagnosticWrapper<ErrorKind>]
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§fn default() -> CompileErrors
fn default() -> 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 DiagnosticWrapper<ErrorKind>
impl From<CompileErrors> for DiagnosticWrapper<ErrorKind>
Source§fn from(errors: CompileErrors) -> DiagnosticWrapper<ErrorKind>
fn from(errors: CompileErrors) -> DiagnosticWrapper<ErrorKind>
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).
Source§impl From<DiagnosticWrapper<ErrorKind>> for CompileErrors
impl From<DiagnosticWrapper<ErrorKind>> for CompileErrors
Source§fn from(error: DiagnosticWrapper<ErrorKind>) -> CompileErrors
fn from(error: DiagnosticWrapper<ErrorKind>) -> CompileErrors
Source§impl From<Vec<DiagnosticWrapper<ErrorKind>>> for CompileErrors
impl From<Vec<DiagnosticWrapper<ErrorKind>>> for CompileErrors
Source§fn from(errors: Vec<DiagnosticWrapper<ErrorKind>>) -> CompileErrors
fn from(errors: Vec<DiagnosticWrapper<ErrorKind>>) -> CompileErrors
Source§impl IntoIterator for CompileErrors
impl IntoIterator for CompileErrors
Source§type Item = DiagnosticWrapper<ErrorKind>
type Item = DiagnosticWrapper<ErrorKind>
Source§type IntoIter = IntoIter<DiagnosticWrapper<ErrorKind>>
type IntoIter = IntoIter<DiagnosticWrapper<ErrorKind>>
Source§fn into_iter(self) -> <CompileErrors as IntoIterator>::IntoIter
fn into_iter(self) -> <CompileErrors as IntoIterator>::IntoIter
Auto Trait Implementations§
impl Freeze for CompileErrors
impl RefUnwindSafe for CompileErrors
impl Send for CompileErrors
impl Sync for CompileErrors
impl Unpin for CompileErrors
impl UnwindSafe for CompileErrors
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].