tkaitchuck / constrandom

Macro to generate random constants in Rust https://xkcd.com/221/
Apache License 2.0
73 stars 14 forks source link

Use native #[proc_macro] support if rustc is new enough #21

Closed AlexTMjugador closed 2 years ago

AlexTMjugador commented 2 years ago

According to its own readme, the proc-macro-hack crate was superseded by native support for #[proc_macro] in expression position in Rust 1.45. Besides that, proc-macro-hack is known to cause issues with rust-analyzer, a popular language server for Rust. A somewhat important consequence of these issues is that using the const_random macro makes Rust Analyzer yield an spurious "unresolved macro" error, which is annoying.

To improve on this situation without explicitly bumping MSRV, let's use native rustc support when available. This can slightly modify the macro hygiene, although I didn't notice any glaring difference.

Related Rust Analyzer project issues and PRs: https://github.com/rust-analyzer/rust-analyzer/issues/7221 https://github.com/rust-analyzer/rust-analyzer/pull/9128