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:
parent
f46f4b5f66
commit
4c9ef93df7
@ -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 {
|
||||
|
1
tests/config/issue-2641.toml
Normal file
1
tests/config/issue-2641.toml
Normal file
@ -0,0 +1 @@
|
||||
newline_style = "Windows"
|
3
tests/source/issue-2641.rs
Normal file
3
tests/source/issue-2641.rs
Normal file
@ -0,0 +1,3 @@
|
||||
macro_rules! a {
|
||||
() => {{}}
|
||||
}
|
3
tests/target/issue-2641.rs
Normal file
3
tests/target/issue-2641.rs
Normal file
@ -0,0 +1,3 @@
|
||||
macro_rules! a {
|
||||
() => {{}};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user