Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document behavior of #[cfg] in macros #836

Open
RalfJung opened this issue Jun 22, 2020 · 2 comments
Open

Document behavior of #[cfg] in macros #836

RalfJung opened this issue Jun 22, 2020 · 2 comments
Labels
A-attributes Area: Attributes A-macros Area: Macros

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 22, 2020

The macro reference should explain how #[cfg] and #[cfg_attr(...)] behave inside macros.

Does this macro check the allow_clippy flag of the crate the macro is defined in, or of the crate the macro is used in?

macro_rules! field_check {
    ($type:path, $field:tt) => {
        // Make sure the field actually exists. This line ensures that a
        // compile-time error is generated if $field is accessed through a
        // Deref impl.
        #[cfg_attr(allow_clippy, allow(clippy::unneeded_field_pattern))]
        let $type { $field: _, .. };
    };
}
@ehuss ehuss added A-attributes Area: Attributes A-macros Area: Macros labels Jun 22, 2020
@ehuss
Copy link
Contributor

ehuss commented Jun 22, 2020

I assume you are interested in more than just allow/deny diagnostic behavior. I mention that because I believe (some?) diagnostics have special behavior in external macros where they are disabled. The reference has historically shied away from documenting diagnostics, so that particular behavior is a bit of a gray area, but probably should be mentioned.

There are a few other behaviors of cfg/cfg_attr that I'd like to see documented (#565, #103). In particular, I think the order of transformations ("phases of translation" in C++ parlance) would be useful to specify to make it clear when cfg processing is done in relation to other phases.

@RalfJung
Copy link
Member Author

I assume you are interested in more than just allow/deny diagnostic behavior.

Yes, I wonder about cfg in general (including cfg!). I didn't even know diagnostics have some special magic hacks.^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes A-macros Area: Macros
Projects
None yet
Development

No branches or pull requests

2 participants