1
Fork 0

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

@ -1,9 +1,9 @@
use super::*; use super::*;
use rustc_span::with_default_session_globals; use rustc_span::create_default_session_globals_then;
#[test] #[test]
fn test_block_doc_comment_1() { fn test_block_doc_comment_1() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let comment = "\n * Test \n ** Test\n * Test\n"; let comment = "\n * Test \n ** Test\n * Test\n";
let stripped = beautify_doc_string(Symbol::intern(comment)); let stripped = beautify_doc_string(Symbol::intern(comment));
assert_eq!(stripped.as_str(), " Test \n* Test\n Test"); assert_eq!(stripped.as_str(), " Test \n* Test\n Test");
@ -12,7 +12,7 @@ fn test_block_doc_comment_1() {
#[test] #[test]
fn test_block_doc_comment_2() { fn test_block_doc_comment_2() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let comment = "\n * Test\n * Test\n"; let comment = "\n * Test\n * Test\n";
let stripped = beautify_doc_string(Symbol::intern(comment)); let stripped = beautify_doc_string(Symbol::intern(comment));
assert_eq!(stripped.as_str(), " Test\n Test"); assert_eq!(stripped.as_str(), " Test\n Test");
@ -21,7 +21,7 @@ fn test_block_doc_comment_2() {
#[test] #[test]
fn test_block_doc_comment_3() { fn test_block_doc_comment_3() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let comment = "\n let a: *i32;\n *a = 5;\n"; let comment = "\n let a: *i32;\n *a = 5;\n";
let stripped = beautify_doc_string(Symbol::intern(comment)); let stripped = beautify_doc_string(Symbol::intern(comment));
assert_eq!(stripped.as_str(), " let a: *i32;\n *a = 5;"); assert_eq!(stripped.as_str(), " let a: *i32;\n *a = 5;");
@ -30,7 +30,7 @@ fn test_block_doc_comment_3() {
#[test] #[test]
fn test_line_doc_comment() { fn test_line_doc_comment() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let stripped = beautify_doc_string(Symbol::intern(" test")); let stripped = beautify_doc_string(Symbol::intern(" test"));
assert_eq!(stripped.as_str(), " test"); assert_eq!(stripped.as_str(), " test");
let stripped = beautify_doc_string(Symbol::intern("! test")); let stripped = beautify_doc_string(Symbol::intern("! test"));

View file

@ -1,8 +1,8 @@
use super::*; use super::*;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_span::create_default_session_globals_then;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::with_default_session_globals;
fn fun_to_string( fn fun_to_string(
decl: &ast::FnDecl, decl: &ast::FnDecl,
@ -24,7 +24,7 @@ fn variant_to_string(var: &ast::Variant) -> String {
#[test] #[test]
fn test_fun_to_string() { fn test_fun_to_string() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let abba_ident = Ident::from_str("abba"); let abba_ident = Ident::from_str("abba");
let decl = let decl =
@ -39,7 +39,7 @@ fn test_fun_to_string() {
#[test] #[test]
fn test_variant_to_string() { fn test_variant_to_string() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let ident = Ident::from_str("principal_skinner"); let ident = Ident::from_str("principal_skinner");
let var = ast::Variant { let var = ast::Variant {

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. /// Test the span yields correct positions in JSON.
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
let expected_output = TestData { spans: vec![expected_output] }; 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())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned()); sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());

View file

@ -3,8 +3,8 @@ use crate::tests::{matches_codepattern, string_to_crate};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::mut_visit::MutVisitor; use rustc_ast::mut_visit::MutVisitor;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_span::create_default_session_globals_then;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::with_default_session_globals;
// This version doesn't care about getting comments or doc-strings in. // This version doesn't care about getting comments or doc-strings in.
fn print_crate_items(krate: &ast::Crate) -> String { fn print_crate_items(krate: &ast::Crate) -> String {
@ -38,7 +38,7 @@ macro_rules! assert_pred {
// Make sure idents get transformed everywhere. // Make sure idents get transformed everywhere.
#[test] #[test]
fn ident_transformation() { fn ident_transformation() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut zz_visitor = ToZzIdentMutVisitor; let mut zz_visitor = ToZzIdentMutVisitor;
let mut krate = let mut krate =
string_to_crate("#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string()); string_to_crate("#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
@ -55,7 +55,7 @@ fn ident_transformation() {
// Make sure idents get transformed even inside macro defs. // Make sure idents get transformed even inside macro defs.
#[test] #[test]
fn ident_transformation_in_defs() { fn ident_transformation_in_defs() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut zz_visitor = ToZzIdentMutVisitor; let mut zz_visitor = ToZzIdentMutVisitor;
let mut krate = string_to_crate( let mut krate = string_to_crate(
"macro_rules! a {(b $c:expr $(d $e:token)f+ => \ "macro_rules! a {(b $c:expr $(d $e:token)f+ => \

View file

@ -10,9 +10,9 @@ use rustc_errors::PResult;
use rustc_parse::new_parser_from_source_str; use rustc_parse::new_parser_from_source_str;
use rustc_parse::parser::ForceCollect; use rustc_parse::parser::ForceCollect;
use rustc_session::parse::ParseSess; use rustc_session::parse::ParseSess;
use rustc_span::create_default_session_globals_then;
use rustc_span::source_map::FilePathMapping; use rustc_span::source_map::FilePathMapping;
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::with_default_session_globals;
use rustc_span::{BytePos, FileName, Pos, Span}; use rustc_span::{BytePos, FileName, Pos, Span};
use std::path::PathBuf; use std::path::PathBuf;
@ -51,7 +51,7 @@ fn string_to_item(source_str: String) -> Option<P<ast::Item>> {
#[should_panic] #[should_panic]
#[test] #[test]
fn bad_path_expr_1() { fn bad_path_expr_1() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
string_to_expr("::abc::def::return".to_string()); string_to_expr("::abc::def::return".to_string());
}) })
} }
@ -59,7 +59,7 @@ fn bad_path_expr_1() {
// Checks the token-tree-ization of macros. // Checks the token-tree-ization of macros.
#[test] #[test]
fn string_to_tts_macro() { fn string_to_tts_macro() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let tts: Vec<_> = let tts: Vec<_> =
string_to_stream("macro_rules! zip (($a)=>($a))".to_string()).trees().collect(); string_to_stream("macro_rules! zip (($a)=>($a))".to_string()).trees().collect();
let tts: &[TokenTree] = &tts[..]; let tts: &[TokenTree] = &tts[..];
@ -96,7 +96,7 @@ fn string_to_tts_macro() {
#[test] #[test]
fn string_to_tts_1() { fn string_to_tts_1() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let tts = string_to_stream("fn a (b : i32) { b; }".to_string()); let tts = string_to_stream("fn a (b : i32) { b; }".to_string());
let expected = TokenStream::new(vec![ let expected = TokenStream::new(vec![
@ -131,7 +131,7 @@ fn string_to_tts_1() {
#[test] #[test]
fn parse_use() { fn parse_use() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let use_s = "use foo::bar::baz;"; let use_s = "use foo::bar::baz;";
let vitem = string_to_item(use_s.to_string()).unwrap(); let vitem = string_to_item(use_s.to_string()).unwrap();
let vitem_s = item_to_string(&vitem); let vitem_s = item_to_string(&vitem);
@ -146,7 +146,7 @@ fn parse_use() {
#[test] #[test]
fn parse_extern_crate() { fn parse_extern_crate() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let ex_s = "extern crate foo;"; let ex_s = "extern crate foo;";
let vitem = string_to_item(ex_s.to_string()).unwrap(); let vitem = string_to_item(ex_s.to_string()).unwrap();
let vitem_s = item_to_string(&vitem); let vitem_s = item_to_string(&vitem);
@ -184,7 +184,7 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
#[test] #[test]
fn span_of_self_arg_pat_idents_are_correct() { fn span_of_self_arg_pat_idents_are_correct() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let srcs = [ let srcs = [
"impl z { fn a (&self, &myarg: i32) {} }", "impl z { fn a (&self, &myarg: i32) {} }",
"impl z { fn a (&mut self, &myarg: i32) {} }", "impl z { fn a (&mut self, &myarg: i32) {} }",
@ -208,7 +208,7 @@ fn span_of_self_arg_pat_idents_are_correct() {
#[test] #[test]
fn parse_exprs() { fn parse_exprs() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
// just make sure that they parse.... // just make sure that they parse....
string_to_expr("3 + 4".to_string()); string_to_expr("3 + 4".to_string());
string_to_expr("a::z.froob(b,&(987+3))".to_string()); string_to_expr("a::z.froob(b,&(987+3))".to_string());
@ -217,7 +217,7 @@ fn parse_exprs() {
#[test] #[test]
fn attrs_fix_bug() { fn attrs_fix_bug() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
string_to_item( string_to_item(
"pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) "pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
-> Result<Box<Writer>, String> { -> Result<Box<Writer>, String> {
@ -238,7 +238,7 @@ let mut fflags: c_int = wb();
#[test] #[test]
fn crlf_doc_comments() { fn crlf_doc_comments() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let sess = sess(); let sess = sess();
let name_1 = FileName::Custom("crlf_source_1".to_string()); let name_1 = FileName::Custom("crlf_source_1".to_string());
@ -272,7 +272,7 @@ fn ttdelim_span() {
new_parser_from_source_str(sess, name, source).parse_expr() new_parser_from_source_str(sess, name, source).parse_expr()
} }
with_default_session_globals(|| { create_default_session_globals_then(|| {
let sess = sess(); let sess = sess();
let expr = parse_expr_from_source_str( let expr = parse_expr_from_source_str(
PathBuf::from("foo").into(), PathBuf::from("foo").into(),
@ -300,7 +300,7 @@ fn ttdelim_span() {
// See `recurse_into_file_modules` in the parser. // See `recurse_into_file_modules` in the parser.
#[test] #[test]
fn out_of_line_mod() { fn out_of_line_mod() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let item = parse_item_from_source_str( let item = parse_item_from_source_str(
PathBuf::from("foo").into(), PathBuf::from("foo").into(),
"mod foo { struct S; mod this_does_not_exist; }".to_owned(), "mod foo { struct S; mod this_does_not_exist; }".to_owned(),

View file

@ -2,8 +2,8 @@ use rustc_ast as ast;
use rustc_ast::tokenstream::TokenStream; use rustc_ast::tokenstream::TokenStream;
use rustc_parse::{new_parser_from_source_str, parser::Parser, source_file_to_stream}; use rustc_parse::{new_parser_from_source_str, parser::Parser, source_file_to_stream};
use rustc_session::parse::ParseSess; use rustc_session::parse::ParseSess;
use rustc_span::create_default_session_if_not_set_then;
use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::with_default_session_globals;
use rustc_span::{BytePos, MultiSpan, Span}; use rustc_span::{BytePos, MultiSpan, Span};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
@ -124,7 +124,7 @@ impl<T: Write> Write for Shared<T> {
} }
fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) { fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
with_default_session_globals(|| { create_default_session_if_not_set_then(|_| {
let output = Arc::new(Mutex::new(Vec::new())); let output = Arc::new(Mutex::new(Vec::new()));
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));

View file

@ -2,7 +2,7 @@ use crate::tests::string_to_stream;
use rustc_ast::token; use rustc_ast::token;
use rustc_ast::tokenstream::{Spacing, TokenStream, TokenStreamBuilder, TokenTree}; use rustc_ast::tokenstream::{Spacing, TokenStream, TokenStreamBuilder, TokenTree};
use rustc_span::with_default_session_globals; use rustc_span::create_default_session_globals_then;
use rustc_span::{BytePos, Span, Symbol}; use rustc_span::{BytePos, Span, Symbol};
use smallvec::smallvec; use smallvec::smallvec;
@ -20,7 +20,7 @@ fn joint(tree: TokenTree) -> TokenStream {
#[test] #[test]
fn test_concat() { fn test_concat() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts("foo::bar::baz"); let test_res = string_to_ts("foo::bar::baz");
let test_fst = string_to_ts("foo::bar"); let test_fst = string_to_ts("foo::bar");
let test_snd = string_to_ts("::baz"); let test_snd = string_to_ts("::baz");
@ -33,7 +33,7 @@ fn test_concat() {
#[test] #[test]
fn test_to_from_bijection() { fn test_to_from_bijection() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_start = string_to_ts("foo::bar(baz)"); let test_start = string_to_ts("foo::bar(baz)");
let test_end = test_start.trees().collect(); let test_end = test_start.trees().collect();
assert_eq!(test_start, test_end) assert_eq!(test_start, test_end)
@ -42,7 +42,7 @@ fn test_to_from_bijection() {
#[test] #[test]
fn test_eq_0() { fn test_eq_0() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts("foo"); let test_res = string_to_ts("foo");
let test_eqs = string_to_ts("foo"); let test_eqs = string_to_ts("foo");
assert_eq!(test_res, test_eqs) assert_eq!(test_res, test_eqs)
@ -51,7 +51,7 @@ fn test_eq_0() {
#[test] #[test]
fn test_eq_1() { fn test_eq_1() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts("::bar::baz"); let test_res = string_to_ts("::bar::baz");
let test_eqs = string_to_ts("::bar::baz"); let test_eqs = string_to_ts("::bar::baz");
assert_eq!(test_res, test_eqs) assert_eq!(test_res, test_eqs)
@ -60,7 +60,7 @@ fn test_eq_1() {
#[test] #[test]
fn test_eq_3() { fn test_eq_3() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts(""); let test_res = string_to_ts("");
let test_eqs = string_to_ts(""); let test_eqs = string_to_ts("");
assert_eq!(test_res, test_eqs) assert_eq!(test_res, test_eqs)
@ -69,7 +69,7 @@ fn test_eq_3() {
#[test] #[test]
fn test_diseq_0() { fn test_diseq_0() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts("::bar::baz"); let test_res = string_to_ts("::bar::baz");
let test_eqs = string_to_ts("bar::baz"); let test_eqs = string_to_ts("bar::baz");
assert_eq!(test_res == test_eqs, false) assert_eq!(test_res == test_eqs, false)
@ -78,7 +78,7 @@ fn test_diseq_0() {
#[test] #[test]
fn test_diseq_1() { fn test_diseq_1() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test_res = string_to_ts("(bar,baz)"); let test_res = string_to_ts("(bar,baz)");
let test_eqs = string_to_ts("bar,baz"); let test_eqs = string_to_ts("bar,baz");
assert_eq!(test_res == test_eqs, false) assert_eq!(test_res == test_eqs, false)
@ -87,7 +87,7 @@ fn test_diseq_1() {
#[test] #[test]
fn test_is_empty() { fn test_is_empty() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let test0: TokenStream = Vec::<TokenTree>::new().into_iter().collect(); let test0: TokenStream = Vec::<TokenTree>::new().into_iter().collect();
let test1: TokenStream = let test1: TokenStream =
TokenTree::token(token::Ident(Symbol::intern("a"), false), sp(0, 1)).into(); TokenTree::token(token::Ident(Symbol::intern("a"), false), sp(0, 1)).into();
@ -101,7 +101,7 @@ fn test_is_empty() {
#[test] #[test]
fn test_dotdotdot() { fn test_dotdotdot() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut builder = TokenStreamBuilder::new(); let mut builder = TokenStreamBuilder::new();
builder.push(joint(TokenTree::token(token::Dot, sp(0, 1)))); builder.push(joint(TokenTree::token(token::Dot, sp(0, 1))));
builder.push(joint(TokenTree::token(token::Dot, sp(1, 2)))); builder.push(joint(TokenTree::token(token::Dot, sp(1, 2))));

View file

@ -76,7 +76,7 @@ impl Compiler {
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`. /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> { pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
rustc_span::with_default_session_globals(move || { rustc_span::create_default_session_if_not_set_then(move |_| {
let cfg = cfgspecs let cfg = cfgspecs
.into_iter() .into_iter()
.map(|s| { .map(|s| {

View file

@ -107,7 +107,7 @@ fn assert_non_crate_hash_different(x: &Options, y: &Options) {
// When the user supplies --test we should implicitly supply --cfg test // When the user supplies --test we should implicitly supply --cfg test
#[test] #[test]
fn test_switch_implies_cfg_test() { fn test_switch_implies_cfg_test() {
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["--test".to_string()]).unwrap(); let matches = optgroups().parse(&["--test".to_string()]).unwrap();
let (sess, cfg) = mk_session(matches); let (sess, cfg) = mk_session(matches);
let cfg = build_configuration(&sess, to_crate_config(cfg)); let cfg = build_configuration(&sess, to_crate_config(cfg));
@ -118,7 +118,7 @@ fn test_switch_implies_cfg_test() {
// When the user supplies --test and --cfg test, don't implicitly add another --cfg test // When the user supplies --test and --cfg test, don't implicitly add another --cfg test
#[test] #[test]
fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap(); let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
let (sess, cfg) = mk_session(matches); let (sess, cfg) = mk_session(matches);
let cfg = build_configuration(&sess, to_crate_config(cfg)); let cfg = build_configuration(&sess, to_crate_config(cfg));
@ -130,20 +130,20 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
#[test] #[test]
fn test_can_print_warnings() { fn test_can_print_warnings() {
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap(); let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
let (sess, _) = mk_session(matches); let (sess, _) = mk_session(matches);
assert!(!sess.diagnostic().can_emit_warnings()); assert!(!sess.diagnostic().can_emit_warnings());
}); });
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let matches = let matches =
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap(); optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
let (sess, _) = mk_session(matches); let (sess, _) = mk_session(matches);
assert!(sess.diagnostic().can_emit_warnings()); assert!(sess.diagnostic().can_emit_warnings());
}); });
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap(); let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
let (sess, _) = mk_session(matches); let (sess, _) = mk_session(matches);
assert!(sess.diagnostic().can_emit_warnings()); assert!(sess.diagnostic().can_emit_warnings());

View file

@ -150,7 +150,7 @@ pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Se
crate::callbacks::setup_callbacks(); crate::callbacks::setup_callbacks();
let main_handler = move || { let main_handler = move || {
rustc_span::with_session_globals(edition, || { rustc_span::create_session_globals_then(edition, || {
io::set_output_capture(stderr.clone()); io::set_output_capture(stderr.clone());
f() f()
}) })
@ -171,12 +171,13 @@ unsafe fn handle_deadlock() {
rustc_data_structures::sync::assert_sync::<tls::ImplicitCtxt<'_, '_>>(); rustc_data_structures::sync::assert_sync::<tls::ImplicitCtxt<'_, '_>>();
let icx: &tls::ImplicitCtxt<'_, '_> = &*(context as *const tls::ImplicitCtxt<'_, '_>); let icx: &tls::ImplicitCtxt<'_, '_> = &*(context as *const tls::ImplicitCtxt<'_, '_>);
let session_globals = rustc_span::SESSION_GLOBALS.with(|sg| sg as *const _); let session_globals = rustc_span::with_session_globals(|sg| sg as *const _);
let session_globals = &*session_globals; let session_globals = &*session_globals;
thread::spawn(move || { thread::spawn(move || {
tls::enter_context(icx, |_| { tls::enter_context(icx, |_| {
rustc_span::SESSION_GLOBALS rustc_span::set_session_globals_then(session_globals, || {
.set(session_globals, || tls::with(|tcx| tcx.queries.deadlock(tcx, &registry))) tls::with(|tcx| tcx.queries.deadlock(tcx, &registry))
})
}); });
}); });
} }
@ -203,13 +204,13 @@ pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Se
let with_pool = move |pool: &rayon::ThreadPool| pool.install(f); let with_pool = move |pool: &rayon::ThreadPool| pool.install(f);
rustc_span::with_session_globals(edition, || { rustc_span::create_session_globals_then(edition, || {
rustc_span::SESSION_GLOBALS.with(|session_globals| { rustc_span::with_session_globals(|session_globals| {
// The main handler runs for each Rayon worker thread and sets up // The main handler runs for each Rayon worker thread and sets up
// the thread local rustc uses. `session_globals` is captured and set // the thread local rustc uses. `session_globals` is captured and set
// on the new threads. // on the new threads.
let main_handler = move |thread: rayon::ThreadBuilder| { let main_handler = move |thread: rayon::ThreadBuilder| {
rustc_span::SESSION_GLOBALS.set(session_globals, || { rustc_span::set_session_globals_then(session_globals, || {
io::set_output_capture(stderr.clone()); io::set_output_capture(stderr.clone());
thread.run() thread.run()
}) })

View file

@ -22,7 +22,7 @@
//! are unrelated to the `TyCtxt` global. Without initializing the `Span` session globals, some //! are unrelated to the `TyCtxt` global. Without initializing the `Span` session globals, some
//! basic, coverage-specific features would be impossible to test, but thankfully initializing these //! basic, coverage-specific features would be impossible to test, but thankfully initializing these
//! globals is comparatively simpler. The easiest way is to wrap the test in a closure argument //! globals is comparatively simpler. The easiest way is to wrap the test in a closure argument
//! to: `rustc_span::with_default_session_globals(|| { test_here(); })`. //! to: `rustc_span::create_default_session_globals_then(|| { test_here(); })`.
use super::counters; use super::counters;
use super::debug; use super::debug;
@ -677,7 +677,7 @@ fn synthesize_body_span_from_terminators(mir_body: &Body<'_>) -> Span {
#[test] #[test]
fn test_make_bcb_counters() { fn test_make_bcb_counters() {
rustc_span::with_default_session_globals(|| { rustc_span::create_default_session_globals_then(|| {
let mir_body = goto_switchint(); let mir_body = goto_switchint();
let body_span = synthesize_body_span_from_terminators(&mir_body); let body_span = synthesize_body_span_from_terminators(&mir_body);
let mut basic_coverage_blocks = graph::CoverageGraph::from_mir(&mir_body); let mut basic_coverage_blocks = graph::CoverageGraph::from_mir(&mir_body);

View file

@ -144,8 +144,7 @@ fn format_align_fill() {
} }
#[test] #[test]
fn format_counts() { fn format_counts() {
use rustc_span::{edition, SessionGlobals, SESSION_GLOBALS}; rustc_span::create_default_session_globals_then(|| {
SESSION_GLOBALS.set(&SessionGlobals::new(edition::DEFAULT_EDITION), || {
same( same(
"{:10x}", "{:10x}",
&[NextArgument(Argument { &[NextArgument(Argument {

View file

@ -26,7 +26,7 @@
use crate::edition::Edition; use crate::edition::Edition;
use crate::symbol::{kw, sym, Symbol}; use crate::symbol::{kw, sym, Symbol};
use crate::SESSION_GLOBALS; use crate::with_session_globals;
use crate::{BytePos, CachingSourceMapView, ExpnIdCache, SourceFile, Span, DUMMY_SP}; use crate::{BytePos, CachingSourceMapView, ExpnIdCache, SourceFile, Span, DUMMY_SP};
use crate::def_id::{CrateNum, DefId, DefPathHash, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::def_id::{CrateNum, DefId, DefPathHash, CRATE_DEF_INDEX, LOCAL_CRATE};
@ -201,7 +201,7 @@ impl HygieneData {
} }
pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T { pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
SESSION_GLOBALS.with(|session_globals| f(&mut *session_globals.hygiene_data.borrow_mut())) with_session_globals(|session_globals| f(&mut *session_globals.hygiene_data.borrow_mut()))
} }
fn fresh_expn(&mut self, mut expn_data: Option<ExpnData>) -> ExpnId { fn fresh_expn(&mut self, mut expn_data: Option<ExpnData>) -> ExpnId {
@ -1367,8 +1367,9 @@ fn update_disambiguator(expn_id: ExpnId) {
} }
} }
let source_map = SESSION_GLOBALS let source_map = with_session_globals(|session_globals| {
.with(|session_globals| session_globals.source_map.borrow().as_ref().unwrap().clone()); session_globals.source_map.borrow().as_ref().unwrap().clone()
});
let mut ctx = let mut ctx =
DummyHashStableContext { caching_source_map: CachingSourceMapView::new(&source_map) }; DummyHashStableContext { caching_source_map: CachingSourceMapView::new(&source_map) };

View file

@ -21,8 +21,8 @@ fn test_lev_distance() {
#[test] #[test]
fn test_find_best_match_for_name() { fn test_find_best_match_for_name() {
use crate::with_default_session_globals; use crate::create_default_session_globals_then;
with_default_session_globals(|| { create_default_session_globals_then(|| {
let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")]; let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")];
assert_eq!( assert_eq!(
find_best_match_for_name(&input, Symbol::intern("aaaa"), None), find_best_match_for_name(&input, Symbol::intern("aaaa"), None),

View file

@ -97,19 +97,65 @@ impl SessionGlobals {
} }
} }
pub fn with_session_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R { #[inline]
pub fn create_session_globals_then<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
assert!(
!SESSION_GLOBALS.is_set(),
"SESSION_GLOBALS should never be overwritten! \
Use another thread if you need another SessionGlobals"
);
let session_globals = SessionGlobals::new(edition); let session_globals = SessionGlobals::new(edition);
SESSION_GLOBALS.set(&session_globals, f) SESSION_GLOBALS.set(&session_globals, f)
} }
pub fn with_default_session_globals<R>(f: impl FnOnce() -> R) -> R { #[inline]
with_session_globals(edition::DEFAULT_EDITION, f) pub fn set_session_globals_then<R>(session_globals: &SessionGlobals, f: impl FnOnce() -> R) -> R {
assert!(
!SESSION_GLOBALS.is_set(),
"SESSION_GLOBALS should never be overwritten! \
Use another thread if you need another SessionGlobals"
);
SESSION_GLOBALS.set(session_globals, f)
}
#[inline]
pub fn create_default_session_if_not_set_then<R, F>(f: F) -> R
where
F: FnOnce(&SessionGlobals) -> R,
{
create_session_if_not_set_then(edition::DEFAULT_EDITION, f)
}
#[inline]
pub fn create_session_if_not_set_then<R, F>(edition: Edition, f: F) -> R
where
F: FnOnce(&SessionGlobals) -> R,
{
if !SESSION_GLOBALS.is_set() {
let session_globals = SessionGlobals::new(edition);
SESSION_GLOBALS.set(&session_globals, || SESSION_GLOBALS.with(f))
} else {
SESSION_GLOBALS.with(f)
}
}
#[inline]
pub fn with_session_globals<R, F>(f: F) -> R
where
F: FnOnce(&SessionGlobals) -> R,
{
SESSION_GLOBALS.with(f)
}
#[inline]
pub fn create_default_session_globals_then<R>(f: impl FnOnce() -> R) -> R {
create_session_globals_then(edition::DEFAULT_EDITION, f)
} }
// If this ever becomes non thread-local, `decode_syntax_context` // If this ever becomes non thread-local, `decode_syntax_context`
// and `decode_expn_id` will need to be updated to handle concurrent // and `decode_expn_id` will need to be updated to handle concurrent
// deserialization. // deserialization.
scoped_tls::scoped_thread_local!(pub static SESSION_GLOBALS: SessionGlobals); scoped_tls::scoped_thread_local!(static SESSION_GLOBALS: SessionGlobals);
// FIXME: We should use this enum or something like it to get rid of the // FIXME: We should use this enum or something like it to get rid of the
// use of magic `/rust/1.x/...` paths across the board. // use of magic `/rust/1.x/...` paths across the board.
@ -855,13 +901,13 @@ impl<D: Decoder> Decodable<D> for Span {
/// the `SourceMap` provided to this function. If that is not available, /// the `SourceMap` provided to this function. If that is not available,
/// we fall back to printing the raw `Span` field values. /// we fall back to printing the raw `Span` field values.
pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T { pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
SESSION_GLOBALS.with(|session_globals| { with_session_globals(|session_globals| {
*session_globals.source_map.borrow_mut() = Some(source_map); *session_globals.source_map.borrow_mut() = Some(source_map);
}); });
struct ClearSourceMap; struct ClearSourceMap;
impl Drop for ClearSourceMap { impl Drop for ClearSourceMap {
fn drop(&mut self) { fn drop(&mut self) {
SESSION_GLOBALS.with(|session_globals| { with_session_globals(|session_globals| {
session_globals.source_map.borrow_mut().take(); session_globals.source_map.borrow_mut().take();
}); });
} }
@ -880,7 +926,7 @@ pub fn debug_with_source_map(
} }
pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
SESSION_GLOBALS.with(|session_globals| { with_session_globals(|session_globals| {
if let Some(source_map) = &*session_globals.source_map.borrow() { if let Some(source_map) = &*session_globals.source_map.borrow() {
debug_with_source_map(span, f, source_map) debug_with_source_map(span, f, source_map)
} else { } else {

View file

@ -5,7 +5,6 @@
// See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28 // See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
use crate::hygiene::SyntaxContext; use crate::hygiene::SyntaxContext;
use crate::SESSION_GLOBALS;
use crate::{BytePos, SpanData}; use crate::{BytePos, SpanData};
use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::fx::FxIndexSet;
@ -122,5 +121,5 @@ impl SpanInterner {
// If an interner exists, return it. Otherwise, prepare a fresh one. // If an interner exists, return it. Otherwise, prepare a fresh one.
#[inline] #[inline]
fn with_span_interner<T, F: FnOnce(&mut SpanInterner) -> T>(f: F) -> T { fn with_span_interner<T, F: FnOnce(&mut SpanInterner) -> T>(f: F) -> T {
SESSION_GLOBALS.with(|session_globals| f(&mut *session_globals.span_interner.lock())) crate::with_session_globals(|session_globals| f(&mut *session_globals.span_interner.lock()))
} }

View file

@ -13,7 +13,7 @@ use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::str; use std::str;
use crate::{Edition, Span, DUMMY_SP, SESSION_GLOBALS}; use crate::{with_session_globals, Edition, Span, DUMMY_SP};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
@ -1790,7 +1790,7 @@ impl Ident {
#[inline] #[inline]
fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T { fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
SESSION_GLOBALS.with(|session_globals| f(&mut *session_globals.symbol_interner.lock())) with_session_globals(|session_globals| f(&mut *session_globals.symbol_interner.lock()))
} }
/// An alternative to [`Symbol`], useful when the chars within the symbol need to /// An alternative to [`Symbol`], useful when the chars within the symbol need to

View file

@ -1,6 +1,6 @@
use super::*; use super::*;
use crate::{edition, SessionGlobals}; use crate::create_default_session_globals_then;
#[test] #[test]
fn interner_tests() { fn interner_tests() {
@ -18,7 +18,7 @@ fn interner_tests() {
#[test] #[test]
fn without_first_quote_test() { fn without_first_quote_test() {
SESSION_GLOBALS.set(&SessionGlobals::new(edition::DEFAULT_EDITION), || { create_default_session_globals_then(|| {
let i = Ident::from_str("'break"); let i = Ident::from_str("'break");
assert_eq!(i.without_first_quote().name, kw::Break); assert_eq!(i.without_first_quote().name, kw::Break);
}); });

View file

@ -2,8 +2,8 @@ use super::*;
use rustc_ast::attr; use rustc_ast::attr;
use rustc_ast::Path; use rustc_ast::Path;
use rustc_span::create_default_session_globals_then;
use rustc_span::symbol::{Ident, Symbol}; use rustc_span::symbol::{Ident, Symbol};
use rustc_span::with_default_session_globals;
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
fn word_cfg(s: &str) -> Cfg { fn word_cfg(s: &str) -> Cfg {
@ -52,7 +52,7 @@ macro_rules! dummy_meta_item_list {
#[test] #[test]
fn test_cfg_not() { fn test_cfg_not() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
assert_eq!(!Cfg::False, Cfg::True); assert_eq!(!Cfg::False, Cfg::True);
assert_eq!(!Cfg::True, Cfg::False); assert_eq!(!Cfg::True, Cfg::False);
assert_eq!(!word_cfg("test"), Cfg::Not(Box::new(word_cfg("test")))); assert_eq!(!word_cfg("test"), Cfg::Not(Box::new(word_cfg("test"))));
@ -70,7 +70,7 @@ fn test_cfg_not() {
#[test] #[test]
fn test_cfg_and() { fn test_cfg_and() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut x = Cfg::False; let mut x = Cfg::False;
x &= Cfg::True; x &= Cfg::True;
assert_eq!(x, Cfg::False); assert_eq!(x, Cfg::False);
@ -154,7 +154,7 @@ fn test_cfg_and() {
#[test] #[test]
fn test_cfg_or() { fn test_cfg_or() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut x = Cfg::True; let mut x = Cfg::True;
x |= Cfg::False; x |= Cfg::False;
assert_eq!(x, Cfg::True); assert_eq!(x, Cfg::True);
@ -238,7 +238,7 @@ fn test_cfg_or() {
#[test] #[test]
fn test_parse_ok() { fn test_parse_ok() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mi = dummy_meta_item_word("all"); let mi = dummy_meta_item_word("all");
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all"))); assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
@ -271,7 +271,7 @@ fn test_parse_ok() {
#[test] #[test]
fn test_parse_err() { fn test_parse_err() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mi = attr::mk_name_value_item(Ident::from_str("foo"), LitKind::Bool(false), DUMMY_SP); let mi = attr::mk_name_value_item(Ident::from_str("foo"), LitKind::Bool(false), DUMMY_SP);
assert!(Cfg::parse(&mi).is_err()); assert!(Cfg::parse(&mi).is_err());
@ -303,7 +303,7 @@ fn test_parse_err() {
#[test] #[test]
fn test_render_short_html() { fn test_render_short_html() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
assert_eq!(word_cfg("unix").render_short_html(), "Unix"); assert_eq!(word_cfg("unix").render_short_html(), "Unix");
assert_eq!(name_value_cfg("target_os", "macos").render_short_html(), "macOS"); assert_eq!(name_value_cfg("target_os", "macos").render_short_html(), "macOS");
assert_eq!(name_value_cfg("target_pointer_width", "16").render_short_html(), "16-bit"); assert_eq!(name_value_cfg("target_pointer_width", "16").render_short_html(), "16-bit");
@ -358,7 +358,7 @@ fn test_render_short_html() {
#[test] #[test]
fn test_render_long_html() { fn test_render_long_html() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
assert_eq!( assert_eq!(
word_cfg("unix").render_long_html(), word_cfg("unix").render_long_html(),
"This is supported on <strong>Unix</strong> only." "This is supported on <strong>Unix</strong> only."
@ -442,7 +442,7 @@ fn test_render_long_html() {
fn test_simplify_with() { fn test_simplify_with() {
// This is a tiny subset of things that could be simplified, but it likely covers 90% of // This is a tiny subset of things that could be simplified, but it likely covers 90% of
// real world usecases well. // real world usecases well.
with_default_session_globals(|| { create_default_session_globals_then(|| {
let foo = word_cfg("foo"); let foo = word_cfg("foo");
let bar = word_cfg("bar"); let bar = word_cfg("bar");
let baz = word_cfg("baz"); let baz = word_cfg("baz");

View file

@ -513,7 +513,7 @@ crate fn make_test(
// Uses librustc_ast to parse the doctest and find if there's a main fn and the extern // Uses librustc_ast to parse the doctest and find if there's a main fn and the extern
// crate already is included. // crate already is included.
let result = rustc_driver::catch_fatal_errors(|| { let result = rustc_driver::catch_fatal_errors(|| {
rustc_span::with_session_globals(edition, || { rustc_span::create_session_if_not_set_then(edition, |_| {
use rustc_errors::emitter::{Emitter, EmitterWriter}; use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::Handler; use rustc_errors::Handler;
use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::maybe_new_parser_from_source_str;

View file

@ -1,8 +1,8 @@
use super::write_code; use super::write_code;
use crate::html::format::Buffer; use crate::html::format::Buffer;
use expect_test::expect_file; use expect_test::expect_file;
use rustc_span::create_default_session_globals_then;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::with_default_session_globals;
const STYLE: &str = r#" const STYLE: &str = r#"
<style> <style>
@ -18,7 +18,7 @@ const STYLE: &str = r#"
#[test] #[test]
fn test_html_highlighting() { fn test_html_highlighting() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let src = include_str!("fixtures/sample.rs"); let src = include_str!("fixtures/sample.rs");
let html = { let html = {
let mut out = Buffer::new(); let mut out = Buffer::new();
@ -31,7 +31,7 @@ fn test_html_highlighting() {
#[test] #[test]
fn test_dos_backline() { fn test_dos_backline() {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let src = "pub fn foo() {\r\n\ let src = "pub fn foo() {\r\n\
println!(\"foo\");\r\n\ println!(\"foo\");\r\n\
}\r\n"; }\r\n";

View file

@ -1,7 +1,7 @@
use super::*; use super::*;
use rustc_span::create_default_session_globals_then;
use rustc_span::source_map::DUMMY_SP; use rustc_span::source_map::DUMMY_SP;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::with_default_session_globals;
fn create_doc_fragment(s: &str) -> Vec<DocFragment> { fn create_doc_fragment(s: &str) -> Vec<DocFragment> {
vec![DocFragment { vec![DocFragment {
@ -17,7 +17,7 @@ fn create_doc_fragment(s: &str) -> Vec<DocFragment> {
#[track_caller] #[track_caller]
fn run_test(input: &str, expected: &str) { fn run_test(input: &str, expected: &str) {
with_default_session_globals(|| { create_default_session_globals_then(|| {
let mut s = create_doc_fragment(input); let mut s = create_doc_fragment(input);
unindent_fragments(&mut s); unindent_fragments(&mut s);
assert_eq!(&s.iter().collect::<String>(), expected); assert_eq!(&s.iter().collect::<String>(), expected);

View file

@ -19,7 +19,7 @@ use std::path::Path;
mod gravy; mod gravy;
pub fn main() { pub fn main() {
rustc_span::with_default_session_globals(|| parse()); rustc_span::create_default_session_globals_then(|| parse());
assert_eq!(gravy::foo(), 10); assert_eq!(gravy::foo(), 10);
} }

View file

@ -202,7 +202,7 @@ impl MutVisitor for AddParens {
} }
fn main() { fn main() {
rustc_span::with_default_session_globals(|| run()); rustc_span::create_default_session_globals_then(|| run());
} }
fn run() { fn run() {

View file

@ -26,6 +26,7 @@ use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Spa
use rustc_span::{sym, FileName, Pos}; use rustc_span::{sym, FileName, Pos};
use std::io; use std::io;
use std::ops::Range; use std::ops::Range;
use std::thread;
use url::Url; use url::Url;
declare_clippy_lint! { declare_clippy_lint! {
@ -584,10 +585,10 @@ fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) {
} }
fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
fn has_needless_main(code: &str, edition: Edition) -> bool { fn has_needless_main(code: String, edition: Edition) -> bool {
rustc_driver::catch_fatal_errors(|| { rustc_driver::catch_fatal_errors(|| {
rustc_span::with_session_globals(edition, || { rustc_span::create_session_globals_then(edition, || {
let filename = FileName::anon_source_code(code); let filename = FileName::anon_source_code(&code);
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false); let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
@ -649,7 +650,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
.unwrap_or_default() .unwrap_or_default()
} }
if has_needless_main(text, edition) { // Because of the global session, we need to create a new session in a different thread with
// the edition we need.
let text = text.to_owned();
if thread::spawn(move || has_needless_main(text, edition)).join().expect("thread::spawn failed") {
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
} }
} }

View file

@ -284,7 +284,8 @@ fn parse_args() -> (OutputFormat, PathBuf) {
fn main() { fn main() {
rustc_driver::init_env_logger("RUST_LOG"); rustc_driver::init_env_logger("RUST_LOG");
let (format, dst) = parse_args(); let (format, dst) = parse_args();
let result = rustc_span::with_default_session_globals(move || main_with_result(format, &dst)); let result =
rustc_span::create_default_session_globals_then(move || main_with_result(format, &dst));
if let Err(e) = result { if let Err(e) = result {
panic!("{}", e.to_string()); panic!("{}", e.to_string());
} }

View file

@ -34,7 +34,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
return Err(ErrorKind::VersionMismatch); return Err(ErrorKind::VersionMismatch);
} }
rustc_span::with_session_globals(self.config.edition().into(), || { rustc_span::create_session_if_not_set_then(self.config.edition().into(), |_| {
if self.config.disable_all_formatting() { if self.config.disable_all_formatting() {
// When the input is from stdin, echo back the input. // When the input is from stdin, echo back the input.
if let Input::Text(ref buf) = input { if let Input::Text(ref buf) = input {