Crate for outputting Rust compiler style errors

Hi all,

One of the things I think is really valuable in Rust a lot is the really good compiler error output you get in a terminal but also that they can be output to JSON or whatever for Rust Analyzer/whatever to also make use of.

A few times I've seen other libraries output a similar thing, but nearly always they seem to handcraft code themselves in their libraries that makes the output in a terminal look similar but it tends to be slightly hacky (without meaning any disrespect at all) and limited in scope compared to the things you can do in the Rust compiler.

Has there ever been consideration to abstracting some of the compiler code out into it's own crate that can be used by other languages? Has anyone ever attempted such a thing before? What would be the compiler teams thoughts on doing such a thing? I guess you'd lose some control over altering that code as quickly, but I suspect it's reasonably mature at this point too (at a guess).

I ask largely as I want to be able to output things in a similar style for something I'm writing but don't want to start depending on (and pretty sure it might not even be possible without pulling in large chunks of) the compiler code, no thank you.

Kind regards and thanks in advance,

Steven

You are probably looking for annotate-snippets. Cargo uses it already and rustc has an unstable option to use it, but doesn't yet unconditionally use it because it isn't yet on part with the builtin error formatter of rustc.

6 Likes

Awesome, thank you so much, I'll take a look. I've been searching for two days, should've clearly looked more carefully at the Cargo.toml in rustc_errors.

1 Like

Besides annotate-snippets, which is already being worked on to reach parity, you can also look at miette, if you want something more "fancy".

3 Likes

There is also ariadne.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.