Call syntax::with_globals before using a parser
This commit is contained in:
parent
a353294fe4
commit
eda626cfc9
2 changed files with 25 additions and 12 deletions
|
@ -657,6 +657,14 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_input<T: Write>(
|
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,
|
input: Input,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
mut out: Option<&mut T>,
|
mut out: Option<&mut T>,
|
||||||
|
|
|
@ -962,22 +962,27 @@ fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream)
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use syntax;
|
||||||
use syntax::parse::{parse_stream_from_source_str, ParseSess};
|
use syntax::parse::{parse_stream_from_source_str, ParseSess};
|
||||||
use syntax::codemap::{FileName, FilePathMapping};
|
use syntax::codemap::{FileName, FilePathMapping};
|
||||||
|
|
||||||
fn format_macro_args_str(s: &str) -> String {
|
fn format_macro_args_str(s: &str) -> String {
|
||||||
let input = parse_stream_from_source_str(
|
let mut result = String::new();
|
||||||
FileName::Custom("stdin".to_owned()),
|
syntax::with_globals(|| {
|
||||||
s.to_owned(),
|
let input = parse_stream_from_source_str(
|
||||||
&ParseSess::new(FilePathMapping::empty()),
|
FileName::Custom("stdin".to_owned()),
|
||||||
None,
|
s.to_owned(),
|
||||||
);
|
&ParseSess::new(FilePathMapping::empty()),
|
||||||
let shape = Shape {
|
None,
|
||||||
width: 100,
|
);
|
||||||
indent: Indent::empty(),
|
let shape = Shape {
|
||||||
offset: 0,
|
width: 100,
|
||||||
};
|
indent: Indent::empty(),
|
||||||
format_macro_args(input.into(), shape).unwrap()
|
offset: 0,
|
||||||
|
};
|
||||||
|
result = format_macro_args(input.into(), shape).unwrap();
|
||||||
|
});
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue