#macro #error #spans #error-message #improve #information

nightly macro scrub

Remove span information to improve error messages

1 unstable release

0.1.0 Dec 27, 2023

#2484 in Development tools

MIT/Apache

7KB
63 lines

scrub

A macro for letting macros absolve themselves of guilt, blaming any and all errors on their callers.

For example, consider a macro that has as its contract that the input must be an expression of a specific type. If a caller breaks this contract, a part of the macro body is highlighted as the error cause, even though it obviously was the caller's fault.

error[E0308]: mismatched types
 --> examples/blame.rs:3:7
  |
3 |         let () = $e;
  |             ^^ expected `A`, found `()`
...
9 |     b!(A);
  |     -----
  |     |  |
  |     |  this expression has type `A`
  |     in this macro invocation

Now you can finally tell those callers whose fault it really is.

error[E0308]: mismatched types
  --> examples/blameless.rs:11:2
   |
11 |     b!(A);
   |     ^^^-^
   |     |  |
   |     |  this expression has type `A`
   |     expected `A`, found `()`

Due to using the proc_macro_span feature, this crate requires nightly.


lib.rs:

A macro for letting macros absolve themselves of guilt, blaming any and all errors on their callers.

For example, consider a macro that has as its contract that the input must be an expression of a specific type. If a caller breaks this contract, a part of the macro body is highlighted as the error cause, even though it obviously was the caller's fault.

<style type="text/css"> .diag-r { color: var(--code-highlight-prelude-val-color); } .diag-b { color: var(--code-highlight-prelude-color); } </style>
error[E0308]: mismatched types
 --> examples/blame.rs:3:7
  |
3 |         let () = $e;
  |             ^^ expected `A`, found `()`
...
9 |     b!(A);
  |     -----
  |     |  |
  |     |  this expression has type `A`
  |     in this macro invocation

Now you can finally tell those callers whose fault it really is.

error[E0308]: mismatched types
  --> examples/blameless.rs:11:2
   |
11 |     b!(A);
   |     ^^^-^
   |     |  |
   |     |  this expression has type `A`
   |     expected `A`, found `()`

Due to using the proc_macro_span feature, this crate requires nightly.

No runtime deps