power-assert-rs icon indicating copy to clipboard operation
power-assert-rs copied to clipboard

Rewrite using proc-macro-hack

Open roblabla opened this issue 7 years ago • 4 comments

Hey,

It's now possible to create functionlike!() proc macros on stable rust using proc-macro-hack.

I'm going to try rewriting power-assert-rs using it.

roblabla avatar Oct 18 '18 13:10 roblabla

Actually, this is impossible because of https://github.com/dtolnay/proc-macro-hack/issues/15.

Proc Macros are going to be stabilized on 1.30, but they won't be able to expand to expressions. Furthermore, this proc macro would rely on spans, which are also unstable still. I'll rewrite it using those feature so they work on the latest nightly.

roblabla avatar Oct 19 '18 11:10 roblabla

https://github.com/roblabla/power-assert-rs

here's a WIP port to Proc Macros 1.30. It has several problems:

  • It hits https://github.com/alexcrichton/proc-macro2/issues/110
  • It uses a doc hidden'd function from proc_macro2: Span::unstable(), in order to avoid the semver_exempt cfg flag.
  • It requires two nightly features: proc_macro_hygiene and proc_macro_span

roblabla avatar Oct 19 '18 15:10 roblabla

I released proc-macro-hack 0.5.0 which preserves spans and supports expanding to expressions.

dtolnay avatar Oct 31 '18 19:10 dtolnay

There’s a PR open to recover the raw string of a Span: https://github.com/rust-lang/rust/pull/55780. It will be feature gated behind proc_macro_span.

Once it lands, I’ll update my fork, and it’ll likely be usable (albeit nightly only)

roblabla avatar Nov 20 '18 10:11 roblabla