External Publication
Visit Post

Parser error recovery in `syn` for better IDE support with proc-macros

Rust Internals [Unofficial] May 31, 2026
Source
  • For attribute macros and derive macros, if the macro is getting called at all, you know that rustc thinks that the item is valid syntax and will not be producing an error. if you then get a syn parse error, then you must be in a case where syn doesn’t support the syntax rustc does, and in that case you had better tell the user that that’s the problem, because rustc won’t.

  • For function-like macros that take expressions (or whatever existing syntax applies in the context of the macro call) as input, you can't know whether rustc will think your input is valid syntax or not, and it might be the case that if you just produce the input, there won’t be any syntax error and the user will be confused.

In both of these cases, you can’t be sure that just repeating the input will produce a syntax error. It may, as I said previously, just result in your macro mysteriously having no effect.

Discussion in the ATmosphere

Loading comments...