File tree 3 files changed +82
-1
lines changed
3 files changed +82
-1
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,22 @@ pub fn compile_rest(sess: Session,
188
188
* sess. building_library = session:: building_library (
189
189
sess. opts . crate_type , crate_opt. unwrap ( ) , sess. opts . test ) ;
190
190
191
+ // strip before expansion to allow macros to depend on
192
+ // configuration variables e.g/ in
193
+ //
194
+ // #[macro_escape] #[cfg(foo)]
195
+ // mod bar { macro_rules! baz!(() => {{}}) }
196
+ //
197
+ // baz! should not use this definition unless foo is enabled.
198
+ crate_opt = Some ( time ( time_passes, ~"configuration 1 ", ||
199
+ front:: config:: strip_unconfigured_items ( crate_opt. unwrap ( ) ) ) ) ;
200
+
191
201
crate_opt = Some ( time ( time_passes, ~"expansion", ||
192
202
syntax:: ext:: expand:: expand_crate ( sess. parse_sess , copy cfg,
193
203
crate_opt. unwrap ( ) ) ) ) ;
194
204
195
- crate_opt = Some ( time ( time_passes, ~"configuration", ||
205
+ // strip again, in case expansion added anything with a #[cfg].
206
+ crate_opt = Some ( time ( time_passes, ~"configuration 2 ", ||
196
207
front:: config:: strip_unconfigured_items ( crate_opt. unwrap ( ) ) ) ) ;
197
208
198
209
crate_opt = Some ( time ( time_passes, ~"maybe building test harness", ||
Original file line number Diff line number Diff line change
1
+ // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // xfail-fast compile-flags directive doesn't work for check-fast
12
+ // compile-flags: --cfg foo
13
+
14
+ // check that cfg correctly chooses between the macro impls (see also
15
+ // cfg-macros-notfoo.rs)
16
+
17
+ #[ cfg( foo) ]
18
+ #[ macro_escape]
19
+ mod foo {
20
+ macro_rules! bar {
21
+ ( ) => { true }
22
+ }
23
+ }
24
+
25
+ #[ cfg( not( foo) ) ]
26
+ #[ macro_escape]
27
+ mod foo {
28
+ macro_rules! bar {
29
+ ( ) => { false }
30
+ }
31
+ }
32
+
33
+ fn main ( ) {
34
+ assert ! ( bar!( ) )
35
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // xfail-fast compile-flags directive doesn't work for check-fast
12
+ // compile-flags:
13
+
14
+ // check that cfg correctly chooses between the macro impls (see also
15
+ // cfg-macros-foo.rs)
16
+
17
+ #[ cfg( foo) ]
18
+ #[ macro_escape]
19
+ mod foo {
20
+ macro_rules! bar {
21
+ ( ) => { true }
22
+ }
23
+ }
24
+
25
+ #[ cfg( not( foo) ) ]
26
+ #[ macro_escape]
27
+ mod foo {
28
+ macro_rules! bar {
29
+ ( ) => { false }
30
+ }
31
+ }
32
+
33
+ fn main ( ) {
34
+ assert ! ( !bar!( ) )
35
+ }
You can’t perform that action at this time.
0 commit comments