Anyone who has used crates like diesel
or frunk
is aware of the long error messages which can be generated. Here is an example frunk error from a real project:
error[E0599]: no method named
convert
found for typefrunk_core::hlist::HCons<(conversion::v4_0::Out<'_>, frunk_core::labelled::Field<(frunk_core::labelled::chars::c, frunk_core::labelled::chars::a, frunk_core::labelled::chars::t, frunk_core::labelled::chars::e, frunk_core::labelled::chars::g, frunk_core::labelled::chars::o, frunk_core::labelled::chars::r, frunk_core::labelled::chars::y, frunk_core::labelled::chars::__, frunk_core::labelled::chars::n, frunk_core::labelled::chars::a, frunk_core::labelled::chars::m, frunk_core::labelled::chars::e), &std::option::Option<std::string::String>>), frunk_core::hlist::HCons<(conversion::v4_0::Out<'_>, frunk_core::labelled::Field<(frunk_core::labelled::chars::m, frunk_core::labelled::chars::a, frunk_core::labelled::chars::t, frunk_core::labelled::chars::c, frunk_core::labelled::chars::h, frunk_core::labelled::chars::e, frunk_core::labelled::chars::r, frunk_core::labelled::chars::__, frunk_core::labelled::chars::n, frunk_core::labelled::chars::a, frunk_core::labelled::chars::m, frunk_core::labelled::chars::e), &std::option::Option<std::string::String>>), frunk_core::hlist::HCons<(conversion::v4_0::Out<'_>, frunk_core::labelled::Field<(frunk_core::labelled::chars::m, frunk_core::labelled::chars::e, frunk_core::labelled::chars::s, frunk_core::labelled::chars::s, frunk_core::labelled::chars::a, frunk_core::labelled::chars::g, frunk_core::labelled::chars::e), &std::option::Option<std::string::String>>), frunk_core::hlist::HCons<(conversion::v4_0::Out<'_>, frunk_core::labelled::Field<(frunk_core::labelled::chars::t, frunk_core::labelled::chars::y, frunk_core::labelled::chars::p, frunk_core::labelled::chars::e, frunk_core::labelled::chars::__), &std::option::Option<String>>), frunk_core::hlist::HNil>>>>
in the current scope
In this case, it would dramatically improve the error message if frunk could override the way that the Field
and HCons
types are displayed inside error messages, turning the above message into something like this:
error[E0599]: no method named
convert
found for typehlist![(conversion::v4_0::Out<'_>, field!(category_name, &std::option::Option<std::string::String>), (conversion::v4_0::Out<'_>, field!(matcher_name, &std::option::Option<std::string::String>), (conversion::v4_0::Out<'_>, field!(message, &std::option::Option<std::string::String>), (conversion::v4_0::Out<'_>, field!(type_, &std::option::Option<std::string::String>)]
in the current scope
This is still valid rust syntax, it's just "re-macroing" the types to save space.
One way this could be implemented is via a special trait with a const fn
method to return the type name. Frunk could implement this method for the HCons
, HNil
, Field
types to provide better human-readable names, although this would require the ability to construct strings inside const functions.