pre icon indicating copy to clipboard operation
pre copied to clipboard

Apply `assure` and `forward` directly to expressions

Open ErichDonGubler opened this issue 5 years ago • 3 comments

~Rust 1.45 lifts the restriction that proc-macros cannot be invoked in expression and statement position, which is the restriction referred to as the reason for needing a #[pre] macro on items using #[assure(...)] in the latest (0.2.0) crate docs:~

Doing this is currently necessary, because the current (1.44.1) stable rust compiler does not support attribute macros being applied to statements or expressions directly.

~What are plans for this crate now that this restriction has been lifted? Is any help needed to, say, lift the constraint that #[pre] needs to be applied to items?~

The premise of the question is invalid, but @aticu has left this issue open and renamed it appropriately.

ErichDonGubler avatar Aug 07 '20 16:08 ErichDonGubler

Unfortunately this restriction has only been lifted for function-like proc-macros. pre uses attribute proc-macros, where this restriction still applies.

The following code still fails on 1.45

fn main() {
    unsafe {
        #[test_macro]
        foo()
    }
}

with this error message

error[E0658]: attributes on expressions are experimental
 --> src/main.rs:7:9
  |
7 |         #[test_macro]
  |         ^^^^^^^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information

error[E0658]: custom attributes cannot be applied to expressions
 --> src/main.rs:7:9
  |
7 |         #[test_macro]
  |         ^^^^^^^^^^^^^
  |
  = note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information

error: aborting due to 2 previous errors

I guess this issue could be left open though, until that limitation can be lifted.

aticu avatar Aug 07 '20 17:08 aticu

Ergh, I obviously misunderstood the situation. Thanks for the patient response. :)

ErichDonGubler avatar Aug 07 '20 20:08 ErichDonGubler

Ergh, I obviously misunderstood the situation.

No worries, I had to double check as well, when I read the patch notes.

aticu avatar Aug 07 '20 20:08 aticu