Struct rune::Diagnostics [−][src]
Structure to collect compilation diagnostics.
If the project is compiled with the diagnostics
feature, you can make use
of the EmitDiagnostics
trait to emit human-readable diagnostics.
Examples
use rune::{Sources, Diagnostics, EmitDiagnostics}; use rune::termcolor::{StandardStream, ColorChoice}; let mut sources = Sources::new(); let mut diagnostics = Diagnostics::new(); // use sources and diagnostics to compile a project. if !diagnostics.is_empty() { let mut writer = StandardStream::stderr(ColorChoice::Always); diagnostics.emit_diagnostics(&mut writer, &sources)?; }
Implementations
impl Diagnostics
[src]
pub fn without_warnings() -> Self
[src]
Construct a new, empty collection of compilation warnings that is disabled, i.e. any warnings added to it will be ignored.
Examples
use rune::{Diagnostic, Diagnostics}; use runestick::Span; let mut diagnostics = Diagnostics::without_warnings(); assert!(diagnostics.is_empty()); diagnostics.not_used(0, Span::empty(), None); assert!(diagnostics.is_empty()); let warning = diagnostics.into_diagnostics().into_iter().next(); assert!(matches!(warning, None));
pub fn new() -> Self
[src]
Construct a new, empty collection of compilation warnings.
Examples
use rune::{Diagnostic, Diagnostics, Warning, WarningKind}; use runestick::Span; let mut diagnostics = Diagnostics::new(); assert!(diagnostics.is_empty()); diagnostics.not_used(0, Span::empty(), None); assert!(!diagnostics.is_empty()); assert!(matches! { diagnostics.into_diagnostics().into_iter().next(), Some(Diagnostic::Warning(..)) });
pub fn is_empty(&self) -> bool
[src]
Indicate if there is any diagnostics.
pub fn has_error(&self) -> bool
[src]
Check if diagnostics has any errors reported.
pub fn has_warning(&self) -> bool
[src]
Check if diagnostics has any warnings reported.
pub fn diagnostics(&self) -> &[Diagnostic]
[src]
Access underlying diagnostics.
pub fn into_diagnostics(self) -> Vec<Diagnostic>
[src]
Convert into underlying diagnostics.
pub fn not_used(&mut self, source_id: usize, span: Span, context: Option<Span>)
[src]
Indicate that a value is produced but never used.
pub fn let_pattern_might_panic(
&mut self,
source_id: usize,
span: Span,
context: Option<Span>
)
[src]
&mut self,
source_id: usize,
span: Span,
context: Option<Span>
)
Indicate that a binding pattern might panic.
Like let (a, b) = value
.
pub fn template_without_expansions(
&mut self,
source_id: usize,
span: Span,
context: Option<Span>
)
[src]
&mut self,
source_id: usize,
span: Span,
context: Option<Span>
)
Indicate that we encountered a template string without any expansion groups.
Like `Hello`
.
pub fn remove_tuple_call_parens(
&mut self,
source_id: usize,
span: Span,
variant: Span,
context: Option<Span>
)
[src]
&mut self,
source_id: usize,
span: Span,
variant: Span,
context: Option<Span>
)
Add a warning indicating that the parameters of an empty tuple can be removed when creating it.
Like None()
.
pub fn uneccessary_semi_colon(&mut self, source_id: usize, span: Span)
[src]
Add a warning about an unecessary semi-colon.
pub fn warning<T>(&mut self, source_id: SourceId, kind: T) where
WarningKind: From<T>,
[src]
WarningKind: From<T>,
Push a warning to the collection of diagnostics.
pub fn error<T>(&mut self, source_id: SourceId, kind: T) where
ErrorKind: From<T>,
[src]
ErrorKind: From<T>,
Report an error.
Trait Implementations
impl Debug for Diagnostics
[src]
impl Default for Diagnostics
[src]
impl EmitDiagnostics for Diagnostics
[src]
Emit collected diagnostics.
See load_sources for how to use.
fn emit_diagnostics<O>(
&self,
out: &mut O,
sources: &Sources
) -> Result<(), DiagnosticsError> where
O: WriteColor,
[src]
&self,
out: &mut O,
sources: &Sources
) -> Result<(), DiagnosticsError> where
O: WriteColor,
Auto Trait Implementations
impl !RefUnwindSafe for Diagnostics
impl Send for Diagnostics
impl Sync for Diagnostics
impl Unpin for Diagnostics
impl !UnwindSafe for Diagnostics
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,