diff --git a/rustfmt-core/rustfmt-lib/src/lib.rs b/rustfmt-core/rustfmt-lib/src/lib.rs index 4dc0981b6c6..29e2a7c360e 100644 --- a/rustfmt-core/rustfmt-lib/src/lib.rs +++ b/rustfmt-core/rustfmt-lib/src/lib.rs @@ -350,6 +350,7 @@ fn format_code_block(code_snippet: &str, config: &Config) -> Option Option config.tab_spaces() { + } else if line.len() > indent_str.len() { // Make sure that the line has leading whitespaces. - let indent_str = Indent::from_width(config, config.tab_spaces()).to_string(config); if line.starts_with(indent_str.as_ref()) { let offset = if config.hard_tabs() { 1 diff --git a/rustfmt-core/rustfmt-lib/tests/target/issue-4152.rs b/rustfmt-core/rustfmt-lib/tests/target/issue-4152.rs new file mode 100644 index 00000000000..80f9ff5e304 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/target/issue-4152.rs @@ -0,0 +1,18 @@ +// rustfmt-hard_tabs: true + +macro_rules! bit { + ($bool:expr) => { + if $bool { + 1; + 1 + } else { + 0; + 0 + } + }; +} +macro_rules! add_one { + ($vec:expr) => {{ + $vec.push(1); + }}; +}