mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 16:15:03 +00:00
Call syntax::with_globals before using a parser
This commit is contained in:
parent
a353294fe4
commit
eda626cfc9
@ -657,6 +657,14 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
|
||||
}
|
||||
|
||||
pub fn format_input<T: Write>(
|
||||
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<T: Write>(
|
||||
input: Input,
|
||||
config: &Config,
|
||||
mut out: Option<&mut T>,
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user