pub struct Error {
pub kind: ErrorKind,
pub span: NodeSpan,
pub declaration: Name,
/* private fields */
}Expand description
A type error: what went wrong, where, and in which declaration.
§Where the positions come from
The typer does not check the canonical AST directly — it translates it into its
own Term language — but that translation now carries the canonical node’s
[NodeSpan] along, and each constraint keeps the span of the term that produced
it. So a unification failure knows the sub-expression it is about, and
labels draws the caret there.
The declaration’s own span is still kept as span, for the one case that has no
finer answer: an error whose origin came from a hand-built term, or from a
canonical node the parser never spanned. Then the label degrades to the whole
declaration rather than disappearing.
Fields§
§kind: ErrorKind§span: NodeSpanWhere the declaration the error was found in was written. Used only as the fallback described above.
declaration: NameThat declaration’s name, which is what the note names: in a module of a
hundred declarations, a caret is not much use without it when the diagnostic
is rendered without a file (see compile_package).
Trait Implementations§
Source§impl PhaseError for Error
Type errors are about types, and Type’s Display writes them the way the
source does — so the message can name both sides of a mismatch instead of
dumping the typer’s internal representation.
impl PhaseError for Error
Type errors are about types, and Type’s Display writes them the way the
source does — so the message can name both sides of a mismatch instead of
dumping the typer’s internal representation.
Source§fn labels(&self) -> Vec<SpanLabel>
fn labels(&self) -> Vec<SpanLabel>
A caret under the text that disagrees, and — when inference can say where the type it disagrees with came from — a second, secondary one under that.
Falls back to underlining the whole declaration when the failing constraint has no position, which is what a term built by hand, or one translated from a canonical node with no span, produces.