duplicate icon indicating copy to clipboard operation
duplicate copied to clipboard

Confusing error message when not using parametric substitution correctly

Open Emoun opened this issue 3 years ago • 1 comments

Situation:

When trying to use parametric substitution but forgetting to encapsulate the argument to a parametrized identifier in [], the resulting error message is confusing.

Reproduction:

A simple example is to try and create a duplicate with and without &:

#[duplicate(refs(T); [& T]; [T])]
fn from(x: refs(Bits<1, false>)) -> bool {
    x.value == 1
}

Expected Behavior:

An error message pointing out that the argument to refs is not encapsulated in [].

Actual Behavior:

The error message:

message: Error substituting identifier with arguments: ()

Affected Versions:

Only tested on 0.3.0

Local Environment:

Using default features

Miscellaneous:

Emoun avatar Sep 10 '21 16:09 Emoun

Implementing better error messages cannot commence before we have a test setup ready for testing the error messages. Such a test setup should be very similar to our expand-tests using macrotest. However, the difference is that the existing tests check that compilation succeeds while the tests needed here check that compilation fails with some error. This cannot be done using macrotest. trybuild is available for this. However, as our experience has shown (eupn/macrotest#41, eupn/macrotest#43), trybuild will need the ability to configure features at the least (see dtolnay/trybuild#108).

Emoun avatar Sep 14 '21 10:09 Emoun

Using duplicate_macrotest finally allows to test errors.

Fixed awaiting next release.

Emoun avatar Feb 26 '23 23:02 Emoun