External Publication
Visit Post

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

Rust Internals [Unofficial] June 3, 2026
Source

I meant that in terms of diagnostics ultimately shown to the user, not proc macro developer experience. I solved that with precedence to emulate Rustc's behaviour in my crates.

I think the proc_macro2_diagnostic-API is a bit sketchy for recovering parsers too though, since you'd have to smuggle errors in the "warning" variant to do so. I'd have to see some example code, but I think having to aggregate manually also makes it a bit more verbose than my approach of just adding , errors to nested parser calls when parsing a sequence of recovering elements. Ymmv on whether you'd like to make forwarding or local handling of side-channel errors easier, of course. I personally find the former easier since, with precedence levels, I don't need local diagnostics handling at all in my macros.

Edit: I missed that the Warning variant emits when Tryd. Hm, not a huge fan of subtle side effects like that, to be honest, but that's personal preference.

Discussion in the ATmosphere

Loading comments...