Struct rune::Diagnostics[][src]

pub struct Diagnostics { /* fields omitted */ }

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]

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]

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]

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]

Push a warning to the collection of diagnostics.

pub fn error<T>(&mut self, source_id: SourceId, kind: T) where
    ErrorKind: From<T>, 
[src]

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.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.