Rustc output filter plugins

Code which engages in type-level programming tends to produce compiler error messages unfit for human consumption.

For example uom produces compiler error messages containing (many occurrences of) beauties such as this:

Quantity<(dyn Dimension<L = PInt<UInt<UTerm, B1>>, J = Z0, Kind = (dyn Kind +
'static), N = Z0, T = NInt<UInt<UInt<UTerm, B1>, B0>>, M = Z0, Th = Z0, I = Z0>
+ 'static), (dyn uom::si::Units<f32, luminous_intensity =
uom::si::luminous_intensity::candela, mass = uom::si::mass::kilogram, length =
uom::si::length::meter, time = uom::si::time::second, thermodynamic_temperature
= uom::si::thermodynamic_temperature::kelvin, amount_of_substance =
uom::si::amount_of_substance::mole, electric_current =
uom::si::electric_current::ampere> + 'static), f32>

To make this fit for human consumption, it should be translated to something like this

Quantity<m^1 s^-2, Kind, f32>

or, in relatively rare cases where more detail is needed, maybe something like this

Quantity<m^1 s^-2, Kind, f32; L=meter M=kilogram T=second I=ampere Th=kelvin N=mole J=candela>

uom itself depends on typenum for which tnfilt is able to perform transformations such as these:

  • PInt<UInt<UTerm, B1>> -> PInt<U1>
  • NInt<UInt<UInt<UTerm, B1>, B0>> -> NInt<U2>

tnfilt is simply a parser written in nom into which you pipe the output of rustc.

I was thinking of writing something similar for uom but it strikes me that

  • Rather than writing an ad-hoc parser for rustc output, perhaps there is a way to hook into and take advantage of the internals of rustc. This could
    1. make the job of parsing the output easier;
    2. make rustc aware of the modified output, so that the filtered version is integrated correctly into the rest of the output.
  • There are many crates that do type-level programming. Rather than each one facing and solving this kind of problem on its own and producing incompatible solutions, perhaps there is some way to share the burden and have solutions that cooperate rather than interfere with each other.

Is there a way to use the internals of rustc to help in writing such filters?

Would it be possible to write these as plugins to rustc, to make the rustc incorporate the modified messages directly in its output, rather than having to pipe rustc output through the filter?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.