Skip to content

Commit eda626c

Browse files
committed
Call syntax::with_globals before using a parser
1 parent a353294 commit eda626c

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
657657
}
658658

659659
pub fn format_input<T: Write>(
660+
input: Input,
661+
config: &Config,
662+
out: Option<&mut T>,
663+
) -> Result<(Summary, FileMap, FormatReport), (io::Error, Summary)> {
664+
syntax::with_globals(|| format_input_inner(input, config, out))
665+
}
666+
667+
fn format_input_inner<T: Write>(
660668
input: Input,
661669
config: &Config,
662670
mut out: Option<&mut T>,

src/macros.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -962,22 +962,27 @@ fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream)
962962
#[cfg(test)]
963963
mod test {
964964
use super::*;
965+
use syntax;
965966
use syntax::parse::{parse_stream_from_source_str, ParseSess};
966967
use syntax::codemap::{FileName, FilePathMapping};
967968

968969
fn format_macro_args_str(s: &str) -> String {
969-
let input = parse_stream_from_source_str(
970-
FileName::Custom("stdin".to_owned()),
971-
s.to_owned(),
972-
&ParseSess::new(FilePathMapping::empty()),
973-
None,
974-
);
975-
let shape = Shape {
976-
width: 100,
977-
indent: Indent::empty(),
978-
offset: 0,
979-
};
980-
format_macro_args(input.into(), shape).unwrap()
970+
let mut result = String::new();
971+
syntax::with_globals(|| {
972+
let input = parse_stream_from_source_str(
973+
FileName::Custom("stdin".to_owned()),
974+
s.to_owned(),
975+
&ParseSess::new(FilePathMapping::empty()),
976+
None,
977+
);
978+
let shape = Shape {
979+
width: 100,
980+
indent: Indent::empty(),
981+
offset: 0,
982+
};
983+
result = format_macro_args(input.into(), shape).unwrap();
984+
});
985+
result
981986
}
982987

983988
#[test]

0 commit comments

Comments
 (0)