pub struct Diagnostic { /* private fields */ }Expand description
A rich diagnostic message with source location information.
Diagnostics provide detailed information about errors and warnings, including:
- A severity level
- An optional error code for documentation and searchability
- A primary message describing the issue
- One or more labeled source spans
- Optional help text with suggestions
§Example
error[E301]: cannot override type `Rectangle`
--> src/main.orr:10:1
|
10 | type Rectangle = Oval[fill_color="red"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type override not supported
|
= help: built-in types cannot be redefinedImplementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn error(message: impl Into<String>) -> Self
pub fn error(message: impl Into<String>) -> Self
Create an error diagnostic.
§Example
let span = Span::new(0..10);
let diag = Diagnostic::error("undefined type `Foo`")
.with_code(ErrorCode::E300)
.with_label(span, "not found")
.with_help("did you mean `Bar`?");Sourcepub fn warning(message: impl Into<String>) -> Self
pub fn warning(message: impl Into<String>) -> Self
Create a warning diagnostic.
§Example
let span = Span::new(0..10);
let diag = Diagnostic::warning("unused component")
.with_label(span, "this component is never referenced")
.with_help("consider removing it");Sourcepub fn with_label(self, span: Span, message: impl Into<String>) -> Self
pub fn with_label(self, span: Span, message: impl Into<String>) -> Self
Add a primary label to this diagnostic.
Sourcepub fn with_secondary_label(
self,
span: Span,
message: impl Into<String>,
) -> Self
pub fn with_secondary_label( self, span: Span, message: impl Into<String>, ) -> Self
Add a secondary label to this diagnostic.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl Display for Diagnostic
impl Display for Diagnostic
Source§impl Error for Diagnostic
impl Error for Diagnostic
1.30.0 · Source§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 · Source§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 Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnsafeUnpin for Diagnostic
impl UnwindSafe for Diagnostic
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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