@@ -97,8 +97,13 @@ CfgAliasAttribute:
97
97
cfg_alias(IDENTIFIER `=` ConfigurationPredicate)
98
98
```
99
99
100
- The identifier is added to the ` cfg ` namespace. It must not conflict with any
101
- builtin configuration names, or with those passed via ` --cfg ` or ` --check-cfg ` . [ ^ check-cfg ]
100
+ The identifier is added to the ` cfg ` namespace. It must not conflict with:
101
+
102
+ - Any builtin configuration names
103
+ - Any configuration passed via ` --cfg `
104
+ - Any configuration passed with ` --check-cfg ` , since this indicates a possible
105
+ but omitted ` --cfg ` option
106
+ - Other aliases that are in scope
102
107
103
108
Once defined, the alias can be used as a regular predicate.
104
109
@@ -125,8 +130,38 @@ other?
125
130
If we go with the first option, we should limit to a single expansion to avoid
126
131
recursing (as is done for ` #define ` in C).
127
132
128
- [ ^ check-cfg ] : ` --check-cfg ` is included here because it indicates there may be a
129
- corresponding ` --cfg ` .
133
+ ## Optional: ` cfg_alias ` in non-crate attributes
134
+
135
+ At a language level, it should be possbile to allow using ` cfg_alias ` as a
136
+ module-level attribute rather than crate-level:
137
+
138
+ ``` rust
139
+ #[cfg_alias(foo = bar)]
140
+ mod uses_bar {
141
+ // Enabled/disabled based on `cfg(bar)`
142
+ #[cfg(foo)]
143
+ fn qux () { /* ... */ }
144
+ }
145
+
146
+ #[cfg_alias(foo = baz)]
147
+ mod uses_baz {
148
+ // Enabled/disabled based on `cfg(baz)`
149
+ #[cfg(foo)]
150
+ fn qux () { /* ... */ }
151
+ }
152
+ ```
153
+
154
+ This has the advantage of keeping aliases in closer proximity to where they are
155
+ used; if a configuration pattern is only used within a specific module, an alias
156
+ can be added at the top of the file rather than making it crate-global.
157
+
158
+ This RFC proposes that the use of ` cfg_alias ` on modules _ should_ be included if
159
+ possible. However, this may bring implementation complexity since (to the RFC
160
+ author's knowledge), the rustc configuration system is not designed to allow
161
+ scoped configuration.
162
+
163
+ If implementation of module-level aliases turns out to be nontrivial, this
164
+ portion of the feature may be deferred or dropped before stabilization.
130
165
131
166
# Drawbacks
132
167
0 commit comments