Deprecate procedural macro

Hi guys, What's the best/idiomatic way to deprecate a procedural macro? I tried by use deprecate attribute but seams that not works like I'm expecting should work: it print the warning message while the procedural macro crate compiling (even without any use) but not at the call side.

The only way that I find to do it is to use diagnostic API in nightly or print a message on stderror in stable. But I'm wondering that there isn't any simpler way.


I guess you could generate some code that triggers a deprecate warning as part of the macro output, with the right span.

Hm, deprecated on proc macros should work, we even have a test.
This was recently implemented though, so I'm not sure the change is on stable.

1 Like

Ok, I checked, it works on beta but it shows also warning while compiling crate that spam the complete procedural macro code.

michele@DartVader:~/learning/rust/rstest/playground$ cargo +beta test
   [OMIS ...]
   Compiling rstest v0.4.1 (/home/michele/learning/rust/rstest)
warning: use of deprecated item 'rstest_parametrize': Please use just rstest instead (rstest_parametrize will be removed soon).
   --> /home/michele/learning/rust/rstest/src/
871 | / pub fn rstest_parametrize(args: proc_macro::TokenStream, input: proc_macro::TokenStream)
872 | |                           -> proc_macro::TokenStream
873 | | {
874 | |     rstest(args, input)
875 | | }
    | |_^
    = note: `#[warn(deprecated)]` on by default

   Compiling playground v0.1.0 (/home/michele/learning/rust/rstest/playground)
warning: use of deprecated item 'rstest_parametrize': Please use just rstest instead (rstest_parametrize will be removed soon).
 --> src/
6 | #[rstest_parametrize(a, case(10))]
  |   ^^^^^^^^^^^^^^^^^^
  = note: `#[warn(deprecated)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 18.52s
     Running target/debug/deps/playground-6d176a6696915b8f

running 2 tests
test should_not_deprecate::case_1 ... ok
test should_deprecate::case_1 ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

That make this feature unusable in beta too :frowning:


1 Like

@petrochenkov maybe the test check just if deprecation is present ... but nothing about others warning that the compiler emit.

Should I file a ticket for this behavior in beta?

Yeah, please fill an issue.
I suspect that the use of the proc macro function from the proc macro harness triggers the warning.