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(..))
});

Indicate if there is any diagnostics.

Check if diagnostics has any errors reported.

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.

Report an error.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Emit collected diagnostics.

See load_sources for how to use.

Emit diagnostics for the current type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.