@@ -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
@@ -115,18 +120,54 @@ will emit an unknown configuration lint:
115
120
#![cfg_alias(some_alias = true)]
116
121
```
117
122
118
- RFC Question:
123
+ _ RFC question: "usable only after definition" is mentioned here to retain the
124
+ ability to parse attributes in order, rather than going back and updating
125
+ earlier attributes that may use the alias. Is this a reasonable limitation to
126
+ keep?_
127
+
128
+ _ RFC question: two ways to implement this are with (1) near-literal
129
+ substitution, or (2) checking whether the alias should be set or not at the time
130
+ it is defined. Is there any user-visible behavior that would make us need to
131
+ specify one or the other?_
132
+
133
+ _ If we go with the first option, we should limit to a single expansion to avoid
134
+ recursing (as is done for ` #define ` in C)._
135
+
136
+ ## ` cfg_alias ` in non-crate attributes
137
+
138
+ ` cfg_alias ` may also be used as a module-level attribute rather than
139
+ crate-level:
140
+
141
+ ``` rust
142
+ #[cfg_alias(foo = bar)]
143
+ mod uses_bar {
144
+ // Enabled/disabled based on `cfg(bar)`
145
+ #[cfg(foo)]
146
+ fn qux () { /* ... */ }
147
+ }
148
+
149
+ #[cfg_alias(foo = baz)]
150
+ mod uses_baz {
151
+ // Enabled/disabled based on `cfg(baz)`
152
+ #[cfg(foo)]
153
+ fn qux () { /* ... */ }
154
+ }
155
+ ```
119
156
120
- Two ways to implement this are with (1) near-literal substitution, or (2)
121
- checking whether the alias should be set or not at the time it is defined. Is
122
- there any user-visible behavior that would make us need to specify one or the
123
- other?
157
+ This has the advantage of keeping aliases in closer proximity to where they are
158
+ used; if a configuration pattern is only used within a specific module, an alias
159
+ can be added at the top of the file rather than making it crate-global.
124
160
125
- If we go with the first option, we should limit to a single expansion to avoid
126
- recursing (as is done for ` #define ` in C).
161
+ When defined at a module level, aliases are added to the configuration namespace
162
+ for everything within that module including later module-level configuration.
163
+ There is no conflict with aliases that use the same name in other modules.
127
164
128
- [ ^ check-cfg ] : ` --check-cfg ` is included here because it indicates there may be a
129
- corresponding ` --cfg ` .
165
+ This RFC proposes that the use of ` cfg_alias ` on modules _ should_ be included if
166
+ possible. However, this may bring implementation complexity since, to the RFC
167
+ author's knowledge, the rustc configuration system is not designed to allow
168
+ scoped configuration. If implementation of module-level aliases turns out to be
169
+ nontrivial, this portion of the feature may be deferred or dropped before
170
+ stabilization.
130
171
131
172
# Drawbacks
132
173
0 commit comments