[][src]Crate codemap_diagnostic

A library for formatting compiler error messages, extracted from rustc and built on the types from the codemap crate.

Example

extern crate codemap;
extern crate codemap_diagnostic;
use codemap::CodeMap;
use codemap_diagnostic::{ Level, SpanLabel, SpanStyle, Diagnostic, ColorConfig, Emitter };

fn main() {
  let code = "foo + bar";
  let mut codemap = CodeMap::new();
  let file_span = codemap.add_file("test.rs".to_owned(), code.to_owned()).span;
  let name_span = file_span.subspan(0, 3);

  let label = SpanLabel {
      span: name_span,
      style: SpanStyle::Primary,
      label: Some("undefined variable".to_owned())
  };
  let d = Diagnostic {
      level: Level::Error,
      message: "cannot find value `foo` in this scope".to_owned(),
      code: Some("C000".to_owned()),
      spans: vec![label]
  };

  let mut emitter = Emitter::stderr(ColorConfig::Always, Some(&codemap));
  emitter.emit(&[d]);
}

Structs

Diagnostic

A diagnostic message.

Emitter

Formats and prints diagnostic messages.

SpanLabel

A labeled region of the code related to a Diagnostic.

Enums

ColorConfig

Settings for terminal styling.

Level

A level representing the severity of a Diagnostic.

SpanStyle

Underline style for a SpanLabel.