diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-05-05 21:31:25 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-08 16:16:28 +0200 |
| commit | a2654fb64c9c9d368063b488693d8da17bc9b4e9 (patch) | |
| tree | e6337d870d12feb89266d5dc2a77214458af7440 /compiler/rustc_expand/src | |
| parent | 0cd0709f19d316c4796fa71c5f52c8612a5f3771 (diff) | |
| download | rust-a2654fb64c9c9d368063b488693d8da17bc9b4e9.tar.gz rust-a2654fb64c9c9d368063b488693d8da17bc9b4e9.zip | |
Rework SESSION_GLOBALS API to prevent overwriting it
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/mut_visit/tests.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/parse/tests.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/tests.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/tokenstream/tests.rs | 20 |
4 files changed, 27 insertions, 27 deletions
diff --git a/compiler/rustc_expand/src/mut_visit/tests.rs b/compiler/rustc_expand/src/mut_visit/tests.rs index 7e7155ad278..0068539fb3b 100644 --- a/compiler/rustc_expand/src/mut_visit/tests.rs +++ b/compiler/rustc_expand/src/mut_visit/tests.rs @@ -3,8 +3,8 @@ use crate::tests::{matches_codepattern, string_to_crate}; use rustc_ast as ast; use rustc_ast::mut_visit::MutVisitor; use rustc_ast_pretty::pprust; +use rustc_span::create_default_session_globals_then; use rustc_span::symbol::Ident; -use rustc_span::with_default_session_globals; // This version doesn't care about getting comments or doc-strings in. fn print_crate_items(krate: &ast::Crate) -> String { @@ -38,7 +38,7 @@ macro_rules! assert_pred { // Make sure idents get transformed everywhere. #[test] fn ident_transformation() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let mut zz_visitor = ToZzIdentMutVisitor; let mut krate = 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. #[test] fn ident_transformation_in_defs() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let mut zz_visitor = ToZzIdentMutVisitor; let mut krate = string_to_crate( "macro_rules! a {(b $c:expr $(d $e:token)f+ => \ diff --git a/compiler/rustc_expand/src/parse/tests.rs b/compiler/rustc_expand/src/parse/tests.rs index 288efe22982..6402a81e7c1 100644 --- a/compiler/rustc_expand/src/parse/tests.rs +++ b/compiler/rustc_expand/src/parse/tests.rs @@ -10,9 +10,9 @@ use rustc_errors::PResult; use rustc_parse::new_parser_from_source_str; use rustc_parse::parser::ForceCollect; use rustc_session::parse::ParseSess; +use rustc_span::create_default_session_globals_then; use rustc_span::source_map::FilePathMapping; use rustc_span::symbol::{kw, sym, Symbol}; -use rustc_span::with_default_session_globals; use rustc_span::{BytePos, FileName, Pos, Span}; use std::path::PathBuf; @@ -51,7 +51,7 @@ fn string_to_item(source_str: String) -> Option<P<ast::Item>> { #[should_panic] #[test] fn bad_path_expr_1() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { string_to_expr("::abc::def::return".to_string()); }) } @@ -59,7 +59,7 @@ fn bad_path_expr_1() { // Checks the token-tree-ization of macros. #[test] fn string_to_tts_macro() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let tts: Vec<_> = string_to_stream("macro_rules! zip (($a)=>($a))".to_string()).trees().collect(); let tts: &[TokenTree] = &tts[..]; @@ -96,7 +96,7 @@ fn string_to_tts_macro() { #[test] 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 expected = TokenStream::new(vec![ @@ -131,7 +131,7 @@ fn string_to_tts_1() { #[test] fn parse_use() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let use_s = "use foo::bar::baz;"; let vitem = string_to_item(use_s.to_string()).unwrap(); let vitem_s = item_to_string(&vitem); @@ -146,7 +146,7 @@ fn parse_use() { #[test] fn parse_extern_crate() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let ex_s = "extern crate foo;"; let vitem = string_to_item(ex_s.to_string()).unwrap(); let vitem_s = item_to_string(&vitem); @@ -184,7 +184,7 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> { #[test] fn span_of_self_arg_pat_idents_are_correct() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let srcs = [ "impl z { fn a (&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] fn parse_exprs() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { // just make sure that they parse.... string_to_expr("3 + 4".to_string()); string_to_expr("a::z.froob(b,&(987+3))".to_string()); @@ -217,7 +217,7 @@ fn parse_exprs() { #[test] fn attrs_fix_bug() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { string_to_item( "pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) -> Result<Box<Writer>, String> { @@ -238,7 +238,7 @@ let mut fflags: c_int = wb(); #[test] fn crlf_doc_comments() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let sess = sess(); 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() } - with_default_session_globals(|| { + create_default_session_globals_then(|| { let sess = sess(); let expr = parse_expr_from_source_str( PathBuf::from("foo").into(), @@ -300,7 +300,7 @@ fn ttdelim_span() { // See `recurse_into_file_modules` in the parser. #[test] fn out_of_line_mod() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let item = parse_item_from_source_str( PathBuf::from("foo").into(), "mod foo { struct S; mod this_does_not_exist; }".to_owned(), diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs index f2345ff2707..ed3aa1eaca8 100644 --- a/compiler/rustc_expand/src/tests.rs +++ b/compiler/rustc_expand/src/tests.rs @@ -2,8 +2,8 @@ use rustc_ast as ast; use rustc_ast::tokenstream::TokenStream; use rustc_parse::{new_parser_from_source_str, parser::Parser, source_file_to_stream}; 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::with_default_session_globals; use rustc_span::{BytePos, MultiSpan, Span}; 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) { - with_default_session_globals(|| { + create_default_session_if_not_set_then(|_| { let output = Arc::new(Mutex::new(Vec::new())); let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); diff --git a/compiler/rustc_expand/src/tokenstream/tests.rs b/compiler/rustc_expand/src/tokenstream/tests.rs index 8b546e7e4a3..31052bfb54c 100644 --- a/compiler/rustc_expand/src/tokenstream/tests.rs +++ b/compiler/rustc_expand/src/tokenstream/tests.rs @@ -2,7 +2,7 @@ use crate::tests::string_to_stream; use rustc_ast::token; 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 smallvec::smallvec; @@ -20,7 +20,7 @@ fn joint(tree: TokenTree) -> TokenStream { #[test] fn test_concat() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts("foo::bar::baz"); let test_fst = string_to_ts("foo::bar"); let test_snd = string_to_ts("::baz"); @@ -33,7 +33,7 @@ fn test_concat() { #[test] 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_end = test_start.trees().collect(); assert_eq!(test_start, test_end) @@ -42,7 +42,7 @@ fn test_to_from_bijection() { #[test] fn test_eq_0() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts("foo"); let test_eqs = string_to_ts("foo"); assert_eq!(test_res, test_eqs) @@ -51,7 +51,7 @@ fn test_eq_0() { #[test] fn test_eq_1() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts("::bar::baz"); let test_eqs = string_to_ts("::bar::baz"); assert_eq!(test_res, test_eqs) @@ -60,7 +60,7 @@ fn test_eq_1() { #[test] fn test_eq_3() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts(""); let test_eqs = string_to_ts(""); assert_eq!(test_res, test_eqs) @@ -69,7 +69,7 @@ fn test_eq_3() { #[test] fn test_diseq_0() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts("::bar::baz"); let test_eqs = string_to_ts("bar::baz"); assert_eq!(test_res == test_eqs, false) @@ -78,7 +78,7 @@ fn test_diseq_0() { #[test] fn test_diseq_1() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test_res = string_to_ts("(bar,baz)"); let test_eqs = string_to_ts("bar,baz"); assert_eq!(test_res == test_eqs, false) @@ -87,7 +87,7 @@ fn test_diseq_1() { #[test] fn test_is_empty() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let test0: TokenStream = Vec::<TokenTree>::new().into_iter().collect(); let test1: TokenStream = TokenTree::token(token::Ident(Symbol::intern("a"), false), sp(0, 1)).into(); @@ -101,7 +101,7 @@ fn test_is_empty() { #[test] fn test_dotdotdot() { - with_default_session_globals(|| { + create_default_session_globals_then(|| { let mut builder = TokenStreamBuilder::new(); builder.push(joint(TokenTree::token(token::Dot, sp(0, 1)))); builder.push(joint(TokenTree::token(token::Dot, sp(1, 2)))); |
