Struct rune::Diagnostics
source · pub struct Diagnostics { /* private fields */ }
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§
source§impl Diagnostics
impl Diagnostics
source§impl Diagnostics
impl Diagnostics
sourcepub fn without_warnings() -> Self
pub fn without_warnings() -> Self
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));
sourcepub fn new() -> Self
pub fn new() -> Self
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(..))
});
sourcepub fn has_warning(&self) -> bool
pub fn has_warning(&self) -> bool
Check if diagnostics has any warnings reported.
sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Access underlying diagnostics.
sourcepub fn into_diagnostics(self) -> Vec<Diagnostic>
pub fn into_diagnostics(self) -> Vec<Diagnostic>
Convert into underlying diagnostics.
sourcepub fn not_used(
&mut self,
source_id: SourceId,
span: Span,
context: Option<Span>
)
pub fn not_used( &mut self, source_id: SourceId, span: Span, context: Option<Span> )
Indicate that a value is produced but never used.
sourcepub fn let_pattern_might_panic(
&mut self,
source_id: SourceId,
span: Span,
context: Option<Span>
)
pub fn let_pattern_might_panic( &mut self, source_id: SourceId, span: Span, context: Option<Span> )
Indicate that a binding pattern might panic.
Like let (a, b) = value
.
sourcepub fn template_without_expansions(
&mut self,
source_id: SourceId,
span: Span,
context: Option<Span>
)
pub fn template_without_expansions( &mut self, source_id: SourceId, span: Span, context: Option<Span> )
Indicate that we encountered a template string without any expansion groups.
Like `Hello`
.
sourcepub fn remove_tuple_call_parens(
&mut self,
source_id: SourceId,
span: Span,
variant: Span,
context: Option<Span>
)
pub fn remove_tuple_call_parens( &mut self, source_id: SourceId, 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()
.
sourcepub fn uneccessary_semi_colon(&mut self, source_id: SourceId, span: Span)
pub fn uneccessary_semi_colon(&mut self, source_id: SourceId, span: Span)
Add a warning about an unecessary semi-colon.
sourcepub 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.
sourcepub fn error<T>(&mut self, source_id: SourceId, kind: T)where
FatalDiagnosticKind: From<T>,
pub fn error<T>(&mut self, source_id: SourceId, kind: T)where FatalDiagnosticKind: From<T>,
Report an error.