Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Fixed
- (Style Edition 2027) Properly format closures with wrapped parameters and an explicit return type instead of leaving the enclosing expression unformatted. Issue: [#7012](https://github.com/rust-lang/rustfmt/issues/7012).


## [1.10.0] 2026-07-21

Expand Down
11 changes: 10 additions & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,16 @@ fn rewrite_closure_fn_decl(
prefix.push_str(&ret_str);
}
// 1 = space between `|...|` and body.
let extra_offset = last_line_width(&prefix) + 1;
let last_line = last_line_width(&prefix) + 1;
let extra_offset =
if prefix.contains('\n') && context.config.style_edition() >= StyleEdition::Edition2027 {
// The return type was pushed onto a line of its own, so `last_line_width` measures
// from column zero. Callers apply this offset on top of `shape`, so subtract the
// width already accounted for by `shape` to avoid counting the indent twice.
last_line.saturating_sub(shape.used_width())
} else {
last_line
};

Ok((prefix, extra_offset))
}
Expand Down
27 changes: 27 additions & 0 deletions tests/source/issue_7012_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// rustfmt-style_edition: 2024

fn test() {
if outer {
if inner {
if even_more_inner {
let items = page
.into_iter()
.map(
|list_media_response::ListEntry {
cdn,
media_id,
length,
}|
-> Result<_, RequestError<BackupAuthCredentialRejected>> {
Ok(ListMediaItem {
cdn,
media_id,
object_length: length,
})
},
)
.try_collect()?;
}
}
}
}
27 changes: 27 additions & 0 deletions tests/source/issue_7012_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// rustfmt-style_edition: 2027

fn test() {
if outer {
if inner {
if even_more_inner {
let items = page
.into_iter()
.map(
|list_media_response::ListEntry {
cdn,
media_id,
length,
}|
-> Result<_, RequestError<BackupAuthCredentialRejected>> {
Ok(ListMediaItem {
cdn,
media_id,
object_length: length,
})
},
)
.try_collect()?;
}
}
}
}
27 changes: 27 additions & 0 deletions tests/target/issue_7012_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// rustfmt-style_edition: 2024

fn test() {
if outer {
if inner {
if even_more_inner {
let items = page
.into_iter()
.map(
|list_media_response::ListEntry {
cdn,
media_id,
length,
}|
-> Result<_, RequestError<BackupAuthCredentialRejected>> {
Ok(ListMediaItem {
cdn,
media_id,
object_length: length,
})
},
)
.try_collect()?;
}
}
}
}
27 changes: 27 additions & 0 deletions tests/target/issue_7012_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// rustfmt-style_edition: 2027

fn test() {
if outer {
if inner {
if even_more_inner {
let items = page
.into_iter()
.map(
|list_media_response::ListEntry {
cdn,
media_id,
length,
}|
-> Result<_, RequestError<BackupAuthCredentialRejected>> {
Ok(ListMediaItem {
cdn,
media_id,
object_length: length,
})
},
)
.try_collect()?;
}
}
}
}
Loading