Hacker News new | ask | show | jobs
by ibraheemdev 1987 days ago
One problem with the macros approach is that you get really hard to understand error messages. For example, if a user wrote a method where one of the arguments did not implement ToPolarValue, they would get the following error:

  fn blah(blah: Blah)
  ^^^^^^^^^^^^^^^^^^^ the trait bound Method<_, _> is not satisfied
As opposed to something like this with variadic generics:

  fn blah(blah: Blah)
                ^^^^ the trait bound ToPolarValue is not satisfied
1 comments

There is an accepted and partially implemented RFC [1] that can improve proc macro error messages a lot.

Sadly it hasn't been worked on in years.

[1] https://github.com/rust-lang/rust/issues/54140

proc macro diagnostics are a cool feature, but they would not help here. Here, macros are being used to generate implementations of a trait. If the trait bound is not satisfied, you have no way of knowing why other than that there was no implementation generated for it, hence the confusing error message. With variadic generics however, you could write something like:

  Fn(..Args) -> T
which I assume would let the compiler know why the trait bound is not satisfied and output a nicer error message.