Rework SESSION_GLOBALS API to prevent overwriting it

This commit is contained in:
Guillaume Gomez 2021-05-05 21:31:25 +02:00 committed by Guillaume Gomez
parent 0cd0709f19
commit a2654fb64c
27 changed files with 146 additions and 100 deletions

View file

@ -39,16 +39,11 @@ impl<T: Write> Write for Shared<T> {
}
}
fn with_default_session_globals(f: impl FnOnce()) {
let session_globals = rustc_span::SessionGlobals::new(rustc_span::edition::DEFAULT_EDITION);
rustc_span::SESSION_GLOBALS.set(&session_globals, f);
}
/// Test the span yields correct positions in JSON.
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
let expected_output = TestData { spans: vec![expected_output] };
with_default_session_globals(|| {
rustc_span::create_default_session_globals_then(|| {
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());