gccrs
gccrs copied to clipboard
Have error classes for simpler emission and more factoring
Something we might start to think about doing is for every error diagnostic have some kind of class for them all, so we can enforce good error messages so for example we might have:
class ErrorDiagnostics {
static void StaticMutableUnsafe(Location) {
Originally posted by @philberty in https://github.com/Rust-GCC/gccrs/pull/1417#pullrequestreview-1052766761
I think a good interface would be the following:
class Emittable {
Location locus;
std::string msg;
unsigned error_code;
void emit() {
rust_error_at(locus, msg); // or similar
}
}
class ErrorStaticMutableUnsafe: public Emittable {
/* ... */
}
I wonder if there is something we can do better with an enum class
or similar
ACK. In context of thinking about re-using the rustc
error codes (that was even before @davidmalcolm's #1408 "Experiment: add optional error codes to diagnostics"), I also had this thought: whether there's a point to be made to maintain all GCC/Rust front end diagnostics in a central place.
Might also help with getting a feel for how many of the rustc
codes we support, eventually, and where the differences/omissions are?
I'm all for factorisation - it's always easier when searching for where an error occurs to search in a central place, especially with format strings and so on. Plus, if we do want to change an error message, it's always better to change it in a single location.
Might also help with getting a feel for how many of the rustc codes we support, eventually, and where the differences/omissions are?
Yes, that'd be great. That's why I think we'd need to keep an enum
for error codes as it would be very easy to see which ones we support
FWIW, something I've done in the C/C++ frontends is to have some custom rich_location subclasses, for highlighting the things of interest to particular kinds of diagnostic. See e.g. class binary_op_rich_location
in gcc/gcc-rich-location.h
. Though this might be orthogonal to this suggestion.
This issue was fixed by these PR's:
- [x] https://github.com/Rust-GCC/gccrs/pull/2468
- [x] https://github.com/Rust-GCC/gccrs/pull/2480
- [x] https://github.com/Rust-GCC/gccrs/pull/2518
- [x] https://github.com/Rust-GCC/gccrs/pull/2395