Skip to content

Commit 0031617

Browse files
author
Elliott Slaughter
committed
rustc: Add cfg(gc) and cfg(nogc).
Needed in libcore to determine whether core::gc is being compiled with GC on or not, which then affects various safety checks to avoid collecting memory the GC is itself using.
1 parent adf9fa2 commit 0031617

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/rustc/driver/driver.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,29 @@ fn default_configuration(sess: session, argv0: ~str, input: input) ->
6262
mk(~"build_input", source_name(input))];
6363
}
6464

65+
fn append_configuration(cfg: ast::crate_cfg, name: ~str) -> ast::crate_cfg {
66+
if attr::contains_name(cfg, name) {
67+
return cfg;
68+
} else {
69+
return vec::append_one(cfg, attr::mk_word_item(name));
70+
}
71+
}
72+
6573
fn build_configuration(sess: session, argv0: ~str, input: input) ->
6674
ast::crate_cfg {
6775
// Combine the configuration requested by the session (command line) with
6876
// some default and generated configuration items
6977
let default_cfg = default_configuration(sess, argv0, input);
7078
let user_cfg = sess.opts.cfg;
7179
// If the user wants a test runner, then add the test cfg
72-
let gen_cfg =
73-
{
74-
if sess.opts.test && !attr::contains_name(user_cfg, ~"test") {
75-
~[attr::mk_word_item(~"test")]
76-
} else {
77-
~[attr::mk_word_item(~"notest")]
78-
}
79-
};
80-
return vec::append(vec::append(user_cfg, gen_cfg), default_cfg);
80+
let user_cfg = append_configuration(
81+
user_cfg,
82+
if sess.opts.test { ~"test" } else { ~"notest" });
83+
// If the user requested GC, then add the GC cfg
84+
let user_cfg = append_configuration(
85+
user_cfg,
86+
if sess.opts.gc { ~"gc" } else { ~"nogc" });
87+
return vec::append(user_cfg, default_cfg);
8188
}
8289

8390
// Convert strings provided as --cfg [cfgspec] into a crate_cfg

0 commit comments

Comments
 (0)