This would require `proc_macro::SourceFile` to be stabilized (or a similar API): https://github.com/rust-lang/rust/issues/54725 Probably would require fixing https://github.com/rust-lang/rust/issues/62892 We could make it work on nightly using `--cfg procmacro2_semver_exempt` but that's a half-measure.