From e219932eff68c5aeaf2cc181302a57472310cbb1 Mon Sep 17 00:00:00 2001 From: 0xcharry Date: Wed, 10 Dec 2025 20:32:01 +0100 Subject: [PATCH 1/2] Update common.rs --- crates/fmt/src/state/common.rs | 47 +--------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/crates/fmt/src/state/common.rs b/crates/fmt/src/state/common.rs index e3e37c5169329..5352464a69642 100644 --- a/crates/fmt/src/state/common.rs +++ b/crates/fmt/src/state/common.rs @@ -1,5 +1,5 @@ use super::{CommentConfig, Separator, State}; -use crate::pp::{BreakToken, Printer, SIZE_INFINITY}; +use crate::pp::{Printer, SIZE_INFINITY}; use foundry_common::iter::IterDelimited; use foundry_config::fmt as config; use itertools::{Either, Itertools}; @@ -573,12 +573,6 @@ impl<'ast> State<'_, 'ast> { mut get_block_span: impl FnMut(&'ast T) -> Span, pos_hi: BytePos, ) { - // Attempt to print in a single line. - if block_format.attempt_single_line() && block.len() == 1 { - self.print_single_line_block(block, block_format, print, get_block_span); - return; - } - // Empty blocks with comments require special attention. if block.is_empty() { self.print_empty_block(block_format, pos_hi); @@ -706,37 +700,6 @@ impl<'ast> State<'_, 'ast> { self.block_depth -= 1; } - fn print_single_line_block( - &mut self, - block: &'ast [T], - block_format: BlockFormat, - mut print: impl FnMut(&mut Self, &'ast T), - mut get_block_span: impl FnMut(&'ast T) -> Span, - ) { - self.s.cbox(self.ind); - - match block_format { - BlockFormat::Compact(true) => { - self.scan_break(BreakToken { pre_break: Some("{"), ..Default::default() }); - print(self, &block[0]); - self.print_comments(get_block_span(&block[0]).hi(), CommentConfig::default()); - self.s.scan_break(BreakToken { post_break: Some("}"), ..Default::default() }); - self.s.offset(-self.ind); - } - _ => { - self.word("{"); - self.space(); - print(self, &block[0]); - self.print_comments(get_block_span(&block[0]).hi(), CommentConfig::default()); - self.space_if_not_bol(); - self.s.offset(-self.ind); - self.word("}"); - } - } - - self.end(); - } - fn print_empty_block(&mut self, block_format: BlockFormat, pos_hi: BytePos) { let has_braces = block_format.with_braces(); @@ -935,12 +898,8 @@ impl ListFormat { /// Formatting style for code blocks #[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[expect(dead_code)] pub(crate) enum BlockFormat { Regular, - /// Attempts to fit all elements in one line, before breaking consistently. Flags whether to - /// use braces or not. - Compact(bool), /// Doesn't print braces. Flags the offset that should be applied before opening the block box. /// Useful when the caller needs to manually handle the braces. NoBraces(Option), @@ -953,8 +912,4 @@ impl BlockFormat { pub(crate) fn breaks(&self) -> bool { matches!(self, Self::NoBraces(None)) } - - pub(crate) fn attempt_single_line(&self) -> bool { - matches!(self, Self::Compact(_)) - } } From c55c2e293d000b68efbdb5b495e11781bbb74ae3 Mon Sep 17 00:00:00 2001 From: 0xcharry Date: Wed, 10 Dec 2025 20:35:21 +0100 Subject: [PATCH 2/2] Update sol.rs --- crates/fmt/src/state/sol.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/fmt/src/state/sol.rs b/crates/fmt/src/state/sol.rs index 52fb7fe0172f1..c20bed3e85bec 100644 --- a/crates/fmt/src/state/sol.rs +++ b/crates/fmt/src/state/sol.rs @@ -2678,12 +2678,11 @@ impl MemberOrCallArgs { } #[derive(Debug, Clone)] -#[expect(dead_code)] enum AttributeKind<'ast> { - Visibility(ast::Visibility), - StateMutability(ast::StateMutability), + Visibility, + StateMutability, Virtual, - Override(&'ast ast::Override<'ast>), + Override, Modifier(&'ast ast::Modifier<'ast>), } @@ -2757,14 +2756,14 @@ impl<'ast> AttributeCommentMapper<'ast> { first_pos = v.span.lo() } self.attributes - .push(AttributeInfo { kind: AttributeKind::Visibility(*v), span: v.span }); + .push(AttributeInfo { kind: AttributeKind::Visibility, span: v.span }); } if let Some(sm) = header.state_mutability { if sm.span.lo() < first_pos { first_pos = sm.span.lo() } self.attributes - .push(AttributeInfo { kind: AttributeKind::StateMutability(*sm), span: sm.span }); + .push(AttributeInfo { kind: AttributeKind::StateMutability, span: sm.span }); } if let Some(span) = header.virtual_ { if span.lo() < first_pos { @@ -2776,7 +2775,7 @@ impl<'ast> AttributeCommentMapper<'ast> { if o.span.lo() < first_pos { first_pos = o.span.lo() } - self.attributes.push(AttributeInfo { kind: AttributeKind::Override(o), span: o.span }); + self.attributes.push(AttributeInfo { kind: AttributeKind::Override, span: o.span }); } for m in header.modifiers.iter() { if m.span().lo() < first_pos {