Closed
Description
Given code like this
#![feature(decl_macro)]
#![cfg(someflagthatisnotset)]
pub macro mymacro() {}
what I expect should happen is that this works fine, since the feature flag is set so the parser should accept parsing the pub macro
, and also the file is anyway empty after cfg
expansion. However, I get a warning instead:
warning: `macro` is experimental
--> src/lib.rs:4:1
|
4 | pub macro mymacro() {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: [see issue #39412 <https://github.com/rust-lang/rust/issues/39412>](https://github.com/rust-lang/rust/issues/39412) for more information
= help: [add `#![feature(decl_macro)]`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) to the crate attributes to enable
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, [see issue #65860 <https://github.com/rust-lang/rust/issues/65860>](https://github.com/rust-lang/rust/issues/65860)
It looks like the cfg
does disable the feature flag, but does not disable parsing of the rest of the file. That is a problem, since it means it is impossible to cfg
-out an entire file that contains experimental syntax. I thought I could fix this by ordering the cfg
after the feature
, but as the example shows that does not help.
This probably started happening with #99935.
Cc @CAD97 @petrochenkov