Struct rune::Diagnostics [−][src]
pub struct Diagnostics { /* fields omitted */ }
Expand description
Structure to collect compilation diagnostics.
If the project is compiled with the emit
feature, you can make use of
Diagnostics::emit.
Examples
use rune::{Sources, Diagnostics};
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(&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::{Diagnostics, SourceId};
use rune::ast::Span;
let mut diagnostics = Diagnostics::without_warnings();
assert!(diagnostics.is_empty());
diagnostics.not_used(SourceId::empty(), 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::{Diagnostics, SourceId};
use rune::ast::Span;
use rune::diagnostics::Diagnostic;
let mut diagnostics = Diagnostics::new();
assert!(diagnostics.is_empty());
diagnostics.not_used(SourceId::empty(), 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.
pub fn into_diagnostics(self) -> Vec<Diagnostic>ⓘ
pub fn into_diagnostics(self) -> Vec<Diagnostic>ⓘ
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.
pub fn warning<T>(&mut self, source_id: SourceId, kind: T) where
WarningDiagnosticKind: From<T>,
pub fn warning<T>(&mut self, source_id: SourceId, kind: T) where
WarningDiagnosticKind: From<T>,
Push a warning to the collection of diagnostics.
Report an error.