Rustc's json output format

So, here's my current report on the usability of the json output:

"expected X, got Y" errors

These are split into two children without spans. There's a few ways that they could be improved.

  1. for types, the error could give the span of the reason for the expected. So if it's a function argument, give a span for that argument's declaration.
  2. these are so common in rustc that there's special code processing this kind of text into multiple lines
  • json should profit from this, too, maybe an expected field?
  1. these should not be split up, but I'm not sure how to do this better, other than 2.

multiple suggested imports

To automate future 1-click-solutions, instead of listing them in the current note manner, the suggested_replacement could be used to offer inserting a new line on the top of the file with use xyz;.

suggestions for suggestions

  1. remove the suggested_replacement field, and instead add a new "error level".
  2. generally use suggestions more often. E.g. in unresolved name errors

the label field

I've so far ignored it. Many errors do not set it, and with those that do set it, I've found that I can't replace the main message, and that it's partially redundant with the notes. An example is a type-mismatch. let _: () = 5; gives "type mismatch" for the message, expected type '()' and got type '_' for the notes, and then "expected (), found integral variable" for the label. The label is nicer than the notes, but still needs the message.

I could simply show it when it's there, but I don't want to clutter the error popups with redundancy.

#Macro Expansion

I'm not sure how to improve on this yet. An alternative would be to repeat the error at every expansion location. Or just show something at the location of the expansion.

#WIP

Anyway, this is a work in progress. If anyone has ideas what to try out, I'll check how it works and post some screenshots.

1 Like