fix: Don't insert an extra brace in macros with native newlines

Due to `format_snippet` formatting the input with \r\n the subtraction
would wouldn't give a length that removed the }

Fixes #2641
This commit is contained in:
Markus Westerlind 2018-05-08 20:31:33 +02:00
parent f46f4b5f66
commit 4c9ef93df7
4 changed files with 8 additions and 1 deletions

View File

@ -645,7 +645,7 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
// then unindent the whole code block.
let formatted = format_snippet(&snippet, config)?;
// 2 = "}\n"
let block_len = formatted.len().checked_sub(2).unwrap_or(0);
let block_len = formatted.rfind('}').unwrap_or(formatted.len());
let mut is_indented = true;
for (kind, ref line) in LineClasses::new(&formatted[FN_MAIN_PREFIX.len()..block_len]) {
if !is_first {

View File

@ -0,0 +1 @@
newline_style = "Windows"

View File

@ -0,0 +1,3 @@
macro_rules! a {
() => {{}}
}

View File

@ -0,0 +1,3 @@
macro_rules! a {
() => {{}};
}