#compiler #error #format #rustc #warning

codemap-diagnostic

Library for displaying compiler error messages, extracted from rustc

2 releases

0.1.1 Feb 7, 2019
0.1.0 Jun 28, 2017

#49 in Command-line interface

Download history 48/week @ 2018-10-25 85/week @ 2018-11-01 63/week @ 2018-11-08 42/week @ 2018-11-15 50/week @ 2018-11-22 69/week @ 2018-11-29 39/week @ 2018-12-06 69/week @ 2018-12-13 44/week @ 2018-12-20 61/week @ 2018-12-27 43/week @ 2019-01-03 89/week @ 2019-01-10 59/week @ 2019-01-17 56/week @ 2019-01-24 31/week @ 2019-01-31

237 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

64KB
1K SLoC

CodeMap Diagnostic

Documentation

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

screenshot

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

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]);
}

Dependencies

~608KB