Skip to content

Commit bd04796

Browse files
committed
Move with_globals setup from run_compiler to run
1 parent 7219130 commit bd04796

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/librustc_driver/lib.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,29 @@ pub fn run<F>(run_compiler: F) -> isize
185185
where F: FnOnce() -> (CompileResult, Option<Session>) + Send + 'static
186186
{
187187
let result = monitor(move || {
188-
let (result, session) = run_compiler();
189-
if let Err(CompileIncomplete::Errored(_)) = result {
190-
match session {
191-
Some(sess) => {
192-
sess.abort_if_errors();
193-
panic!("error reported but abort_if_errors didn't abort???");
194-
}
195-
None => {
196-
let emitter =
197-
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
198-
None,
199-
true,
200-
false);
201-
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
202-
handler.emit(&MultiSpan::new(),
203-
"aborting due to previous error(s)",
204-
errors::Level::Fatal);
205-
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
188+
syntax::with_globals(|| {
189+
let (result, session) = run_compiler();
190+
if let Err(CompileIncomplete::Errored(_)) = result {
191+
match session {
192+
Some(sess) => {
193+
sess.abort_if_errors();
194+
panic!("error reported but abort_if_errors didn't abort???");
195+
}
196+
None => {
197+
let emitter =
198+
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
199+
None,
200+
true,
201+
false);
202+
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
203+
handler.emit(&MultiSpan::new(),
204+
"aborting due to previous error(s)",
205+
errors::Level::Fatal);
206+
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
207+
}
206208
}
207209
}
208-
}
210+
});
209211
});
210212

211213
match result {
@@ -471,17 +473,15 @@ pub fn run_compiler<'a>(args: &[String],
471473
emitter_dest: Option<Box<dyn Write + Send>>)
472474
-> (CompileResult, Option<Session>)
473475
{
474-
syntax::with_globals(|| {
475-
let matches = match handle_options(args) {
476-
Some(matches) => matches,
477-
None => return (Ok(()), None),
478-
};
476+
let matches = match handle_options(args) {
477+
Some(matches) => matches,
478+
None => return (Ok(()), None),
479+
};
479480

480-
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
481+
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
481482

482-
driver::spawn_thread_pool(sopts, |sopts| {
483-
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)
484-
})
483+
driver::spawn_thread_pool(sopts, |sopts| {
484+
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)
485485
})
486486
}
487487

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ fn main() {
9292
let tc = TestCalls { count: &mut count };
9393
// we should never get use this filename, but lets make sure they are valid args.
9494
let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
95-
rustc_driver::run_compiler(&args, Box::new(tc), None, None);
95+
syntax::with_globals(|| {
96+
rustc_driver::run_compiler(&args, Box::new(tc), None, None);
97+
});
9698
}
9799
assert_eq!(count, 30);
98100
}

0 commit comments

Comments
 (0)