Why is mainstream Rust so macro-heavy?

tokio::select! panics if it can't match any arms; the compiler could detect this condition if select! was actual syntax.

This can be (partially) mitigated by library authors. Macros can be written in ways that don't severely obstruct IDE and compiler features.

For example, a function attribute proc-macro using syn might go the easy way of parsing the entire function using ItemFn::parse.

This causes the macro to short-circuit on invalid Rust syntax in the function code block. As you might've noticed, this kind of obliterates IDE feature availability when in the middle of making changes to the block.

Parsing like this is of course expected syn usage, but in the majority of such cases, only the function signature is relevant to the library author (as inner block code can vary so significantly between use cases).

In cases where the code block *is* relevant, direct token substitution can often work too. The more complicated the change you're trying to apply via macro is, the more work it'll require to parse it properly. There is some form of invisible line somewhere that would tell us where it makes sense to actually rely on a full item parse.

But in the trivial case, it genuinely makes sense to simply parse the function signature directly and paste the rest of the token buffer without checking its correctness. This way we forward any syntax errors to the compiler and get most of what we want back (macro doesn't short circuit in most cases). This can also be more performant in terms of compilation time.

The other half of this is, the way a macro does error handling and error reporting matters a lot, too. It is up to the library author to expose error information in a useful way. After all, macros are kind of the compiler escape hatch – it makes perfect sense that this responsibility would shift from the compiler to the programmer. There are plenty of tools macro authors can take advantage of to make this a little better – a good example is proc-macro-error2 – via proper error span attribution and error case coverage.

Macros aren't perfect, and there are more issues my response doesn't go over, but some of the problem you're describing could be attributed to library authors, instead of the fundamentals of the system we work with. I hope I was able to highlight the issue in a useful manner through this analogy.

I also wanted to add that any arguments related to macros causing obfuscation are missing the point IMO. The amount of obfuscation caused by macros is intentional and variable. A macro can choose to change very little (extracting and using information) or it can just as well invent new syntax – this is up to the author. We are free to refuse to use tools that don't fit our needs. If a crate doesn't expose the ability to use one of its features proper without relying on macros, this should be filed as an issue – not everyone can accept the compile-time cost.