Skip to content

Commit b6f254b

Browse files
committed
Move syntax::with_globals call from run_compiler to run
1 parent c648b0b commit b6f254b

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

src/librustc_driver/lib.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,30 @@ pub fn abort_on_err<T>(result: Result<T, CompileIncomplete>, sess: &Session) ->
184184
pub fn run<F>(run_compiler: F) -> isize
185185
where F: FnOnce() -> (CompileResult, Option<Session>) + Send + 'static
186186
{
187-
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));
187+
let result = syntax::with_globals(|| {
188+
monitor(move || {
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 {

src/libsyntax/lib.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ impl Globals {
100100
pub fn with_globals<F, R>(f: F) -> R
101101
where F: FnOnce() -> R
102102
{
103-
let globals = Globals::new();
104-
GLOBALS.set(&globals, || {
105-
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
106-
})
103+
if GLOBALS.is_set() {
104+
if syntax_pos::GLOBALS.is_set() {
105+
f()
106+
} else {
107+
GLOBALS.with(|globals| {
108+
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
109+
})
110+
}
111+
} else {
112+
let globals = Globals::new();
113+
GLOBALS.set(&globals, || {
114+
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
115+
})
116+
}
107117
}
108118

109119
scoped_thread_local!(pub static GLOBALS: Globals);

0 commit comments

Comments
 (0)