diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 94052d9a93df..7dda996f8062 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -1537,7 +1537,17 @@ impl<'a, W: Write> Formatter<'a, W> { let returns_start_loc = func.returns.first().unwrap().0; let returns_loc = returns_start_loc.with_end_from(&func.returns.last().unwrap().0); if fmt.inline_config.is_disabled(returns_loc) { - fmt.indented(1, |fmt| fmt.visit_source(returns_loc))?; + fmt.indented(1, |fmt| { + fmt.surrounded( + SurroundingChunk::new("returns (", Some(returns_loc.start()), None), + SurroundingChunk::new(")", None, returns_end), + |fmt, _| { + fmt.visit_source(returns_loc)?; + Ok(()) + }, + )?; + Ok(()) + })?; } else { let mut returns = fmt.items_to_chunks( returns_end, diff --git a/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/fmt.sol b/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/fmt.sol index 556db3698eaf..7b751e22ec26 100644 --- a/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/fmt.sol +++ b/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/fmt.sol @@ -11,3 +11,11 @@ contract ReturnFnFormat { ) {} } + +// https://github.com/foundry-rs/foundry/issues/7920 +contract ReturnFnDisableFormat { + // forgefmt: disable-next-line + function disableFnFormat() external returns (uint256) { + return 0; + } +} diff --git a/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/original.sol b/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/original.sol index 79008d44ae3a..0c785cde81b1 100644 --- a/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/original.sol +++ b/crates/fmt/testdata/FunctionDefinitionWithFunctionReturns/original.sol @@ -10,4 +10,12 @@ contract ReturnFnFormat { internal pure returns (uint256) ) {} +} + +// https://github.com/foundry-rs/foundry/issues/7920 +contract ReturnFnDisableFormat { + // forgefmt: disable-next-line + function disableFnFormat() external returns (uint256) { + return 0; + } } \ No newline at end of file