From eda626cfc9659658a89cc28680066f69aef11b0e Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Thu, 15 Mar 2018 18:55:52 +0900 Subject: [PATCH] Call syntax::with_globals before using a parser --- src/lib.rs | 8 ++++++++ src/macros.rs | 29 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9857abe2b52..37cf29196ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -657,6 +657,14 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option } pub fn format_input( + input: Input, + config: &Config, + out: Option<&mut T>, +) -> Result<(Summary, FileMap, FormatReport), (io::Error, Summary)> { + syntax::with_globals(|| format_input_inner(input, config, out)) +} + +fn format_input_inner( input: Input, config: &Config, mut out: Option<&mut T>, diff --git a/src/macros.rs b/src/macros.rs index 78a8f0c0b31..b260e15501f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -962,22 +962,27 @@ fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream) #[cfg(test)] mod test { use super::*; + use syntax; use syntax::parse::{parse_stream_from_source_str, ParseSess}; use syntax::codemap::{FileName, FilePathMapping}; fn format_macro_args_str(s: &str) -> String { - let input = parse_stream_from_source_str( - FileName::Custom("stdin".to_owned()), - s.to_owned(), - &ParseSess::new(FilePathMapping::empty()), - None, - ); - let shape = Shape { - width: 100, - indent: Indent::empty(), - offset: 0, - }; - format_macro_args(input.into(), shape).unwrap() + let mut result = String::new(); + syntax::with_globals(|| { + let input = parse_stream_from_source_str( + FileName::Custom("stdin".to_owned()), + s.to_owned(), + &ParseSess::new(FilePathMapping::empty()), + None, + ); + let shape = Shape { + width: 100, + indent: Indent::empty(), + offset: 0, + }; + result = format_macro_args(input.into(), shape).unwrap(); + }); + result } #[test]