Expand description
A library for formatting compiler error messages, extracted from rustc and built on the types from the codemap crate.
§Example
extern crate codemap2;
extern crate codemap2_diagnostic;
use codemap2::{CodeMap, DefaultFileData};
use codemap2_diagnostic::{ Level, SpanLabel, SpanStyle, Diagnostic, ColorConfig, Emitter };
fn main() {
let code = "foo + bar";
let mut codemap = CodeMap::new();
let file_span = codemap.add_file(DefaultFileData::new("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]);
}
Re-exports§
pub extern crate codemap2;
Structs§
- BoxStr
- A wrapper around a
Box<str>
that meets the requirements forFileData::Source
andFileData::Name
. This type is used inDefaultFileData
because - CodeMap
- A data structure recording source code files for position lookup.
- Default
File Data - A default implementation of
FileData
that contains - Diagnostic
- A diagnostic message.
- Emitter
- Formats and prints diagnostic messages.
- File
- A
CodeMap
’s record of a source file. - LineCol
- A line and column.
- Loc
- A file, and a line and column within it.
- Pos
- A small,
Copy
, value representing a position in aCodeMap
’s file. - Span
- A range of text within a CodeMap.
- Span
Label - A labeled region of the code related to a Diagnostic.
- SpanLoc
- A file, and a line and column range within it.
- Spanned
- Associate a Span with a value of arbitrary type (e.g. an AST node).
Enums§
- Color
Config - Settings for terminal styling.
- Level
- A level representing the severity of a Diagnostic.
- Span
Style - Underline style for a SpanLabel.
Traits§
- File
Data - A trait that represents file data