Struct rune::Diagnostics [−][src]
pub struct Diagnostics { /* fields omitted */ }
Expand description
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
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));
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(..)) });
Check if diagnostics has any warnings reported.
Access underlying diagnostics.
Convert into underlying diagnostics.
Indicate that a value is produced but never used.
Indicate that a binding pattern might panic.
Like let (a, b) = value
.
Indicate that we encountered a template string without any expansion groups.
Like `Hello`
.
Add a warning indicating that the parameters of an empty tuple can be removed when creating it.
Like None()
.
Add a warning about an unecessary semi-colon.
Push a warning to the collection of diagnostics.
Trait Implementations
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,
fn emit_diagnostics<O>(
&self,
out: &mut O,
sources: &Sources
) -> Result<(), DiagnosticsError> where
O: WriteColor,
Emit diagnostics for the current type.