Skip to main content

Module cfg_gates

Module cfg_gates 

Source
Expand description

Resolve cfg / cfg_attr on the members of a #[miniextendr] item before anything is generated from it.

An attribute macro receives its item unconfigured: rustc has not evaluated the gates on the item’s methods, trait items, parameters, variants or fields. Forwarding a member’s gate to some generated items is not enough, because item-wide analysis (constructor inference, S7 properties, name collisions, factor levels, R formals) and the generated R text must see the same members the compiled item has. So the macro re-enters itself on two gated copies of the item, one per value of the first member gate it finds. rustc strips the inactive copy before expanding it, so each pass resolves one gate and configurations are never enumerated. The item stays whole: splitting an impl into separately registered blocks would change constructor inference and the ownership of S7 properties.

Gates on the item itself need no re-entry: rustc evaluates them when they precede #[miniextendr], and the expansion forwards them otherwise.

Re-exportsΒ§

use proc_macro2::TokenStream; πŸ”’
use quote::quote; πŸ”’
use syn::Attribute; πŸ”’
use syn::Item; πŸ”’
use syn::Meta; πŸ”’
use syn::Token; πŸ”’
use syn::punctuated::Punctuated; πŸ”’

FunctionsΒ§

member_attrs πŸ”’
member_attrs_mut πŸ”’
Only called for a member member_attrs returned.
member_count πŸ”’
Number of gateable members: function parameters, impl and trait items, enum variants, struct fields.
remove_at πŸ”’
remove_member πŸ”’
select πŸ”’
Re-enter #[miniextendr(attr)] on both resolutions of the item’s first member gate, or return None when no member carries one.