Skip to content

Commit 71fe770

Browse files
Remove the 'cfg' field from session::config::Options.
The 'cfg' in the Options struct is only the commandline-specified subset of the crate configuration and it's almost always wrong to read that instead of the CrateConfig in HIR crate node.
1 parent a40b6ae commit 71fe770

File tree

10 files changed

+74
-240
lines changed

10 files changed

+74
-240
lines changed

src/librustc/session/config.rs

+16-210
Large diffs are not rendered by default.

src/librustc_driver/driver.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,10 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
667667
trace_mac: sess.opts.debugging_opts.trace_macros,
668668
should_test: sess.opts.test,
669669
};
670-
let mut loader = macro_import::MacroLoader::new(sess, &cstore, crate_name);
670+
let mut loader = macro_import::MacroLoader::new(sess,
671+
&cstore,
672+
crate_name,
673+
krate.config.clone());
671674
let mut ecx = syntax::ext::base::ExtCtxt::new(&sess.parse_sess,
672675
krate.config.clone(),
673676
cfg,

src/librustc_driver/lib.rs

+25-13
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
183183
None => return (Ok(()), None),
184184
};
185185

186-
let sopts = config::build_session_options(&matches);
186+
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
187187

188188
if sopts.debugging_opts.debug_llvm {
189189
unsafe { llvm::LLVMRustSetDebug(1); }
@@ -193,14 +193,15 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
193193

194194
do_or_return!(callbacks.early_callback(&matches,
195195
&sopts,
196+
&cfg,
196197
&descriptions,
197198
sopts.error_format),
198199
None);
199200

200201
let (odir, ofile) = make_output(&matches);
201202
let (input, input_file_path) = match make_input(&matches.free) {
202203
Some((input, input_file_path)) => callbacks.some_input(input, input_file_path),
203-
None => match callbacks.no_input(&matches, &sopts, &odir, &ofile, &descriptions) {
204+
None => match callbacks.no_input(&matches, &sopts, &cfg, &odir, &ofile, &descriptions) {
204205
Some((input, input_file_path)) => (input, input_file_path),
205206
None => return (Ok(()), None),
206207
},
@@ -216,10 +217,11 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
216217
cstore.clone(),
217218
codemap);
218219
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
219-
let mut cfg = config::build_configuration(&sess);
220+
let mut cfg = config::build_configuration(&sess, cfg);
220221
target_features::add_configuration(&mut cfg, &sess);
221222

222-
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
223+
do_or_return!(callbacks.late_callback(&matches, &sess, &cfg, &input, &odir, &ofile),
224+
Some(sess));
223225

224226
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
225227
let control = callbacks.build_controller(&sess, &matches);
@@ -299,6 +301,7 @@ pub trait CompilerCalls<'a> {
299301
fn early_callback(&mut self,
300302
_: &getopts::Matches,
301303
_: &config::Options,
304+
_: &ast::CrateConfig,
302305
_: &errors::registry::Registry,
303306
_: ErrorOutputType)
304307
-> Compilation {
@@ -311,6 +314,7 @@ pub trait CompilerCalls<'a> {
311314
fn late_callback(&mut self,
312315
_: &getopts::Matches,
313316
_: &Session,
317+
_: &ast::CrateConfig,
314318
_: &Input,
315319
_: &Option<PathBuf>,
316320
_: &Option<PathBuf>)
@@ -336,6 +340,7 @@ pub trait CompilerCalls<'a> {
336340
fn no_input(&mut self,
337341
_: &getopts::Matches,
338342
_: &config::Options,
343+
_: &ast::CrateConfig,
339344
_: &Option<PathBuf>,
340345
_: &Option<PathBuf>,
341346
_: &errors::registry::Registry)
@@ -377,7 +382,7 @@ fn handle_explain(code: &str,
377382
}
378383
}
379384

380-
fn check_cfg(sopts: &config::Options,
385+
fn check_cfg(cfg: &ast::CrateConfig,
381386
output: ErrorOutputType) {
382387
let emitter: Box<Emitter> = match output {
383388
config::ErrorOutputType::HumanReadable(color_config) => {
@@ -391,7 +396,7 @@ fn check_cfg(sopts: &config::Options,
391396
let handler = errors::Handler::with_emitter(true, false, emitter);
392397

393398
let mut saw_invalid_predicate = false;
394-
for item in sopts.cfg.iter() {
399+
for item in cfg.iter() {
395400
if item.is_meta_item_list() {
396401
saw_invalid_predicate = true;
397402
handler.emit(&MultiSpan::new(),
@@ -409,7 +414,8 @@ fn check_cfg(sopts: &config::Options,
409414
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
410415
fn early_callback(&mut self,
411416
matches: &getopts::Matches,
412-
sopts: &config::Options,
417+
_: &config::Options,
418+
cfg: &ast::CrateConfig,
413419
descriptions: &errors::registry::Registry,
414420
output: ErrorOutputType)
415421
-> Compilation {
@@ -418,13 +424,14 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
418424
return Compilation::Stop;
419425
}
420426

421-
check_cfg(sopts, output);
427+
check_cfg(cfg, output);
422428
Compilation::Continue
423429
}
424430

425431
fn no_input(&mut self,
426432
matches: &getopts::Matches,
427433
sopts: &config::Options,
434+
cfg: &ast::CrateConfig,
428435
odir: &Option<PathBuf>,
429436
ofile: &Option<PathBuf>,
430437
descriptions: &errors::registry::Registry)
@@ -445,7 +452,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
445452
descriptions.clone(),
446453
cstore.clone());
447454
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
448-
let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
455+
let mut cfg = config::build_configuration(&sess, cfg.clone());
456+
target_features::add_configuration(&mut cfg, &sess);
457+
let should_stop = RustcDefaultCalls::print_crate_info(&sess,
458+
&cfg,
459+
None,
460+
odir,
461+
ofile);
449462
if should_stop == Compilation::Stop {
450463
return None;
451464
}
@@ -461,11 +474,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
461474
fn late_callback(&mut self,
462475
matches: &getopts::Matches,
463476
sess: &Session,
477+
cfg: &ast::CrateConfig,
464478
input: &Input,
465479
odir: &Option<PathBuf>,
466480
ofile: &Option<PathBuf>)
467481
-> Compilation {
468-
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
482+
RustcDefaultCalls::print_crate_info(sess, cfg, Some(input), odir, ofile)
469483
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
470484
}
471485

@@ -584,6 +598,7 @@ impl RustcDefaultCalls {
584598

585599

586600
fn print_crate_info(sess: &Session,
601+
cfg: &ast::CrateConfig,
587602
input: Option<&Input>,
588603
odir: &Option<PathBuf>,
589604
ofile: &Option<PathBuf>)
@@ -636,9 +651,6 @@ impl RustcDefaultCalls {
636651
}
637652
}
638653
PrintRequest::Cfg => {
639-
let mut cfg = config::build_configuration(&sess);
640-
target_features::add_configuration(&mut cfg, &sess);
641-
642654
let allow_unstable_cfg = match get_unstable_features_setting() {
643655
UnstableFeatures::Disallow => false,
644656
_ => true,

src/librustc_metadata/creader.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct CrateReader<'a> {
5656
next_crate_num: ast::CrateNum,
5757
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
5858
local_crate_name: String,
59+
local_crate_config: ast::CrateConfig,
5960
}
6061

6162
impl<'a> visit::Visitor for LocalCrateReader<'a> {
@@ -152,13 +153,16 @@ enum LoadResult {
152153
impl<'a> CrateReader<'a> {
153154
pub fn new(sess: &'a Session,
154155
cstore: &'a CStore,
155-
local_crate_name: &str) -> CrateReader<'a> {
156+
local_crate_name: &str,
157+
local_crate_config: ast::CrateConfig)
158+
-> CrateReader<'a> {
156159
CrateReader {
157160
sess: sess,
158161
cstore: cstore,
159162
next_crate_num: cstore.next_crate_num(),
160163
foreign_item_map: FnvHashMap(),
161164
local_crate_name: local_crate_name.to_owned(),
165+
local_crate_config: local_crate_config,
162166
}
163167
}
164168

@@ -561,7 +565,7 @@ impl<'a> CrateReader<'a> {
561565
// NB: Don't use parse::parse_tts_from_source_str because it parses with
562566
// quote_depth > 0.
563567
let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
564-
self.sess.opts.cfg.clone(),
568+
self.local_crate_config.clone(),
565569
source_name.clone(),
566570
body);
567571
let lo = p.span.lo;
@@ -863,7 +867,7 @@ impl<'a> LocalCrateReader<'a> {
863867
LocalCrateReader {
864868
sess: sess,
865869
cstore: cstore,
866-
creader: CrateReader::new(sess, cstore, local_crate_name),
870+
creader: CrateReader::new(sess, cstore, local_crate_name, krate.config.clone()),
867871
krate: krate,
868872
definitions: defs,
869873
}

src/librustc_metadata/macro_import.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ pub struct MacroLoader<'a> {
2929
}
3030

3131
impl<'a> MacroLoader<'a> {
32-
pub fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> MacroLoader<'a> {
32+
pub fn new(sess: &'a Session,
33+
cstore: &'a CStore,
34+
crate_name: &str,
35+
crate_config: ast::CrateConfig)
36+
-> MacroLoader<'a> {
3337
MacroLoader {
3438
sess: sess,
35-
reader: CrateReader::new(sess, cstore, crate_name),
39+
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
3640
}
3741
}
3842
}

src/librustc_plugin/load.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn load_plugins(sess: &Session,
4949
krate: &ast::Crate,
5050
crate_name: &str,
5151
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
52-
let mut loader = PluginLoader::new(sess, cstore, crate_name);
52+
let mut loader = PluginLoader::new(sess, cstore, crate_name, krate.config.clone());
5353

5454
// do not report any error now. since crate attributes are
5555
// not touched by expansion, every use of plugin without
@@ -90,10 +90,14 @@ pub fn load_plugins(sess: &Session,
9090
}
9191

9292
impl<'a> PluginLoader<'a> {
93-
fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> PluginLoader<'a> {
93+
fn new(sess: &'a Session,
94+
cstore: &'a CStore,
95+
crate_name: &str,
96+
crate_config: ast::CrateConfig)
97+
-> PluginLoader<'a> {
9498
PluginLoader {
9599
sess: sess,
96-
reader: CrateReader::new(sess, cstore, crate_name),
100+
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
97101
plugins: vec![],
98102
}
99103
}

src/librustdoc/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ pub fn run_core(search_paths: SearchPaths,
119119
lint_cap: Some(lint::Allow),
120120
externs: externs,
121121
target_triple: triple.unwrap_or(config::host_triple().to_string()),
122-
cfg: config::parse_cfgspecs(cfgs),
123122
// Ensure that rustdoc works even if rustc is feature-staged
124123
unstable_features: UnstableFeatures::Allow,
125124
..config::basic_options().clone()
@@ -139,7 +138,7 @@ pub fn run_core(search_paths: SearchPaths,
139138
codemap, cstore.clone());
140139
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
141140

142-
let mut cfg = config::build_configuration(&sess);
141+
let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs));
143142
target_features::add_configuration(&mut cfg, &sess);
144143

145144
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));

src/librustdoc/test.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ pub fn run(input: &str,
9191
cstore.clone());
9292
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
9393

94-
let mut cfg = config::build_configuration(&sess);
95-
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
94+
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
9695
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9796
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
9897
phase_2_configure_and_expand(
@@ -250,8 +249,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
250249
let outdir = Mutex::new(TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"));
251250
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
252251
let mut control = driver::CompileController::basic();
253-
let mut cfg = config::build_configuration(&sess);
254-
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
252+
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
255253
let out = Some(outdir.lock().unwrap().path().to_path_buf());
256254

257255
if no_run {

src/test/run-make/issue-19371/foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252

5353
fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
5454
let mut opts = basic_options();
55-
opts.output_types = OutputTypes::new([(OutputType::Exe, None)]);
55+
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
5656
opts.maybe_sysroot = Some(sysroot);
5757

5858
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
@@ -65,7 +65,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
6565

6666
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
6767
let (sess, cstore) = basic_sess(sysroot);
68-
let cfg = build_configuration(&sess);
68+
let cfg = build_configuration(&sess, vec![]);
6969
let control = CompileController::basic();
7070

7171
compile_input(&sess, &cstore,

src/test/run-pass-fulldeps/compiler-calls.rs

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern crate rustc_errors as errors;
2424
use rustc::session::Session;
2525
use rustc::session::config::{self, Input};
2626
use rustc_driver::{driver, CompilerCalls, Compilation};
27+
use syntax::ast;
2728

2829
use std::path::PathBuf;
2930

@@ -35,6 +36,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
3536
fn early_callback(&mut self,
3637
_: &getopts::Matches,
3738
_: &config::Options,
39+
_: &ast::CrateConfig,
3840
_: &errors::registry::Registry,
3941
_: config::ErrorOutputType)
4042
-> Compilation {
@@ -45,6 +47,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
4547
fn late_callback(&mut self,
4648
_: &getopts::Matches,
4749
_: &Session,
50+
_: &ast::CrateConfig,
4851
_: &Input,
4952
_: &Option<PathBuf>,
5053
_: &Option<PathBuf>)
@@ -62,6 +65,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
6265
fn no_input(&mut self,
6366
_: &getopts::Matches,
6467
_: &config::Options,
68+
_: &ast::CrateConfig,
6569
_: &Option<PathBuf>,
6670
_: &Option<PathBuf>,
6771
_: &errors::registry::Registry)

0 commit comments

Comments
 (0)