Comments are never dropped #

highcomment

rustfmt drops comments in some positions; apfmt keeps every comment.

Why A formatter must not lose text the author wrote.
Details

rustfmt silently deletes comments in several positions, such as around ->, inside parenthesized types and bounds, and inside use declarations. apfmt keeps all of them, at or close to where they were written.

Style Guide
Does not settle this.

A comment before ->#edition 2024

rustfmt drops the comment. apfmt keeps it in place.

Input
1fn before_arrow() /* a */ -> u32 {}
apfmt c9342b5
1fn before_arrow() /* a */ -> u32 {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn before_arrow() -> u32 {}

A comment after ->#edition 2024

rustfmt drops the comment. apfmt keeps it in place.

Input
1fn after_arrow() -> /* b */ u32 {}
apfmt c9342b5
1fn after_arrow() -> /* b */ u32 {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn after_arrow() -> u32 {}

Comments around the name of a function#edition 2024

rustfmt drops the first two comments. apfmt keeps all three.

Input
1fn /* a */ f /* b */() /* c */ {}
apfmt c9342b5
1fn /* a */ f /* b */() /* c */ {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() /* c */ {}

A line comment before ->#edition 2024

rustfmt drops the comment. apfmt keeps it and puts -> u32 on an indented line.

Input
1fn f() // c
2-> u32 {
3 1
4}
apfmt c9342b5
1fn f() // c
2 -> u32 {
3 1
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() -> u32 {
2 1
3}

A comment in a parenthesized type#edition 2024

rustfmt drops the comment. apfmt keeps it and breaks the parentheses.

Input
1type T = &(
2 // c
3 dyn A
4);
apfmt c9342b5
1type T = &(
2 // c
3 dyn A
4);
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1type T = &(dyn A);

A comment in a parenthesized bound#edition 2024

rustfmt drops the comment. apfmt keeps it.

Input
1fn h<G: (/* c */ Clone)>() {}
apfmt c9342b5
1fn h<G: (/* c */ Clone)>() {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn h<G: (Clone)>() {}

Comments inside use declarations#edition 2024

rustfmt drops the comments, and drops the last use entirely. apfmt keeps them in place.

Input
1use /* c */ a::b;
2use a /* x */ :: c;
3use a::d as /* r */ e;
4use a::{ /* only */ };
apfmt c9342b5
1use /* c */ a::b;
2use a /* x */::c;
3use a::d as /* r */ e;
4use a::{/* only */};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::b;
2use a::c;
3use a::d as e;

A comment before the ; of a use#edition 2024

rustfmt drops the comment. apfmt moves it after the ;.

Input
1use a::{b} /* after */;
apfmt c9342b5
1use a::b; /* after */
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::b;

Macro arguments keep the joining of their punctuation #

highmacro

apfmt leaves macro arguments unchanged when formatting would add or remove a space between punctuation characters; rustfmt reformats them.

Why Adding or removing a space between punctuation characters can change what a procedural macro does.
Details

A procedural macro can see whether two punctuation characters are written next to each other, and its custom syntax may read them as one operator, such as <-, <-> or --. apfmt formats macro arguments that parse as an expression only if every such pair stays as written. Otherwise it copies the arguments unchanged, just as it copies arguments that do not parse.

rustfmt formats them anyway (it only leaves x<-y alone), which can change what the macro does.

Commas, semicolons and the spacing after ? are not checked, because they are never part of an operator.

Style Guide
Does not settle this.

A custom operator#edition 2024

Input
1fn main() {
2 let a = arg!(-f --foo);
3}
apfmt c9342b5
1fn main() {
2 let a = arg!(-f --foo);
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let a = arg!(-f - -foo);
3}

& & must not become &&#edition 2024

Input
1fn main() {
2 m!(& &x);
3}
apfmt c9342b5
1fn main() {
2 m!(& &x);
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 m!(&&x);
3}

.. .. keeps its spacing#edition 2024

Input
1fn main() {
2 m!(a .. .. b);
3}
apfmt c9342b5
1fn main() {
2 m!(a .. .. b);
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 m!(a.. ..b);
3}

< < must not become <<#edition 2024

Input
1fn main() {
2 m!(Vec< <T as Trait>::Assoc>::new());
3}
apfmt c9342b5
1fn main() {
2 m!(Vec< <T as Trait>::Assoc>::new());
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 m!(Vec<<T as Trait>::Assoc>::new());
3}

A string in a copied macro body keeps its text #

highmacrostring

When a macro body that cannot be parsed is reindented, apfmt leaves the text of its string literals alone; rustfmt shifts it and so changes the string.

Why Changing the value of a string is not a formatting decision.
Details

A macro body that does not parse is copied and reindented with its statement. apfmt keeps the lines of a multi-line string literal exactly as they are. rustfmt shifts them along with the code, which changes the value of the string.

Style Guide
Does not settle this.

A multi-line string moves with its macro#edition 2024

Input
1fn main() {
2 m! {
3 a b
4 "x
5 y"
6 }
7}
apfmt c9342b5
1fn main() {
2 m! {
3 a b
4 "x
5 y"
6 }
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 m! {
3 a b
4 "x
5 y"
6 }
7}

A last chain element follows the closing delimiter #

highchain

When the start of a chain spans several lines, apfmt puts a single remaining element right after the closing delimiter ().await?); rustfmt puts it on its own line.

Why It saves a line and keeps the element attached to the call it applies to.
Details

When the first part of a chain (its root) spans several lines, the Style Guide joins the next element to the closing line and block-indents any others. Neither formatter follows this. With two or more remaining elements, apfmt does what rustfmt does: each element goes on its own line at the indentation of the root. They differ when only one element remains: apfmt puts it after the closing delimiter, and rustfmt puts it on its own line. If the element does not fit after the delimiter, apfmt puts it on its own line too.

In the head of an if let, a while let or a let chain, the line this saves lets apfmt move the whole expression to the line after =, as the Style Guide prefers: "prefer breaking after the = for any let sub-expression in an if or while expression that does not fit". rustfmt keeps the chain broken on the line of =. In a plain let statement, apfmt also keeps a multi-line expression on the line of =, unless moving it saves at least two lines.

Style Guide
Follows it: neither

A single element follows the closing delimiter#edition 2024

Input
1async fn call_root() {
2 let response = command_job_output(gsettings, &mut session, opts.job_selector, get_task_selector(Some(opts.task_selector)), opts.stream).await?;
3 let filler = std::iter::repeat_n(style.unused_area, num_characters as usize - indicator_count as usize).collect::<String>();
4}
apfmt c9342b5
1async fn call_root() {
2 let response = command_job_output(
3 gsettings,
4 &mut session,
5 opts.job_selector,
6 get_task_selector(Some(opts.task_selector)),
7 opts.stream,
8 ).await?;
9 let filler = std::iter::repeat_n(
10 style.unused_area,
11 num_characters as usize - indicator_count as usize,
12 ).collect::<String>();
13}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1async fn call_root() {
2 let response = command_job_output(
3 gsettings,
4 &mut session,
5 opts.job_selector,
6 get_task_selector(Some(opts.task_selector)),
7 opts.stream,
8 )
9 .await?;
10 let filler = std::iter::repeat_n(
11 style.unused_area,
12 num_characters as usize - indicator_count as usize,
13 )
14 .collect::<String>();
15}

In a match head#edition 2024

Input
1fn element_after_closing() {
2 match LayoutApplier::new(&self.viewport, &self.senders, &self.sixel_image_store, &self.link_handlerr).apply() {
3 Ok(x) => x,
4 Err(e) => e,
5 }
6}
apfmt c9342b5
1fn element_after_closing() {
2 match LayoutApplier::new(
3 &self.viewport,
4 &self.senders,
5 &self.sixel_image_store,
6 &self.link_handlerr,
7 ).apply()
8 {
9 Ok(x) => x,
10 Err(e) => e,
11 }
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn element_after_closing() {
2 match LayoutApplier::new(
3 &self.viewport,
4 &self.senders,
5 &self.sixel_image_store,
6 &self.link_handlerr,
7 )
8 .apply()
9 {
10 Ok(x) => x,
11 Err(e) => e,
12 }
13}

In the head of if let, the saved line moves the expression after =#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 if let Some(url) = maybe_url && let Some(items) = self.get_variable_items(&key, url, &snapshot, &tokens, &match_result).await {
9 body();
10 }
11 if let Some(items) = self.get_variable_items(&key, url, &snapshot, &tokens, &match_result_long_name).await {
12 body();
13 }
14 }
15 }
16 }
17 }
18 }
19 }
20}
apfmt c9342b5
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 if let Some(url) = maybe_url
9 && let Some(items) =
10 self.get_variable_items(
11 &key,
12 url,
13 &snapshot,
14 &tokens,
15 &match_result,
16 ).await
17 {
18 body();
19 }
20 if let Some(items) =
21 self.get_variable_items(
22 &key,
23 url,
24 &snapshot,
25 &tokens,
26 &match_result_long_name,
27 ).await
28 {
29 body();
30 }
31 }
32 }
33 }
34 }
35 }
36 }
37}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 if let Some(url) = maybe_url
9 && let Some(items) = self
10 .get_variable_items(
11 &key,
12 url,
13 &snapshot,
14 &tokens,
15 &match_result,
16 )
17 .await
18 {
19 body();
20 }
21 if let Some(items) = self
22 .get_variable_items(
23 &key,
24 url,
25 &snapshot,
26 &tokens,
27 &match_result_long_name,
28 )
29 .await
30 {
31 body();
32 }
33 }
34 }
35 }
36 }
37 }
38 }
39}

More elements stay on lines of their own in both#edition 2024

Input
1fn main() {
2 foo(
3 a, // c
4 )
5 .baz?
6 .qux();
7}
apfmt c9342b5 · rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 foo(
3 a, // c
4 )
5 .baz?
6 .qux();
7}

Trailing commas in macro arguments #

highmacrocomma

apfmt adds a trailing comma to broken lists nested in macro arguments and removes it from lists on one line; rustfmt does neither.

Why A nested list is an ordinary expression, so its comma is always valid, and the Style Guide treats it like any other list.
Details

A broken list (call arguments, struct literal fields, array elements) nested in macro arguments gets a trailing comma, as the Style Guide asks for any broken list. rustfmt omits it inside macro calls.

The last argument of the macro call itself gets no trailing comma in either formatter, because the macro might not accept one. A nested list is parsed as an expression, so a comma there is always valid.

A list on one line has no trailing comma (Style Guide). When a list in macro arguments has a trailing comma and fits on one line, rustfmt keeps the comma.

Style Guide
Follows it: apfmt

A broken nested list#edition 2024

Input
1fn main() {
2 assert_eq!(x, Some(TxnState::Ongoing { min_commit_ts: 3.into(), aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 1 }));
3}
apfmt c9342b5
1fn main() {
2 assert_eq!(
3 x,
4 Some(TxnState::Ongoing {
5 min_commit_ts: 3.into(),
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 1,
7 })
8 );
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 assert_eq!(
3 x,
4 Some(TxnState::Ongoing {
5 min_commit_ts: 3.into(),
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 1
7 })
8 );
9}

A nested list that fits on one line#edition 2024

Input
1fn main() {
2 assert_eq!(req_ver, RequestedVersion::Latest(
3 ReleaseChannel::Canary,
4 ));
5}
apfmt c9342b5
1fn main() {
2 assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Canary));
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Canary,));
3}

Attribute arguments are laid out as call arguments #

highattributecomma

apfmt lays out attribute arguments like call arguments, always with a trailing comma when broken; rustfmt writes the comma only if the source has it.

Why The Style Guide formats attribute argument lists like function calls, whatever the source has.
Details

The Style Guide says: "For attributes with argument lists, format like functions." apfmt does this for #[derive(...)], #[cfg(...)], #[cfg_attr(...)] and similar attributes, within the attr_fn_like_width limit: the arguments go on one line, or one per line with a trailing comma. Both formatters make one exception and fill a broken derive list with several names per line.

rustfmt differs in three ways:

  • In a broken list, nested or not, it writes a trailing comma only if the source has one. apfmt always writes it; built-in attributes and common procedural macros accept it.
  • On one line, it removes the trailing comma of the attribute's own list but keeps one in a nested list (cfg(all(a, b,))). apfmt removes both.
  • If a value is not a literal (sql_type = a::b), it leaves the attribute on one line as long as it fits within max_width. apfmt applies attr_fn_like_width here too.
Style Guide
Follows it: apfmt
For attributes with argument lists, format like functions.
Related
A multi-line string hugs the list as in the source

A broken nested list gets a trailing comma#edition 2024

Input
1#[cfg(all(target_os = "linux", not(any(feature = "aaaaaaaaaaa", feature = "bbbbbbbbbbbbbbbbbbbbbbbbb"))))]
2fn f() {}
apfmt c9342b5
1#[cfg(all(
2 target_os = "linux",
3 not(any(feature = "aaaaaaaaaaa", feature = "bbbbbbbbbbbbbbbbbbbbbbbbb")),
4))]
5fn f() {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1#[cfg(all(
2 target_os = "linux",
3 not(any(feature = "aaaaaaaaaaa", feature = "bbbbbbbbbbbbbbbbbbbbbbbbb"))
4))]
5fn f() {}

A non-literal value does not keep the attribute on one line#edition 2024

Input
1#[cfg_attr(feature = "__sqlite-shared", diesel(sql_type = crate::sql_types::TimestamptzSqlite))]
2struct A;
apfmt c9342b5
1#[cfg_attr(
2 feature = "__sqlite-shared",
3 diesel(sql_type = crate::sql_types::TimestamptzSqlite),
4)]
5struct A;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1#[cfg_attr(feature = "__sqlite-shared", diesel(sql_type = crate::sql_types::TimestamptzSqlite))]
2struct A;

A trailing comma of a nested list on one line#edition 2024

Input
1#[cfg(all(a, b,))]
2fn f() {}
apfmt c9342b5
1#[cfg(all(a, b))]
2fn f() {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1#[cfg(all(a, b,))]
2fn f() {}

A single argument is not hugged when it fits on its own line #

highcallhugging

When the only argument does not fit on the line of the call, apfmt puts it on its own line if it fits there; rustfmt hugs it and breaks its contents.

Why It takes fewer lines.
Details

Hugging means that the inner delimiters stay next to the outer ones and only the contents are broken, with outer(inner( on the first line and )) on the last. When the only argument of a call is another call or a tuple that does not fit on the line, rustfmt hugs it. apfmt puts the argument on its own indented line if it fits there, which takes fewer lines. The same applies to a tuple that is the only element of an array.

A one-element tuple (x,) as the only argument either hugs like any other delimited argument or goes on its own line. rustfmt instead breaks the chain inside it at its root and closes the tuple with ,) on the line of the last element.

Style Guide
Does not settle this.

A call as the only argument#edition 2024

Input
1fn main() {
2 outer(inner(first_argument_value, second_argument_value, third_xxx));
3}
apfmt c9342b5
1fn main() {
2 outer(
3 inner(first_argument_value, second_argument_value, third_xxx),
4 );
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 outer(inner(
3 first_argument_value,
4 second_argument_value,
5 third_xxx,
6 ));
7}

A tuple as the only element of an array#edition 2024

Input
1fn f() {
2 let x = Foo {
3 dependencies: BTreeMap::from([("package-peer".to_string(), "package-peer@4.0.0".to_string())]),
4 };
5}
apfmt c9342b5
1fn f() {
2 let x = Foo {
3 dependencies: BTreeMap::from([
4 ("package-peer".to_string(), "package-peer@4.0.0".to_string()),
5 ]),
6 };
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let x = Foo {
3 dependencies: BTreeMap::from([(
4 "package-peer".to_string(),
5 "package-peer@4.0.0".to_string(),
6 )]),
7 };
8}

A one-element tuple as the only argument#edition 2024

Input
1fn f() {
2 {
3 let req = TscRequest::GetOutliningSpans((self.specifier_map.denormalize(&module.specifier, module.media_type),));
4 let req = TscRequest::GetCompletionDetails((specifier_map.normalize(&module.specifier, first_argument)?,));
5 }
6}
apfmt c9342b5
1fn f() {
2 {
3 let req = TscRequest::GetOutliningSpans((
4 self.specifier_map
5 .denormalize(&module.specifier, module.media_type),
6 ));
7 let req = TscRequest::GetCompletionDetails(
8 (specifier_map.normalize(&module.specifier, first_argument)?,),
9 );
10 }
11}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 let req = TscRequest::GetOutliningSpans((self
4 .specifier_map
5 .denormalize(&module.specifier, module.media_type),));
6 let req = TscRequest::GetCompletionDetails((
7 specifier_map.normalize(&module.specifier, first_argument)?,
8 ));
9 }
10}

Code around a line that does not fit is still formatted #

highoverflowgive-up

When one part of an expression does not fit, apfmt still formats the rest; rustfmt often leaves the whole expression as written.

Why One long string should not exempt a whole expression from formatting.
Details

When a part of an expression cannot fit within the line width, rustfmt often gives up and leaves the whole expression as written, including its layout, indentation and punctuation. apfmt formats everything around the long part.

This also explains other differences in such code: rustfmt keeps details of the source there that it would normally change, such as the spacing of quote::quote!{.

Style Guide
Does not settle this.
Related
Lines that overflow anyway do not decide the layout around them

A match with a long arm#edition 2024

Input
1fn main() {
2 let x = match y {
3 A => {
4 g()
5 },
6 B => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_string().into_something(aaaaa, bbbbbb),
7 };
8}
apfmt c9342b51 line over 100
1fn main() {
2 let x = match y {
3 A => g(),
4 B => {
5 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
6 .to_string()
7 .into_something(aaaaa, bbbbbb)
8 }
9 };
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted1 line over 100
1fn main() {
2 let x = match y {
3 A => {
4 g()
5 },
6 B => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_string().into_something(aaaaa, bbbbbb),
7 };
8}

A chain with a long line in a closure#edition 2024

Input
1fn main() {
2 let w = xs.iter().map(|c| {
3 let s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
4 s
5 }).collect::<Vec<_>>();
6}
apfmt c9342b51 line over 100
1fn main() {
2 let w = xs
3 .iter()
4 .map(|c| {
5 let s =
6 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
7 s
8 })
9 .collect::<Vec<_>>();
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted1 line over 100
1fn main() {
2 let w = xs.iter().map(|c| {
3 let s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
4 s
5 }).collect::<Vec<_>>();
6}

macro_rules! transcribers are formatted where they parse #

highmacro

apfmt formats macro_rules! transcribers wherever they parse; rustfmt often leaves a macro_rules! as written.

Why A macro definition is code too, and should not keep its old indentation.
Details

apfmt formats a transcriber (the right-hand side of a rule) when it parses as items or statements once its metavariables are replaced. m!{ gets its space, a { $x } body breaks like a block, and calls and chains inside are laid out as anywhere else.

A transcriber that does not parse is copied and reindented with its rule, so it moves when the indentation of the macro_rules! changes. rustfmt often leaves a macro_rules! exactly as written, including its indentation: code indented with tab_spaces = 2 stays that way even under the default configuration.

Style Guide
Does not settle this.

A rule with a vis metavariable#edition 2024

Input
1macro_rules! c {
2 ($v:vis $n:ident) => { $v struct $n; };
3}
apfmt c9342b5
1macro_rules! c {
2 ($v:vis $n:ident) => {
3 $v struct $n;
4 };
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted
1macro_rules! c {
2 ($v:vis $n:ident) => { $v struct $n; };
3}

A rule with a repetition#edition 2024

Input
1macro_rules! b { ($($x:expr),* $(,)?) => { vec![$($x),*] } }
apfmt c9342b5
1macro_rules! b {
2 ($($x:expr),* $(,)?) => {
3 vec![$($x),*]
4 };
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted
1macro_rules! b { ($($x:expr),* $(,)?) => { vec![$($x),*] } }

A struct literal field value moves to the next line when it overflows #

mediumstructoverflow

If a struct literal field value cannot fit on the line of its name, apfmt moves it to the next line; rustfmt leaves the line too long.

Why The line stays within max_width where that is possible.
Details

Both formatters keep a field value on the line of its name whenever it fits there, even if it has to be broken. When every layout on that line overflows, for example with a long string literal, rustfmt leaves the line too long, and apfmt moves the value to the next line, block-indented, where it fits. A cast is the exception: it breaks before as on the line of the name, like a binary operator.

Style Guide
Does not settle this.

A long string value#edition 2024

Input
1fn f() {
2 let config = SplitConfig {
3 unified_read_pool_thread_cpu_overload_threshold_ratio: "a very long string literal that doesn't fit",
4 a: 1,
5 };
6}
apfmt c9342b5
1fn f() {
2 let config = SplitConfig {
3 unified_read_pool_thread_cpu_overload_threshold_ratio:
4 "a very long string literal that doesn't fit",
5 a: 1,
6 };
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn f() {
2 let config = SplitConfig {
3 unified_read_pool_thread_cpu_overload_threshold_ratio: "a very long string literal that doesn't fit",
4 a: 1,
5 };
6}

Aligned trailing comments within a width limit #

mediumcommentalignment

Both align trailing comments, but apfmt leaves out items far wider than the rest and aligns in a few cases where rustfmt does not.

Why A single very wide item should not push every comment far to the right. The extra cases follow from having one rule.
Details

Both formatters align the trailing comments of list items on consecutive lines, although the Style Guide asks for a single space. rustfmt aligns them to the widest item, however far right that pushes the comments and even if a line then exceeds max_width.

apfmt leaves out items that are much wider than the others: at most a quarter of the items (or a single item), when more than trailing_comment_align_threshold columns (40 by default) separate them from the rest. It also leaves out lines that alignment would push past max_width. These lines keep a single space.

apfmt also aligns in three cases where rustfmt keeps a single space. Neither choice is clearly better: apfmt has one rule, and rustfmt changes less of the source.

  • Long comments: whether rustfmt aligns depends on the length of the comments. It would align the items in the sample below if their comments were cut short.
  • Rows of filled items: rustfmt never aligns them.
  • After an item with a doc comment or an attribute: rustfmt does not align that item with the next one, even though their code is on consecutive lines.
Style Guide
Follows it: neither

An item much wider than the others#edition 2024

Input
1enum E {
2 A = 1, // a
3 Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = 2, // b
4 Cc = 3, // c
5 D = 4, // d
6}
apfmt c9342b5
1enum E {
2 A = 1, // a
3 Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = 2, // b
4 Cc = 3, // c
5 D = 4, // d
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1enum E {
2 A = 1, // a
3 Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = 2, // b
4 Cc = 3, // c
5 D = 4, // d
6}

Long comments#edition 2024

Input
1fn g() {
2 let x = [
3 ((Direction::Forward, 1usize), (0, 1)), // T|his is a simple alphabetic line
4 ((Direction::Forward, 999usize), (0, 32)), // This is a simple alphabetic line|
5 ];
6}
apfmt c9342b5
1fn g() {
2 let x = [
3 ((Direction::Forward, 1usize), (0, 1)), // T|his is a simple alphabetic line
4 ((Direction::Forward, 999usize), (0, 32)), // This is a simple alphabetic line|
5 ];
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn g() {
2 let x = [
3 ((Direction::Forward, 1usize), (0, 1)), // T|his is a simple alphabetic line
4 ((Direction::Forward, 999usize), (0, 32)), // This is a simple alphabetic line|
5 ];
6}

Rows of filled items#edition 2024

Input
1const A: [u8; 7] = [
2 0, 0, 0, // len
3 4, // kind
4 0, 0, 0, 0, // id
5];
apfmt c9342b5
1const A: [u8; 7] = [
2 0, 0, 0, // len
3 4, // kind
4 0, 0, 0, 0, // id
5];
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1const A: [u8; 7] = [
2 0, 0, 0, // len
3 4, // kind
4 0, 0, 0, 0, // id
5];

After an item with a doc comment#edition 2024

Input
1struct S {
2 /// doc
3 cc: u32, // c
4 dddddddd: Vec<u32>, // d
5}
apfmt c9342b5
1struct S {
2 /// doc
3 cc: u32, // c
4 dddddddd: Vec<u32>, // d
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1struct S {
2 /// doc
3 cc: u32, // c
4 dddddddd: Vec<u32>, // d
5}

Empty blocks are {} #

mediumblockwhitespace

apfmt writes an empty block as {} everywhere; rustfmt splits it over two lines in some places.

Why One rule for every empty block.
Details

apfmt writes an empty block as {} everywhere, including in if-else chains and after a broken signature or a where clause. rustfmt puts { and } on separate lines in those places. The Style Guide does not cover these cases.

Style Guide
Does not settle this.

In an if-else chain#edition 2024

Input
1fn main() {
2 if x {} else {}
3}
apfmt c9342b5
1fn main() {
2 if x {} else {}
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 if x {
3 } else {
4 }
5}

After a where clause#edition 2024

Input
1fn n<T>(a: T) where T: Clone {}
apfmt c9342b5
1fn n<T>(a: T)
2where
3 T: Clone,
4{}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn n<T>(a: T)
2where
3 T: Clone,
4{
5}

After broken parameters#edition 2024

Input
1fn very_long_function_name_with_parameters(first_parameter: u32, second_parameter: &str, third_parameter: u64) {}
2fn generic_where<T>(first_parameter: u32, second_parameter: &str, third_parameter: u64, t: T) where T: Clone {}
apfmt c9342b5
1fn very_long_function_name_with_parameters(
2 first_parameter: u32,
3 second_parameter: &str,
4 third_parameter: u64,
5) {}
6fn generic_where<T>(first_parameter: u32, second_parameter: &str, third_parameter: u64, t: T)
7where
8 T: Clone,
9{}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn very_long_function_name_with_parameters(
2 first_parameter: u32,
3 second_parameter: &str,
4 third_parameter: u64,
5) {
6}
7fn generic_where<T>(first_parameter: u32, second_parameter: &str, third_parameter: u64, t: T)
8where
9 T: Clone,
10{
11}

A long string literal after = moves to the next line #

mediumletstringoverflow

apfmt moves a long string after = to the next line, including raw and wide strings; rustfmt sometimes leaves it overflowing.

Why The string then fits, or overflows by fewer columns.
Details

When the right side of a let, a const or an assignment is a single string literal too long for the line of =, apfmt moves it to the next line, where it fits or overflows by fewer columns. rustfmt leaves it on the line of = when it is a raw string, when its text contains wide characters such as CJK (apfmt measures their display width), or when it does not fit on the next line either.

Style Guide
Does not settle this.

A raw string and a string of wide characters#edition 2024

Input
1fn f() {
2 {
3 let text = r#"{ "version": "1.0.0", "exports": { ".": "./index.js", "./client": "./client.js" } }"#;
4 let text = "コンピュ ータ上で文字を扱う場合、 典型的には文 字による 通信を行 う場合にその両端点では、";
5 }
6}
apfmt c9342b52 lines over 100
1fn f() {
2 {
3 let text =
4 r#"{ "version": "1.0.0", "exports": { ".": "./index.js", "./client": "./client.js" } }"#;
5 let text =
6 "コンピュ ータ上で文字を扱う場合、 典型的には文 字による 通信を行 う場合にその両端点では、";
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)2 lines over 100
1fn f() {
2 {
3 let text = r#"{ "version": "1.0.0", "exports": { ".": "./index.js", "./client": "./client.js" } }"#;
4 let text = "コンピュ ータ上で文字を扱う場合、 典型的には文 字による 通信を行 う場合にその両端点では、";
5 }
6}

Only struct variants decide the layout of struct variants #

mediumenum

apfmt applies the Style Guide rule to all struct variants and only to them; rustfmt also reacts to tuple variants and skips some struct variants.

Why This is the Style Guide rule, without rustfmt's two extensions to it.
Details

The Style Guide says: "In an enum with multiple struct variants, if any struct variant is written on multiple lines, use the multi-line formatting for all struct variants." apfmt applies this to every struct variant and to struct variants only. rustfmt differs in two ways:

  • It also breaks all struct variants when a *tuple* variant is multi-line.
  • It leaves out variants with an attribute or a doc comment, which stay on one line next to a multi-line struct variant.
Style Guide
Follows it: apfmt
In an enum with multiple struct variants, if any struct variant is written on multiple lines, use the multi-line formatting for all struct variants.

A broken tuple variant#edition 2024

Input
1enum BrokenTupleVariant {
2 A { x: u32 },
3 B(FirstFieldTypeName, SecondFieldTypeName, ThirdFieldTypeNameXX),
4}
apfmt c9342b5
1enum BrokenTupleVariant {
2 A { x: u32 },
3 B(
4 FirstFieldTypeName,
5 SecondFieldTypeName,
6 ThirdFieldTypeNameXX,
7 ),
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1enum BrokenTupleVariant {
2 A {
3 x: u32,
4 },
5 B(
6 FirstFieldTypeName,
7 SecondFieldTypeName,
8 ThirdFieldTypeNameXX,
9 ),
10}

A struct variant with an attribute#edition 2024

Input
1enum WithAttr {
2 #[error("x")]
3 A { x: u32 },
4 B { msg: String, help: String, aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32, bbbbbbbbbbbbbbbbbbbbbbbb: u32 },
5}
apfmt c9342b5
1enum WithAttr {
2 #[error("x")]
3 A {
4 x: u32,
5 },
6 B {
7 msg: String,
8 help: String,
9 aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32,
10 bbbbbbbbbbbbbbbbbbbbbbbb: u32,
11 },
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1enum WithAttr {
2 #[error("x")]
3 A { x: u32 },
4 B {
5 msg: String,
6 help: String,
7 aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32,
8 bbbbbbbbbbbbbbbbbbbbbbbb: u32,
9 },
10}

A struct variant with a doc comment#edition 2024

Input
1enum WithDoc {
2 /// doc
3 A { x: u32 },
4 B { msg: String, help: String, aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32, bbbbbbbbbbbbbbbbbbbbbbbb: u32 },
5}
apfmt c9342b5
1enum WithDoc {
2 /// doc
3 A {
4 x: u32,
5 },
6 B {
7 msg: String,
8 help: String,
9 aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32,
10 bbbbbbbbbbbbbbbbbbbbbbbb: u32,
11 },
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1enum WithDoc {
2 /// doc
3 A { x: u32 },
4 B {
5 msg: String,
6 help: String,
7 aaaaaaaaaaaaaaaaaaaaaaaaaaa: u32,
8 bbbbbbbbbbbbbbbbbbbbbbbb: u32,
9 },
10}

A closure or a control-flow argument is hugged whatever the width of its head #

mediumcallclosurehugging

apfmt hugs a single closure or control-flow argument whenever its first line fits; rustfmt also looks at how wide its head is.

Why A longer head then never takes fewer lines than a shorter one.
Details

A single closure argument hugs the call whenever its first line fits within max_width. rustfmt puts the closure on its own line when its head is wide. The same applies to a single if, match, while or for argument with a long head, which rustfmt hugs only when the first line is within fn_call_width.

Style Guide
Does not settle this.

A closure with a wide head#edition 2024

Input
1fn f() {
2 Box::new(move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
3 a;
4 });
5}
apfmt c9342b5
1fn f() {
2 Box::new(move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
3 a;
4 });
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 Box::new(
3 move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
4 a;
5 },
6 );
7}

A while with a long head#edition 2024

Input
1fn main() {
2 h(while condition_that_is_rather_long(first_argument, second_argument).is_some_and(|x| x > 0) {
3 y();
4 });
5}
apfmt c9342b5
1fn main() {
2 h(while condition_that_is_rather_long(first_argument, second_argument).is_some_and(|x| x > 0) {
3 y();
4 });
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 h(
3 while condition_that_is_rather_long(first_argument, second_argument).is_some_and(|x| x > 0)
4 {
5 y();
6 },
7 );
8}

A broken struct pattern has one field per line #

mediumpatternstruct

apfmt puts each field of a broken struct pattern on its own line; rustfmt can put all fields on one indented line.

Why The Style Guide formats patterns like the corresponding expressions.
Details

The Style Guide formats patterns like the corresponding expressions, so a struct pattern that does not fit within struct_lit_width has one field per line, with .. last and no comma. rustfmt puts all the fields on one indented line when they fit within struct_lit_width without .. but not with , .. added. With more fields, it also uses one per line.

Style Guide
Follows it: apfmt

Fields that fit only without , ..#edition 2024

Input
1fn main() {
2 let S { aaaaa, bbbbbbbbb, .. } = x;
3}
apfmt c9342b5
1fn main() {
2 let S {
3 aaaaa,
4 bbbbbbbbb,
5 ..
6 } = x;
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let S {
3 aaaaa, bbbbbbbbb, ..
4 } = x;
5}

A long argument of a chain element moves to its own line #

mediumchainoverflow

apfmt moves an unbreakable argument of a chain element to its own line even if it still overflows there; rustfmt leaves the element on one line.

Why It overflows by fewer columns, as with a long string after =.
Details

A single argument that cannot break and does not fit on the line of a chain element moves to its own line, even when it overflows there too, because it then overflows by fewer columns. rustfmt leaves the element on one line when the argument does not fit on its own line either.

Style Guide
Does not settle this.
Related
A long string literal after = moves to the next line

A long string argument#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 let a = cmd
6 .hide_default_value(true)
7 .help("Specify when to use the pager, or use `-P` to disable (*auto*, never, always).")
8 .long_help("short");
9 }
10 }
11 }
12}
apfmt c9342b51 line over 100
1fn main() {
2 {
3 {
4 {
5 let a = cmd
6 .hide_default_value(true)
7 .help(
8 "Specify when to use the pager, or use `-P` to disable (*auto*, never, always).",
9 )
10 .long_help("short");
11 }
12 }
13 }
14}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn main() {
2 {
3 {
4 {
5 let a = cmd
6 .hide_default_value(true)
7 .help("Specify when to use the pager, or use `-P` to disable (*auto*, never, always).")
8 .long_help("short");
9 }
10 }
11 }
12}

A short chain is broken before . to keep its arguments on one line #

mediumchain

apfmt breaks a short chain before . to keep its arguments on one line; rustfmt keeps the chain on one line and breaks the arguments.

Why It takes fewer lines, and the Style Guide prefers each element on one line. Neither layout is clearly better.
Details

When breaking a chain before each element lets every element fit on one line, apfmt prefers that to keeping the chain on one line with the arguments of its last element one per line, even with a single element. A receiver followed by .method(a, b, c); takes two lines where rustfmt takes five.

The Style Guide breaks a chain that does not fit before each element and prefers each element on one line. rustfmt keeps such a short chain on one line and breaks the arguments of its last element. In the head of a control-flow expression, { then goes on its own line.

Style Guide
Follows it: apfmt

A statement#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 columnar_writer.record_column_type(field_entry.name(), column_type, sort_values_within_row);
6 document_tokenizer.tokenize_document(current_document, &mut should_tokenize, &mut token_fn)?;
7 }
8 }
9 }
10}
apfmt c9342b5
1fn main() {
2 {
3 {
4 {
5 columnar_writer
6 .record_column_type(field_entry.name(), column_type, sort_values_within_row);
7 document_tokenizer
8 .tokenize_document(current_document, &mut should_tokenize, &mut token_fn)?;
9 }
10 }
11 }
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 columnar_writer.record_column_type(
6 field_entry.name(),
7 column_type,
8 sort_values_within_row,
9 );
10 document_tokenizer.tokenize_document(
11 current_document,
12 &mut should_tokenize,
13 &mut token_fn,
14 )?;
15 }
16 }
17 }
18}

In a match head#edition 2024

Input
1fn main() {
2 {
3 {
4 match self.pending_notify.compare_exchange_weak(n, n - 1, Ordering::SeqCst, Ordering::SeqCst) {
5 Ok(_) => return,
6 Err(x) => n = x,
7 }
8 }
9 }
10}
apfmt c9342b5
1fn main() {
2 {
3 {
4 match self
5 .pending_notify
6 .compare_exchange_weak(n, n - 1, Ordering::SeqCst, Ordering::SeqCst)
7 {
8 Ok(_) => return,
9 Err(x) => n = x,
10 }
11 }
12 }
13}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 match self.pending_notify.compare_exchange_weak(
5 n,
6 n - 1,
7 Ordering::SeqCst,
8 Ordering::SeqCst,
9 ) {
10 Ok(_) => return,
11 Err(x) => n = x,
12 }
13 }
14 }
15}

Blank lines at the start and end of a module or extern block are removed #

mediummoduleblank-lines

apfmt removes blank lines at the start and end of every body; rustfmt keeps some in inline modules and extern blocks.

Why One rule for all bodies.
Details

apfmt removes blank lines after { and before } of every body of items or statements. rustfmt does the same for functions, impls and traits, but keeps the blank lines after { of an inline module and at both ends of an extern block. The Style Guide does not cover them.

Bodyrustfmt after {rustfmt before }apfmt
fn, impl, traitremovedremovedremoved
mod m { ... }keptremovedremoved
extern "C" { ... }keptkeptremoved
Style Guide
Does not settle this.

An inline module#edition 2024

Input
1mod m {
2
3 use x;
4
5 fn f() {}
6
7}
apfmt c9342b5
1mod m {
2 use x;
3
4 fn f() {}
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1mod m {
2
3 use x;
4
5 fn f() {}
6}

An extern block#edition 2024

Input
1extern "C" {
2
3 fn g();
4
5}
apfmt c9342b5
1extern "C" {
2 fn g();
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1extern "C" {
2
3 fn g();
4
5}

Code after a comment continues on an indented line #

mediumcomment

apfmt puts code that continues after a comment on an indented line; rustfmt often leaves such a statement as written.

Why It is a continuation like any other.
Details

apfmt treats code that continues after a comment like any other continuation line and indents it. rustfmt usually leaves such a statement as written, so the comment and the code stay in their original columns.

Style Guide
Does not settle this.

=> after a trailing comment on a pattern#edition 2024

rustfmt puts => at the indentation of the pattern. apfmt puts it on an indented line. The Style Guide has no rule for this.

Input
1fn main() {
2 match c {
3 'a' // first
4 => 1,
5 }
6}
apfmt c9342b5
1fn main() {
2 match c {
3 'a' // first
4 => 1,
5 }
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 match c {
3 'a' // first
4 => 1,
5 }
6}

An own-line comment after =#edition 2024

rustfmt leaves the statement as written. apfmt indents the comment and the right side like code. Both format a const the same way.

Input
1fn f() {
2 let x =
3 // c
4 y;
5}
apfmt c9342b5
1fn f() {
2 let x =
3 // c
4 y;
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let x =
3 // c
4 y;
5}

A trailing line comment inside an expression#edition 2024

rustfmt leaves the rest of the expression at its columns in the source. apfmt puts it on an indented continuation line.

Input
1fn main() {
2 let x = a // c
3 + b;
4}
apfmt c9342b5
1fn main() {
2 let x = a // c
3 + b;
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let x = a // c
3 + b;
4}

Own-line comment inside an expression#edition 2024

rustfmt continues the expression at the indentation of the statement. apfmt continues it on an indented line.

Input
1fn main() {
2 f
3 // explain the call
4 (1, 2);
5 g
6 /* block */
7 (3);
8}
apfmt c9342b5
1fn main() {
2 f
3 // explain the call
4 (1, 2);
5 g
6 /* block */(3);
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 f
3 // explain the call
4 (1, 2);
5 g
6 /* block */
7 (3);
8}

A comment after the keyword of a control-flow head#edition 2024

rustfmt moves the comment to its own line at the indentation of the keyword, with { after the head. apfmt keeps the comment after the keyword and puts the head on an indented line and { on its own line, as the Style Guide asks for any broken control line.

Input
1fn main() {
2 if
3 // c
4 a {
5 x();
6 }
7}
apfmt c9342b5
1fn main() {
2 if
3 // c
4 a
5 {
6 x();
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 if
3 // c
4 a {
5 x();
6 }
7}

A comment after the = of a let-else#edition 2024

rustfmt leaves the statement as written. apfmt puts the initializer on an indented line and else { on its own line, as the Style Guide asks after any initializer moved to the next line.

Input
1fn main() {
2 let Some(x) = // c
3 a else {
4 return;
5 };
6}
apfmt c9342b5
1fn main() {
2 let Some(x) = // c
3 a
4 else {
5 return;
6 };
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let Some(x) = // c
3 a else {
4 return;
5 };
6}

where of an impl with an empty body is on its own line #

mediumwhereimpl

apfmt puts where on its own line even when the impl body is empty; rustfmt keeps a short impl and its where on one line.

Why apfmt follows the Style Guide's rule for where over its separate request for an empty impl on one line.
Details

The Style Guide puts where on its own line. With an empty body, rustfmt keeps a short impl and its where on one line (impl<I> A for B<I> where I: C {}). On a header that fills the line, it leaves where at the end of the line and drops the trailing comma of the predicate.

The Style Guide also asks for an empty impl to be on one line, so it contradicts itself here.

Style Guide
Follows it: apfmt

A short impl#edition 2024

Input
1impl<I> A for B<I> where I: C {}
apfmt c9342b5
1impl<I> A for B<I>
2where
3 I: C,
4{}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1impl<I> A for B<I> where I: C {}

A header that fills the line#edition 2024

Input
1impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V> where T: Copy {}
2impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V> where T: Copy {
3 fn f() {}
4}
apfmt c9342b5
1impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V>
2where
3 T: Copy,
4{}
5impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V>
6where
7 T: Copy,
8{
9 fn f() {}
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V> where
2 T: Copy
3{
4}
5impl<T: Clone> SomeVeryLongTraitNameForTesting<WithGenerics> for AnotherVeryLongTypeName<T, U, V>
6where
7 T: Copy,
8{
9 fn f() {}
10}

The right side of = moves to the next line by the lines it saves #

mediumlet

apfmt moves the right side of = to the next line only when that saves enough lines; rustfmt moves it for any saved line or because of how its first line ends.

Why Moving for every saved line would make apfmt differ from rustfmt more often, and rustfmt's first-line rule can take more lines.
Details

When the right side of a let, an assignment or a let-else is broken on the line of =, apfmt moves it to the next line (block-indented) only when that saves at least two lines. One saved line is enough for two shapes: a chain that is on one line except for the arguments of its last element, and a call whose single argument hugs it. rustfmt moves the right side whenever the next line saves one line. In a few statements, rustfmt's result is therefore one line shorter.

rustfmt also moves the right side when its first line on the line of = ends with (, { or [ and on the next line does not, however many lines it takes there. apfmt goes only by the number of lines. rustfmt's rule can cost lines: on the next line, a chain that no longer fits on one line is broken before every element.

A broken match or if head on the line of = stays there in apfmt when moving it saves no line. rustfmt moves it because its first line ends with (.

Style Guide
Does not settle this.

Moves only when it saves two lines#edition 2024

Input
1fn main() {
2 {
3 let quoted = (contents.len() >= 3 && contents.starts_with(b"$\"") && contents.ends_with(b"\"")) || is_quoted(contents);
4 {
5 let (key_uuid, search_rules) = match ActionPolicy::<A>::authenticate_tenant_token(&auth, token) {
6 Ok(TenantTokenOutcome::Valid(key_uuid, search_rules)) => (key_uuid, Some(search_rules)),
7 Ok(TenantTokenOutcome::NotATenantToken) | Err(AuthError::InvalidTenantToken) => (
8 auth.get_optional_uid_from_encoded_key(token.as_bytes()).map_err(|_e| AuthError::InvalidApiKey)?.ok_or(AuthError::InvalidApiKey)?,
9 None,
10 ),
11 Err(e) => return Err(e),
12 };
13 }
14 }
15}
apfmt c9342b5
1fn main() {
2 {
3 let quoted = (contents.len() >= 3
4 && contents.starts_with(b"$\"")
5 && contents.ends_with(b"\""))
6 || is_quoted(contents);
7 {
8 let (key_uuid, search_rules) = match ActionPolicy::<A>::authenticate_tenant_token(
9 &auth, token,
10 ) {
11 Ok(TenantTokenOutcome::Valid(key_uuid, search_rules)) => {
12 (key_uuid, Some(search_rules))
13 }
14 Ok(TenantTokenOutcome::NotATenantToken) | Err(AuthError::InvalidTenantToken) => (
15 auth.get_optional_uid_from_encoded_key(token.as_bytes())
16 .map_err(|_e| AuthError::InvalidApiKey)?
17 .ok_or(AuthError::InvalidApiKey)?,
18 None,
19 ),
20 Err(e) => return Err(e),
21 };
22 }
23 }
24}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 let quoted =
4 (contents.len() >= 3 && contents.starts_with(b"$\"") && contents.ends_with(b"\""))
5 || is_quoted(contents);
6 {
7 let (key_uuid, search_rules) =
8 match ActionPolicy::<A>::authenticate_tenant_token(&auth, token) {
9 Ok(TenantTokenOutcome::Valid(key_uuid, search_rules)) => {
10 (key_uuid, Some(search_rules))
11 }
12 Ok(TenantTokenOutcome::NotATenantToken)
13 | Err(AuthError::InvalidTenantToken) => (
14 auth.get_optional_uid_from_encoded_key(token.as_bytes())
15 .map_err(|_e| AuthError::InvalidApiKey)?
16 .ok_or(AuthError::InvalidApiKey)?,
17 None,
18 ),
19 Err(e) => return Err(e),
20 };
21 }
22 }
23}

A first line ending with an opening delimiter#edition 2024

Input
1fn f() {
2 {
3 let specifier_len = u32::from_le_bytes(buffer[specifier_end_pos..source_hash_start_pos].try_into()?) as usize;
4 req.data = self.handle_data.request_callbacks.borrow_mut().insert(RequestCallbackState::Write(WriteRequestCallbackState {
5 isolate: unsafe { scope.as_raw_isolate_ptr() },
6 req_wrap_obj: v8::Global::new(scope, req_wrap_obj),
7 stream_handle,
8 }));
9 }
10}
apfmt c9342b5
1fn f() {
2 {
3 let specifier_len = u32::from_le_bytes(
4 buffer[specifier_end_pos..source_hash_start_pos].try_into()?,
5 ) as usize;
6 req.data = self.handle_data.request_callbacks.borrow_mut().insert(
7 RequestCallbackState::Write(WriteRequestCallbackState {
8 isolate: unsafe { scope.as_raw_isolate_ptr() },
9 req_wrap_obj: v8::Global::new(scope, req_wrap_obj),
10 stream_handle,
11 }),
12 );
13 }
14}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 let specifier_len =
4 u32::from_le_bytes(buffer[specifier_end_pos..source_hash_start_pos].try_into()?)
5 as usize;
6 req.data =
7 self.handle_data
8 .request_callbacks
9 .borrow_mut()
10 .insert(RequestCallbackState::Write(WriteRequestCallbackState {
11 isolate: unsafe { scope.as_raw_isolate_ptr() },
12 req_wrap_obj: v8::Global::new(scope, req_wrap_obj),
13 stream_handle,
14 }));
15 }
16}

Comments after an opening delimiter stay on its line #

mediumcomment

apfmt keeps a comment that ends the line of an opening delimiter on that line; rustfmt moves it to the next line.

Why The comment stays where its author put it.
Details

A comment that ends the line of (, { or [ stays there, after a space. If the line would then exceed max_width, the comment moves to the first line of the body. rustfmt moves such a comment to the next line.

A block comment followed by code on the line of the opening delimiter does not end the line. apfmt keeps it in front of that code, while rustfmt puts the comment and the code on separate lines. The same rule holds for blocks and broken lists.

Style Guide
Does not settle this.

After the brace of a function#edition 2024

Input
1fn short() { // Fits on the line with the brace
2 call();
3}
apfmt c9342b5
1fn short() { // Fits on the line with the brace
2 call();
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn short() {
2 // Fits on the line with the brace
3 call();
4}

After the brace of a struct#edition 2024

Input
1struct A { // comment on the brace line
2 a: u32,
3}
apfmt c9342b5
1struct A { // comment on the brace line
2 a: u32,
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1struct A {
2 // comment on the brace line
3 a: u32,
4}

A block comment followed by code#edition 2024

Input
1fn main() {
2 let a = if x { /* c */ 1 } else { 2 };
3}
apfmt c9342b5
1fn main() {
2 let a = if x {
3 /* c */ 1
4 } else {
5 2
6 };
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let a = if x {
3 /* c */
4 1
5 } else {
6 2
7 };
8}

After an opening parenthesis#edition 2024

Input
1fn main() {
2 let z = ( // c
3 b && c
4 );
5}
apfmt c9342b5
1fn main() {
2 let z = ( // c
3 b && c
4 );
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let z = (
3 // c
4 b && c
5 );
6}

Multi-line block comments keep their columns #

mediumcomment

apfmt keeps the relative columns of a multi-line block comment when it moves; rustfmt reindents its lines.

Why The text of the comment keeps its shape, such as aligned lines.
Details

When a multi-line block comment moves, apfmt keeps the columns of its lines relative to its start. rustfmt reindents every line to the indentation of the code. apfmt prints a comment unchanged if one of its lines is indented less than the start of the comment or with a tab, because the relative columns cannot be kept.

Style Guide
Does not settle this.

An aligned comment#edition 2024

Input
1fn f() {
2 let x = 10; /* a
3 a
4 a */
5}
apfmt c9342b5
1fn f() {
2 let x = 10; /* a
3 a
4 a */
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let x = 10; /* a
3 a
4 a */
5}

Comments that move left#edition 2024

Input
1fn f() {
2 x();/* a
3
4 b
5 */
6 y(); /* c
7 d */
8}
apfmt c9342b5
1fn f() {
2 x(); /* a
3
4 b
5 */
6 y(); /* c
7 d */
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 x(); /* a
3····
4
5 b
6 */
7 y(); /* c
8 d */
9}

A line indented less than the start#edition 2024

Input
1fn f() {
2 f(); /* a
3b */
4 g();
5}
apfmt c9342b5
1fn f() {
2 f(); /* a
3b */
4 g();
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 f(); /* a
3 b */
4 g();
5}

A short chain stays on one line with the arguments of its last element broken #

mediumchain

apfmt may keep a short chain on one line with its last argument on its own line; rustfmt breaks before every element and hugs the argument.

Why It takes fewer lines, while rustfmt's elements are easier to scan. Neither layout is clearly better.
Details

When a chain whose last argument is a call does not fit, apfmt may keep the chain on one line and put the argument on its own line. rustfmt breaks before every element and hugs the argument.

Style Guide
Does not settle this.

A call as the last argument#edition 2024

Input
1fn f() {
2 {
3 {
4 SCHED_PROCESSING_READ_HISTOGRAM_STATIC.get(CMD).observe(duration_to_sec(now.saturating_duration_since(begin_instant)));
5 }
6 }
7}
apfmt c9342b5
1fn f() {
2 {
3 {
4 SCHED_PROCESSING_READ_HISTOGRAM_STATIC.get(CMD).observe(
5 duration_to_sec(now.saturating_duration_since(begin_instant)),
6 );
7 }
8 }
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 {
4 SCHED_PROCESSING_READ_HISTOGRAM_STATIC
5 .get(CMD)
6 .observe(duration_to_sec(
7 now.saturating_duration_since(begin_instant),
8 ));
9 }
10 }
11}

A single call argument wider than fn_call_width goes on its own line #

mediumcallhuggingwidth

In apfmt, a breakable single argument wider than fn_call_width is never on one line in the call; rustfmt allows that if the call fits within max_width.

Why A longer argument then never takes fewer lines than a shorter one.
Details

A single call argument that can break and is wider than fn_call_width is not kept on one line in the call, even where it would fit. apfmt hugs it if its first line (inner() is within fn_call_width, and otherwise puts it on its own line. rustfmt hugs under the same condition, but otherwise puts the whole call on one line if it fits within max_width. As a result, a longer function name can take fewer lines than a shorter one.

An argument that cannot break at all, such as a::B::new(), stays on one line within max_width in both formatters.

Style Guide
Does not settle this.

Growing arguments#edition 2024

Input
1fn main() {
2 outer(pppppppppppppppppppppppppppppppppppppppp::new(b, c));
3 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppp::new(
4 b, c,
5 ));
6 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c));
7 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c));
8}
apfmt c9342b5
1fn main() {
2 outer(pppppppppppppppppppppppppppppppppppppppp::new(b, c));
3 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppp::new(
4 b, c,
5 ));
6 outer(
7 pppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c),
8 );
9 outer(
10 pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c),
11 );
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 outer(pppppppppppppppppppppppppppppppppppppppp::new(b, c));
3 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppp::new(
4 b, c,
5 ));
6 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c));
7 outer(pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp::new(b, c));
8}

A chain with a hugged last argument stays on the line of = #

mediumchainlethugging

When a chain hugging its last argument does not fit on the line of =, apfmt breaks before the element; rustfmt moves the chain to the next line or breaks the arguments.

Why Both layouts take as many lines. Neither is clearly better.
Details

When a chain that hugs its last argument does not fit on the line of =, apfmt breaks it before the element, which takes as many lines as moving it to the next line. rustfmt moves it to the next line or breaks its arguments.

Style Guide
Does not settle this.

A struct literal as the hugged argument#edition 2024

Input
1fn f() {
2 {
3 {
4 {
5 let _ = mouse_click_tx.try_send(deno_runtime::ops::desktop::DesktopEvent::MouseClick { x, y, button, modifiers, aaaaaaa });
6 }
7 }
8 }
9}
apfmt c9342b5
1fn f() {
2 {
3 {
4 {
5 let _ = mouse_click_tx
6 .try_send(deno_runtime::ops::desktop::DesktopEvent::MouseClick {
7 x,
8 y,
9 button,
10 modifiers,
11 aaaaaaa,
12 });
13 }
14 }
15 }
16}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 {
4 {
5 let _ =
6 mouse_click_tx.try_send(deno_runtime::ops::desktop::DesktopEvent::MouseClick {
7 x,
8 y,
9 button,
10 modifiers,
11 aaaaaaa,
12 });
13 }
14 }
15 }
16}

A closure gets braces to hug the call #

mediumclosurecallhugging

apfmt gives a closure braces so that it can hug the call; rustfmt puts the arguments one per line and keeps the closure without braces.

Why The body is indented one level less, though the Style Guide prefers a closure without {}. Neither layout is clearly better.
Details

When a closure argument without braces does not fit on the line of the call, apfmt adds braces and hugs it. rustfmt puts the arguments one per line and leaves the closure without braces. Both take about the same number of lines.

Style Guide
Follows it: rustfmt

A closure in a call in an array#edition 2024

Input
1fn f() {
2 let columns = [ui::PickerColumn::new("template", |item: &DebugTemplate, _| item.name.as_str().into())];
3}
apfmt c9342b5
1fn f() {
2 let columns = [ui::PickerColumn::new("template", |item: &DebugTemplate, _| {
3 item.name.as_str().into()
4 })];
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let columns = [ui::PickerColumn::new(
3 "template",
4 |item: &DebugTemplate, _| item.name.as_str().into(),
5 )];
6}

A chain as a match arm body stays on the line of => #

mediumchainmatch

apfmt breaks a chain in a match arm body on the line of =>; rustfmt may put it in a block instead.

Why apfmt avoids the block, at the cost of one more line.
Details

A chain that does not fit on the line of => is broken before its elements there. rustfmt also considers a block with the chain on one line, and prefers it in cases like the sample below. apfmt has no block and takes one more line. The Style Guide does not rank the two.

Style Guide
Does not settle this.

A chain ending with a hugged closure#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 match &local_branch.details {
9 BranchDetails::Local(details) => details.upstream.as_ref().is_some_and(|upstream| {
10 upstream.reference == remote_branch.reference
11 }),
12 BranchDetails::Remote(_) => false,
13 };
14 }
15 }
16 }
17 }
18 }
19 }
20}
apfmt c9342b5
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 match &local_branch.details {
9 BranchDetails::Local(details) => details
10 .upstream
11 .as_ref()
12 .is_some_and(|upstream| {
13 upstream.reference == remote_branch.reference
14 }),
15 BranchDetails::Remote(_) => false,
16 };
17 }
18 }
19 }
20 }
21 }
22 }
23}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 {
6 {
7 {
8 match &local_branch.details {
9 BranchDetails::Local(details) => {
10 details.upstream.as_ref().is_some_and(|upstream| {
11 upstream.reference == remote_branch.reference
12 })
13 }
14 BranchDetails::Remote(_) => false,
15 };
16 }
17 }
18 }
19 }
20 }
21 }
22}

A chain argument is hugged only with its elements attached #

mediumchaincallhugging

apfmt hugs a chain argument only if its elements stay attached to the call; rustfmt may start an element at the indentation of the statement.

Why An element at the indentation of the statement would look as if it applied to the statement.
Details

rustfmt also hugs a single chain argument when the chain breaks before an element, so that element starts at the indentation of the statement, as if it applied to the statement. apfmt hugs a chain only if its elements are on the line of (, where only the arguments of the last one may break, or if a single element follows the closing delimiter of a broken root ().into()), ).await?)). The Style Guide also joins the next element to the closing line of a multi-line root. Otherwise the argument goes on its own line.

Style Guide
Follows it: apfmt

A broken root with a single element#edition 2024

Input
1fn main() {
2 if !output.status.success() {
3 return Err(format!(
4 "rocm-smi exited with error code {}\nStdout: {stdout}\nStderr: {stderr}",
5 output.status
6 )
7 .into());
8 }
9}
apfmt c9342b5
1fn main() {
2 if !output.status.success() {
3 return Err(format!(
4 "rocm-smi exited with error code {}\nStdout: {stdout}\nStderr: {stderr}",
5 output.status
6 ).into());
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 if !output.status.success() {
3 return Err(format!(
4 "rocm-smi exited with error code {}\nStdout: {stdout}\nStderr: {stderr}",
5 output.status
6 )
7 .into());
8 }
9}

Later elements with arguments#edition 2024

Input
1fn main() {
2 let repo_path = match absolute_path.canonicalize() {
3 Ok(p) => p,
4 Err(e) => {
5 return Err(LabeledError::new(format!(
6 "error canonicalizing [{}]",
7 absolute_path.display()
8 ))
9 .with_label(e.to_string(), path.span));
10 }
11 };
12}
apfmt c9342b5
1fn main() {
2 let repo_path = match absolute_path.canonicalize() {
3 Ok(p) => p,
4 Err(e) => {
5 return Err(LabeledError::new(
6 format!("error canonicalizing [{}]", absolute_path.display()),
7 ).with_label(e.to_string(), path.span));
8 }
9 };
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let repo_path = match absolute_path.canonicalize() {
3 Ok(p) => p,
4 Err(e) => {
5 return Err(LabeledError::new(format!(
6 "error canonicalizing [{}]",
7 absolute_path.display()
8 ))
9 .with_label(e.to_string(), path.span));
10 }
11 };
12}

A chain broken before its elements on the line of = stays there #

mediumchainlet

apfmt keeps a chain broken before its elements on the line of =, even where the next line would save one line; rustfmt moves it.

Why apfmt prefers breaking a chain before its elements to breaking its last arguments. In rare cases this costs a line.
Details

When the right side of a let or an assignment is a chain whose elements each fit on a line when it is broken on the line of =, apfmt keeps it there. One level deeper, on the next line, the last element no longer fits on a line, so the chain would have to stay on one line with its last arguments broken. rustfmt compares the number of lines and moves the chain when that saves one.

Style Guide
Does not settle this.

The next line would save one line#edition 2024

Input
1fn main() {
2 {
3 {
4 let items = fields.unnamed.iter().zip(accessor).map(|(_, accessor)| quote!(nu_protocol::IntoValue::into_value(#accessor, span)));
5 {
6 {
7 {
8 {
9 _ = sender.sender.take().unwrap().send(exception_to_err_result(tc_scope, exception, true, false));
10 }
11 }
12 }
13 }
14 }
15 }
16}
apfmt c9342b5
1fn main() {
2 {
3 {
4 let items = fields
5 .unnamed
6 .iter()
7 .zip(accessor)
8 .map(|(_, accessor)| quote!(nu_protocol::IntoValue::into_value(#accessor, span)));
9 {
10 {
11 {
12 {
13 _ = sender
14 .sender
15 .take()
16 .unwrap()
17 .send(exception_to_err_result(tc_scope, exception, true, false));
18 }
19 }
20 }
21 }
22 }
23 }
24}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 let items =
5 fields.unnamed.iter().zip(accessor).map(
6 |(_, accessor)| quote!(nu_protocol::IntoValue::into_value(#accessor, span)),
7 );
8 {
9 {
10 {
11 {
12 _ =
13 sender.sender.take().unwrap().send(exception_to_err_result(
14 tc_scope, exception, true, false,
15 ));
16 }
17 }
18 }
19 }
20 }
21 }
22}

A chain ending with ? after = goes on one line on the next line #

mediumchainlet

apfmt moves a single-element chain ending with ? to one line after =; rustfmt breaks it before the element.

Why The Style Guide puts one line on the next line ahead of a layout broken on the line of =.
Details

A right side that is a single-element chain ending with ? (a.b(…)?) and fits on one line on the next line goes there, following the order of layouts the Style Guide gives for let. rustfmt counts the ? as a chain element, so chain_width (60 by default) limits the chain on one line, and rustfmt breaks it before the element on the line of =. Without the ?, rustfmt also moves it to the next line. Both results take two lines.

Style Guide
Follows it: apfmt

Single-element chains#edition 2024

Input
1fn f() {
2 {
3 {
4 let embedder_id = find_free_index().ok_or(crate::UserError::TooManyEmbedders(total_embedder_count))?;
5 }
6 let block_postings = inverted_index.read_block_postings_from_terminfo(&term_info, IndexRecordOption::Basic)?;
7 let predefined_acl = parse_predefined_acl(&input.predefined_acl).or_invalid_input("invalid predefined_acl")?;
8 }
9}
apfmt c9342b5
1fn f() {
2 {
3 {
4 let embedder_id =
5 find_free_index().ok_or(crate::UserError::TooManyEmbedders(total_embedder_count))?;
6 }
7 let block_postings =
8 inverted_index.read_block_postings_from_terminfo(&term_info, IndexRecordOption::Basic)?;
9 let predefined_acl =
10 parse_predefined_acl(&input.predefined_acl).or_invalid_input("invalid predefined_acl")?;
11 }
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 {
4 let embedder_id = find_free_index()
5 .ok_or(crate::UserError::TooManyEmbedders(total_embedder_count))?;
6 }
7 let block_postings = inverted_index
8 .read_block_postings_from_terminfo(&term_info, IndexRecordOption::Basic)?;
9 let predefined_acl = parse_predefined_acl(&input.predefined_acl)
10 .or_invalid_input("invalid predefined_acl")?;
11 }
12}

{ match ... } as a closure body keeps its braces where the head does not fit #

mediumclosurematch

apfmt and rustfmt differ on when the braces around a closure's match body are removed.

Why Removing the braces would save a level of indentation but split the match line. The Style Guide prefers no braces: rustfmt follows it in the first case and apfmt in the second.
Details

"Use closures without the enclosing {}, if possible" (Style Guide). match is not a control-flow expression for this rule, so both formatters remove the braces of |x| { match x { ... } }. They differ in these cases:

  • When |x| match head { does not fit on one line, apfmt keeps the braces, and breaks the head inside them if it does not fit there either. rustfmt removes them and breaks the head. A closure without braces in the source stays without them in both.
  • With a comment inside the match, rustfmt keeps the braces, and apfmt removes them.
  • In nested blocks { { x } } with a long body or after broken parameters, apfmt removes the outer braces, and rustfmt keeps them.
Style Guide
Follows it: rustfmt
Use closures without the enclosing {}, if possible

A head that does not fit with |x| match#edition 2024

Input
1fn main() {
2{
3{
4{
5let closure = |opt_str, opt_path| { match self.field.compute(opt_str).unwrap_or_default() {
6Some(a) => { polars_err!(ComputeError: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", e) }
7_ => Ok(None),
8} };
9}
10}
11}
12}
apfmt c9342b51 line over 100
1fn main() {
2 {
3 {
4 {
5 let closure = |opt_str, opt_path| {
6 match self.field.compute(opt_str).unwrap_or_default() {
7 Some(a) => {
8 polars_err!(ComputeError: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", e)
9 }
10 _ => Ok(None),
11 }
12 };
13 }
14 }
15 }
16}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 let closure = |opt_str, opt_path| match self
6 .field
7 .compute(opt_str)
8 .unwrap_or_default()
9 {
10 Some(a) => {
11 polars_err!(ComputeError: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", e)
12 }
13 _ => Ok(None),
14 };
15 }
16 }
17 }
18}

A comment inside the match#edition 2024

Input
1fn main() {
2 let f = |x| {
3 match x {
4 // c
5 A => 1,
6 }
7 };
8}
apfmt c9342b5
1fn main() {
2 let f = |x| match x {
3 // c
4 A => 1,
5 };
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let f = |x| {
3 match x {
4 // c
5 A => 1,
6 }
7 };
8}

Nested blocks#edition 2024

Input
1fn f() {
2 let c = |x| { { x } };
3 let c = |x| { { { x } } };
4 let c = |x| { { g(); x } };
5 let c = |x| { { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccc) } };
6 let c = |x| -> u8 { { x } };
7 let c = |x| { unsafe { x } };
8 let c = |x| { { m! {} } };
9 let c = |x| { { x } // c
10 };
11 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { { x } };
12 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { { g(); x } };
13 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { x };
14}
apfmt c9342b5
1fn f() {
2 let c = |x| x;
3 let c = |x| x;
4 let c = |x| {
5 g();
6 x
7 };
8 let c = |x| {
9 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
11 ccccccccccccccccccccccc,
12 )
13 };
14 let c = |x| -> u8 { { x } };
15 let c = |x| unsafe { x };
16 let c = |x| {
17 m! {}
18 };
19 let c = |x| {
20 { x } // c
21 };
22 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
23 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { x };
24 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
25 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| {
26 g();
27 x
28 };
29 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
30 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { x };
31}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let c = |x| x;
3 let c = |x| x;
4 let c = |x| {
5 g();
6 x
7 };
8 let c = |x| {
9 {
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
11 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
12 ccccccccccccccccccccccc,
13 )
14 }
15 };
16 let c = |x| -> u8 { { x } };
17 let c = |x| unsafe { x };
18 let c = |x| {
19 m! {}
20 };
21 let c = |x| {
22 { x } // c
23 };
24 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
25 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { { x } };
26 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
27 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| {
28 {
29 g();
30 x
31 }
32 };
33 let c = |aaaaaaaaaaaaaaaaaaaaaaaaaaa: Aaaaaaaaaaaaaaaaaa,
34 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Bbbbbbbbbbbbbb| { x };
35}

A match arm body loses its block also with a comment inside the expression #

mediummatchcomment

apfmt removes the block around a match arm body even with a comment inside the expression; rustfmt keeps it.

Why apfmt reads the Style Guide's "no line comments" as comments directly in the block.
Details

"If the body is a single expression with no line comments and not a control flow expression, start it on the same line as the left-hand side" (Style Guide). apfmt reads "no line comments" as comments directly in the block. A block that contains only an expression loses its braces even when a comment is inside that expression, for example in a match arm, an unsafe block, a closure body or between arguments, and also from nested blocks. rustfmt keeps the block whenever there is a comment anywhere in its text.

A comment directly in the block keeps the block in both. A comment after the block (=> { f(a) } // c) keeps it in neither.

Style Guide
Follows it: apfmt
If the body is a single expression with no line comments and not a control flow expression, start it on the same line as the left-hand side

A comment in an unsafe block#edition 2024

Input
1fn main() {
2 match k {
3 B => {
4 unsafe {
5 // SAFETY: x
6 validity.push(false)
7 }
8 }
9 }
10}
apfmt c9342b5
1fn main() {
2 match k {
3 B => unsafe {
4 // SAFETY: x
5 validity.push(false)
6 },
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 match k {
3 B => {
4 unsafe {
5 // SAFETY: x
6 validity.push(false)
7 }
8 }
9 }
10}

A match head that fits on one line only in the block goes in the block #

mediummatch

apfmt puts a match head in the block of its arm when it fits on one line only there; rustfmt may put { on its own line.

Why It avoids a { on a line of its own.
Details

A match as an arm body stays on the line of => when its head and { fit there. Otherwise, if the head fits on one line inside a block, apfmt puts it in the block. rustfmt does that too when the head itself does not fit, but when only { does not, it puts { on a line of its own.

A head that breaks either way follows the braces of the source in both formatters. The Style Guide does not say whether match is a control-flow expression, which would require a block.

Style Guide
Does not settle this.

Heads that do not fit with {#edition 2024

Input
1fn head_fits_in_block() {
2 match x {
3 // rustfmt: `{` on its own line
4 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match protobuf_plugin_command.payload {
5 _ => 1,
6 },
7 // rustfmt: `{` on its own line, after a head that could break
8 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
9 _ => 1,
10 },
11 // `match head` does not fit either: the same in rustfmt
12 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
13 _ => 1,
14 },
15 // It fits on the line of `=>`
16 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
17 _ => 1,
18 },
19 }
20}
apfmt c9342b5
1fn head_fits_in_block() {
2 match x {
3 // rustfmt: `{` on its own line
4 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => {
5 match protobuf_plugin_command.payload {
6 _ => 1,
7 }
8 }
9 // rustfmt: `{` on its own line, after a head that could break
10 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => {
11 match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
12 _ => 1,
13 }
14 }
15 // `match head` does not fit either: the same in rustfmt
16 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => {
17 match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
18 _ => 1,
19 }
20 }
21 // It fits on the line of `=>`
22 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
23 _ => 1,
24 },
25 }
26}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn head_fits_in_block() {
2 match x {
3 // rustfmt: `{` on its own line
4 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match protobuf_plugin_command.payload
5 {
6 _ => 1,
7 },
8 // rustfmt: `{` on its own line, after a head that could break
9 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)?
10 {
11 _ => 1,
12 },
13 // `match head` does not fit either: the same in rustfmt
14 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => {
15 match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
16 _ => 1,
17 }
18 }
19 // It fits on the line of `=>`
20 Some(Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) => match compute(aaaaaaaaaaaaa, bbbbbbbbbbbbb)? {
21 _ => 1,
22 },
23 }
24}

An if or match after = moves to the next line rather than break its head #

mediumletifmatch

apfmt moves an if or match to the next line rather than put { on its own line; rustfmt keeps it on the line of =.

Why It avoids a broken control line with its opening brace alone on a line.
Details

When the head of an if or a match on the right side of = fits on the line of = only without {, rustfmt puts { on a line of its own. apfmt moves the expression to the next line, where the head and { fit. The Style Guide says: "If the control line is broken for any reason, then the opening brace should be on its own line".

Style Guide
Follows it: apfmt
If the control line is broken for any reason, then the opening brace should be on its own line

A match whose { does not fit#edition 2024

Input
1fn main() {
2 let naive_time = match chrono::NaiveTime::from_hms_micro_opt(hour, minute, second, time.micro()) {
3 Some(v) => v,
4 None => return Ok(0),
5 };
6}
apfmt c9342b5
1fn main() {
2 let naive_time =
3 match chrono::NaiveTime::from_hms_micro_opt(hour, minute, second, time.micro()) {
4 Some(v) => v,
5 None => return Ok(0),
6 };
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let naive_time = match chrono::NaiveTime::from_hms_micro_opt(hour, minute, second, time.micro())
3 {
4 Some(v) => v,
5 None => return Ok(0),
6 };
7}

A multi-line string hugs the list as in the source #

mediumstringcallhugging

apfmt keeps a multi-line string on the line of the opening delimiter if the source has it there; rustfmt decides by the length of the name in front of it.

Why The author's choice is kept, as in Prettier and Ruff, while rustfmt's choice depends on the length of the callee.
Details

A single string literal spanning several lines, as the only call argument, array element, macro argument or attribute argument (including name = "..."), stays on the line of the opening delimiter if it is there in the source, and moves to a line of its own if it is not. This follows the author, as Prettier and Ruff do. Code formatted by rustfmt stays as it is, except for the trailing comma of a string left on its own line in an attribute. A tuple (r#"...",) or a string with a comment in front of it is always broken.

A hugged string moves only if that can make it fit: when its first line does not fit after the delimiter, or when its last line fits only without the closing delimiter and what follows. If its last line is at least max_width wide, moving cannot help, so the string stays hugged, as in Ruff.

rustfmt hugs such a string only after a callee shorter than tab_spaces (f(r#", [r#"), so the layout depends on the length of the name. It also ignores the width: it hugs after a short callee, in an array and for name = "..." even when that overflows, and moves the string after a longer callee even when that does not help. From a last line of 100 columns, it leaves a chain and a bare string in an attribute unformatted.

In an attribute, rustfmt hugs name = "..." whenever its first line is at most attr_fn_like_width wide, even if the source has it on its own line, and never hugs a bare string. apfmt follows the source in both cases.

The Style Guide does not cover this: a literal is not one of its combinable expressions, and a multi-line argument breaks the call.

Style Guide
Does not settle this.
References
rustfmt#2876: hugging a multi-line string, rustfmt#6556: a long last line leaves the code unformatted
Related
Attribute arguments are laid out as call arguments

Hugged in the source#edition 2024

Input
1fn main() {
2 query(r#"
3SELECT * FROM t
4"#);
5}
apfmt c9342b5
1fn main() {
2 query(r#"
3SELECT * FROM t
4"#);
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 query(
3 r#"
4SELECT * FROM t
5"#,
6 );
7}

On its own line in the source#edition 2024

Input
1fn main() {
2 f(
3 r#"
4SELECT * FROM t
5"#,
6 );
7}
apfmt c9342b5
1fn main() {
2 f(
3 r#"
4SELECT * FROM t
5"#,
6 );
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 f(r#"
3SELECT * FROM t
4"#);
5}

In an attribute#edition 2024

Input
1#[error("a bare string hugged in the source
2second line")]
3struct E;
apfmt c9342b5
1#[error("a bare string hugged in the source
2second line")]
3struct E;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1#[error(
2 "a bare string hugged in the source
3second line"
4)]
5struct E;

Generics clauses stay on one line #

mediumgenericsfn

apfmt keeps a generics clause on one line and breaks the parameters or the return type instead; rustfmt breaks the generics too.

Why This is the Style Guide rule.
Details

The Style Guide says: "Prefer to put a generics clause on one line. Break other parts of an item declaration rather than line-breaking a generics clause." rustfmt breaks the generics and the parameters, and apfmt breaks only the parameters.

With no parameters to break, a return type that does not fit with { moves to the next line. rustfmt does so for a short generics clause only from 102 columns. Up to 101 columns it keeps the return type on the line and puts { on its own line, which is one column over max_width at 101. It breaks a generics clause that does not fit with the return type instead.

Style Guide
Follows it: apfmt
Prefer to put a generics clause on one line. Break other parts of an item declaration rather than line-breaking a generics clause.

With parameters to break#edition 2024

Input
1fn s<T: FirstVeryLongTraitBoundName + SecondVeryLongTraitBoundName + ThirdTraitBoundName + Fourth>(a: T) {
2 a;
3}
apfmt c9342b5
1fn s<T: FirstVeryLongTraitBoundName + SecondVeryLongTraitBoundName + ThirdTraitBoundName + Fourth>(
2 a: T,
3) {
4 a;
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn s<
2 T: FirstVeryLongTraitBoundName + SecondVeryLongTraitBoundName + ThirdTraitBoundName + Fourth,
3>(
4 a: T,
5) {
6 a;
7}

Without parameters#edition 2024

Input
1fn no_params<T: Clone + Debug, U: From<T> + Into<Value>, F: Fn(T) -> U, G: FnMut(U) -> Option<T>>() -> Option<(T, U)> {
2 x
3}
apfmt c9342b5
1fn no_params<T: Clone + Debug, U: From<T> + Into<Value>, F: Fn(T) -> U, G: FnMut(U) -> Option<T>>()
2-> Option<(T, U)> {
3 x
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn no_params<
2 T: Clone + Debug,
3 U: From<T> + Into<Value>,
4 F: Fn(T) -> U,
5 G: FnMut(U) -> Option<T>,
6>() -> Option<(T, U)> {
7 x
8}

A tuple type is not broken where it fits #

mediumtypefn

apfmt keeps a tuple type on one line where it fits; rustfmt may break it anyway.

Why This is the Style Guide rule for types.
Details

"Avoid breaking lines in types where possible" (Style Guide). rustfmt breaks a tuple type even when it would fit on its line, in a return type, a parameter, a generic argument or a field. In apfmt, a return type that does not fit moves to the next line if the function has no parameters, and breaks after broken parameters. A single tuple generic argument that must break hugs <>.

Style Guide
Follows it: apfmt
Avoid breaking lines in types where possible
Related
Generics clauses stay on one line

In a return type without parameters#edition 2024

Input
1pub fn must_new_cluster_and_kv_client() -> (Cluster<ServerCluster<RocksEngine>, RocksEngine>, TikvClient, Context) {
2 must_new_cluster_and_kv_client_mul(1)
3}
apfmt c9342b5
1pub fn must_new_cluster_and_kv_client()
2-> (Cluster<ServerCluster<RocksEngine>, RocksEngine>, TikvClient, Context) {
3 must_new_cluster_and_kv_client_mul(1)
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1pub fn must_new_cluster_and_kv_client() -> (
2 Cluster<ServerCluster<RocksEngine>, RocksEngine>,
3 TikvClient,
4 Context,
5) {
6 must_new_cluster_and_kv_client_mul(1)
7}

In a return type after broken parameters#edition 2024

Input
1impl X {
2 fn render(&mut self, client_id: Option<ClientId>) -> Result<Option<(Vec<CharacterChunk>, Option<String>, Vec<SixelImageChunk>, Vec<KittyImageChunk>)>, ZellijError> {
3 1
4 }
5 fn write_engine_call(&self, call: EngineCall<PipelineData>) -> Result<(PipelineDataWriter<Self>, mpsc::Receiver<EngineCallResponse<PipelineData>>), ShellError> {
6 1
7 }
8}
apfmt c9342b5
1impl X {
2 fn render(
3 &mut self,
4 client_id: Option<ClientId>,
5 ) -> Result<
6 Option<(Vec<CharacterChunk>, Option<String>, Vec<SixelImageChunk>, Vec<KittyImageChunk>)>,
7 ZellijError,
8 > {
9 1
10 }
11 fn write_engine_call(
12 &self,
13 call: EngineCall<PipelineData>,
14 ) -> Result<
15 (PipelineDataWriter<Self>, mpsc::Receiver<EngineCallResponse<PipelineData>>),
16 ShellError,
17 > {
18 1
19 }
20}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1impl X {
2 fn render(
3 &mut self,
4 client_id: Option<ClientId>,
5 ) -> Result<
6 Option<(
7 Vec<CharacterChunk>,
8 Option<String>,
9 Vec<SixelImageChunk>,
10 Vec<KittyImageChunk>,
11 )>,
12 ZellijError,
13 > {
14 1
15 }
16 fn write_engine_call(
17 &self,
18 call: EngineCall<PipelineData>,
19 ) -> Result<
20 (
21 PipelineDataWriter<Self>,
22 mpsc::Receiver<EngineCallResponse<PipelineData>>,
23 ),
24 ShellError,
25 > {
26 1
27 }
28}

In a variant#edition 2024

Input
1enum E {
2 A(Box<(String, u32, GetCompletionsAtPositionOptions, FormatCodeSettings, Aaaaaaaaaaaaaaaa)>),
3}
apfmt c9342b5
1enum E {
2 A(Box<(String, u32, GetCompletionsAtPositionOptions, FormatCodeSettings, Aaaaaaaaaaaaaaaa)>),
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1enum E {
2 A(
3 Box<(
4 String,
5 u32,
6 GetCompletionsAtPositionOptions,
7 FormatCodeSettings,
8 Aaaaaaaaaaaaaaaa,
9 )>,
10 ),
11}

for breaks before in #

mediumloop

apfmt breaks a for head before in, as the Style Guide asks; rustfmt breaks after in.

Why This is the Style Guide rule, settled in style-team#62 and never implemented in rustfmt.
Details

The Style Guide breaks a for head that does not fit before in, and block-indents the in line. rustfmt breaks after in. The style team settled this rule in style-team#62 ("the in and = should go on the next line, like other binops"), but rustfmt never implemented it.

The same applies after a broken or-pattern: its last line takes the in only when the iterable fits there too.

An iterable that does not fit on the line of for is not broken there either, unless the in line cannot be on a single line: apfmt prefers breaking before in to breaking the iterable on the line of for. Neither the Style Guide nor the style team discussion ranks these two options. A chain wider than chain_width cannot be on the in line, so it breaks before every . on the line of for, as in rustfmt and as in if and while.

The Style Guide also allows a head whose last line is closing delimiters followed by {. apfmt uses this for an iterable that cannot be on a single line, such as a hugged closure, as rustfmt does. After a broken pattern and a broken iterable, { follows the closing delimiters, while rustfmt breaks after in.

Style Guide
Follows it: apfmt
References
style-team#62

A plain head#edition 2024

Input
1fn f() {
2 for (aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) in cccccccccccccccccccccccccccccccc(ddddddddd) { y }
3}
apfmt c9342b5
1fn f() {
2 for (aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
3 in cccccccccccccccccccccccccccccccc(ddddddddd)
4 {
5 y
6 }
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 for (aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) in
3 cccccccccccccccccccccccccccccccc(ddddddddd)
4 {
5 y
6 }
7}

After a broken or-pattern#edition 2024

Input
1fn f() {
2 for Some(LongVariantNameAlpha(a)) | Some(LongVariantNameBeta(a)) | Some(LongVariantNameGammaXYZ(a)) in compute(argument_one, argument_two, argument_three, argument_four) {
3 foo(a);
4 }
5}
apfmt c9342b5
1fn f() {
2 for Some(LongVariantNameAlpha(a))
3 | Some(LongVariantNameBeta(a))
4 | Some(LongVariantNameGammaXYZ(a))
5 in compute(argument_one, argument_two, argument_three, argument_four)
6 {
7 foo(a);
8 }
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 for Some(LongVariantNameAlpha(a))
3 | Some(LongVariantNameBeta(a))
4 | Some(LongVariantNameGammaXYZ(a)) in
5 compute(argument_one, argument_two, argument_three, argument_four)
6 {
7 foo(a);
8 }
9}

After a broken pattern and a broken iterable#edition 2024

Input
1fn f() {
2 if a {
3 for AllocationDescription { allocation_identifier, queue_identifier, worker_count } in load_all_the_allocation_descriptions(first_argument_value, second_argument_value, third) {
4 x
5 }
6 }
7}
apfmt c9342b5
1fn f() {
2 if a {
3 for AllocationDescription {
4 allocation_identifier,
5 queue_identifier,
6 worker_count,
7 } in load_all_the_allocation_descriptions(
8 first_argument_value,
9 second_argument_value,
10 third,
11 ) {
12 x
13 }
14 }
15}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 if a {
3 for AllocationDescription {
4 allocation_identifier,
5 queue_identifier,
6 worker_count,
7 } in
8 load_all_the_allocation_descriptions(first_argument_value, second_argument_value, third)
9 {
10 x
11 }
12 }
13}

Comments behind an operator move in front of it #

mediumcommentoperator

apfmt moves a comment behind an operator in front of it; rustfmt breaks after the operator.

Why A broken operator chain starts its lines with the operator (Style Guide).
Details

A broken operator chain starts its lines with the operator (Style Guide), so apfmt moves comments behind an operator in front of it, as if the source had them there. rustfmt keeps the source and breaks after the operator. A block comment followed by its operand on the same line stays with the operand.

Style Guide
Follows it: apfmt

A trailing comment after an operator#edition 2024

apfmt puts the comment before the operator, and the operator starts the next line.

Input
1fn main() {
2 let x = first_condition_value && // first
3 second_condition_value;
4}
apfmt c9342b5
1fn main() {
2 let x = first_condition_value // first
3 && second_condition_value;
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let x = first_condition_value && // first
3 second_condition_value;
4}

An own-line comment after an operator#edition 2024

apfmt keeps the comment on its own line, and the operator starts the line after it.

Input
1fn main() {
2 let x = first_condition_value &&
3 // own line
4 second_condition_value;
5}
apfmt c9342b5
1fn main() {
2 let x = first_condition_value
3 // own line
4 && second_condition_value;
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let x = first_condition_value &&
3 // own line
4 second_condition_value;
5}

A comment before ; moves after it #

mediumcomment

apfmt puts ; right after the code and the comment after it; rustfmt leaves ; on its own line after the comment.

Why A ; alone on its line carries no meaning, and the comment still follows its statement.
Details

rustfmt leaves the ; on its own line after a comment. apfmt puts the ; right after the code and the comment after it.

Style Guide
Does not settle this.

Block and line comments#edition 2024

Input
1fn main() {
2 f(1)
3 /* about f */;
4 g(2)
5 // about g
6 ;
7 h(3);
8}
apfmt c9342b5
1fn main() {
2 f(1); /* about f */
3 g(2); // about g
4 h(3);
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 f(1)
3 /* about f */;
4 g(2)
5 // about g
6 ;
7 h(3);
8}

Blank lines between the elements of a method chain are kept #

mediumchainblank-lines

apfmt keeps blank lines between the elements of a broken method chain; rustfmt leaves such a statement as written or removes them.

Why Blank lines group the calls of a builder. Prettier keeps them too.
Details

apfmt keeps a blank line between the elements of a broken method chain, even without a comment after it, because it groups the calls of a builder. rustfmt usually leaves such a statement as written, and otherwise removes the blank line. The Style Guide has no rule for this. Prettier keeps these blank lines too, but also breaks the chain because of them, while apfmt joins a chain that fits on one line and drops them.

Operator chains are different: in both formatters, their operands lose blank lines unless a comment follows, as call arguments do.

Style Guide
Does not settle this.

A blank line alone#edition 2024

Input
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4
5 .set_sync(true);
6}
apfmt c9342b5
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4
5 .set_sync(true);
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4 .set_sync(true);
5}

A blank line in front of a comment#edition 2024

Input
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4
5 // A comment
6 .set_sync(true);
7}
apfmt c9342b5
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4
5 // A comment
6 .set_sync(true);
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let opts = WriteOptions::new()
3 .set_disable_wal(opt.disable_wal())
4 // A comment
5 .set_sync(true);
6}

A blank line before an own-line comment is kept in every list #

mediumcommentblank-lines

apfmt keeps a blank line before an own-line comment in every list; rustfmt removes it between call arguments and array elements.

Why It separates the comment, which belongs to the next item, from the item above.
Details

A blank line before an own-line comment separates the comment, which belongs to the next item, from the item above. apfmt keeps it in every list. rustfmt removes it between call arguments and array elements, where it removes all blank lines, as apfmt does when no comment follows. rustfmt decided to remove blank lines inside expressions in rustfmt #1172 and implemented that in rustfmt #1822.

Lists of named fields and declarations keep all their blank lines in both formatters when broken one item per line: struct definitions, enum variants, parameters, and struct literals and patterns.

A blank line next to a comment between two attributes of the same kind also stays in apfmt, and rustfmt removes it. Without a comment both remove it, except in match: rustfmt also removes the one between an inner attribute and the #[...] of the first arm, and apfmt keeps it there, as at the start of a file.

Style Guide
Does not settle this.
References
rustfmt #1172, rustfmt #1822

Call arguments and arrays#edition 2024

Input
1fn f() {
2 g(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
4
5 // c
6 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
7
8 cccccccccccccccccccccccccccc,
9 );
10 let v = [
11 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
12
13 // c
14 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
15 ];
16}
apfmt c9342b5
1fn f() {
2 g(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
4
5 // c
6 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
7 cccccccccccccccccccccccccccc,
8 );
9 let v = [
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
11
12 // c
13 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
14 ];
15}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 g(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
4 // c
5 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
6 cccccccccccccccccccccccccccc,
7 );
8 let v = [
9 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
10 // c
11 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
12 ];
13}

Between attributes#edition 2024

Input
1#[a]
2
3// c
4#[b]
5fn f() {}
apfmt c9342b5
1#[a]
2
3// c
4#[b]
5fn f() {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1#[a]
2// c
3#[b]
4fn f() {}

Filled call arguments #

mediumcallcommentstring

Both fill simple call arguments on lines, but apfmt measures comments exactly, keeps a comment after ( in place and does not fill multi-line strings.

Why Filling itself follows rustfmt. Exact measurement uses the full line width, and a multi-line string is not a short item.
Details

Both formatters fill simple call arguments on lines, several per line, although the Style Guide asks for one argument per line. They differ in three details:

  • Comment widths are measured exactly. rustfmt reserves 6 columns more than a comment needs, so apfmt fits more items on a line.
  • **A comment ending the line of ( stays there**, as in all other lists. rustfmt moves it to the next line.
  • A multi-line string literal is not a short item, so apfmt does not fill arguments that include one. rustfmt fills them when the text of the literal is at most short_array_element_width_threshold long.
Style Guide
Follows it: neither
Related
Comments after an opening delimiter stay on its line

Comment widths are measured exactly#edition 2024

Input
1fn main() {
2 edge_case(1, /* a */ /* b */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
3}
apfmt c9342b5
1fn main() {
2 edge_case(
3 1, /* a */ /* b */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
4 22, 23, 24, 25, 26, 27,
5 );
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 edge_case(
3 1, /* a */ /* b */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
4 21, 22, 23, 24, 25, 26, 27,
5 );
6}

A comment ending the line of (#edition 2024

Input
1fn main() {
2 edge_case( // after paren
3 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
4 edge_case(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
5 // dangling at end
6 );
7}
apfmt c9342b5
1fn main() {
2 edge_case( // after paren
3 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
4 26, 27, 28,
5 );
6 edge_case(
7 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
8 26, 27,
9 // dangling at end
10 );
11}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 edge_case(
3 // after paren
4 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
5 26, 27, 28,
6 );
7 edge_case(
8 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
9 26, 27,
10 // dangling at end
11 );
12}

A multi-line string among the arguments#edition 2024

Input
1fn main() {
2 h(1, x, "
3multi", y);
4}
apfmt c9342b5
1fn main() {
2 h(
3 1,
4 x,
5 "
6multi",
7 y,
8 );
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 h(
3 1, x, "
4multi", y,
5 );
6}

Lines that overflow anyway do not decide the layout around them #

mediumoverflowclosure

apfmt does not hug a closure just to save indentation for a line that overflows anyway; rustfmt gives up on such a closure body.

Why A line that overflows anyway overflows by only a few more columns when indented deeper.
Details

A line that overflows max_width in every layout, such as a long comment or a macro call that cannot be broken, overflows by only a few more columns when indented deeper, however long it is. apfmt therefore does not hug a closure to save that line a level of indentation if the line of the call then overflows. rustfmt gives up on such a closure body: it copies it unchanged after putting the arguments one per line. apfmt formats the body, and moves the right side of a let to the next line when the call then fits there.

With overflow_line_penalty = 0, apfmt hugs the closure too.

Style Guide
Does not settle this.

A closure with an unbreakable macro call#edition 2024

Input
1impl Add for &DecimalChunked {
2 fn add(self, rhs: Self) -> Self::Output {
3 // `polars_err!(ComputeError: ...)` is copied unchanged and overflows at any indentation;
4 // the closure is not hugged to save it a few columns when the call line then overflows
5 let phys = broadcast_try_binary_elementwise(self.physical(), rhs.physical(), |opt_l, opt_r| {
6 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
7 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
8 })?;
9 Ok(Some(ls))
10 });
11 broadcast_try_binary_elementwise_xxxxxxxxxx(self.physical(), rhs.physical(), |opt_l, opt_r| {
12 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
13 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
14 })?;
15 Ok(Some(ls))
16 });
17 }
18}
apfmt c9342b52 lines over 100
1impl Add for &DecimalChunked {
2 fn add(self, rhs: Self) -> Self::Output {
3 // `polars_err!(ComputeError: ...)` is copied unchanged and overflows at any indentation;
4 // the closure is not hugged to save it a few columns when the call line then overflows
5 let phys =
6 broadcast_try_binary_elementwise(self.physical(), rhs.physical(), |opt_l, opt_r| {
7 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
8 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
9 })?;
10 Ok(Some(ls))
11 });
12 broadcast_try_binary_elementwise_xxxxxxxxxx(
13 self.physical(),
14 rhs.physical(),
15 |opt_l, opt_r| {
16 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
17 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
18 })?;
19 Ok(Some(ls))
20 },
21 );
22 }
23}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)2 lines over 100
1impl Add for &DecimalChunked {
2 fn add(self, rhs: Self) -> Self::Output {
3 // `polars_err!(ComputeError: ...)` is copied unchanged and overflows at any indentation;
4 // the closure is not hugged to save it a few columns when the call line then overflows
5 let phys = broadcast_try_binary_elementwise(
6 self.physical(),
7 rhs.physical(),
8 |opt_l, opt_r| {
9 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
10 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
11 })?;
12 Ok(Some(ls))
13 },
14 );
15 broadcast_try_binary_elementwise_xxxxxxxxxx(
16 self.physical(),
17 rhs.physical(),
18 |opt_l, opt_r| {
19 let ls = dec128_rescale(l, left_s, prec, scale).ok_or_else(|| {
20 polars_err!(ComputeError: "overflow in Decimal cast for {l} from scale {left_s} to {scale}")
21 })?;
22 Ok(Some(ls))
23 },
24 );
25 }
26}

A repeated vec! is laid out like a repeated array #

mediummacro

apfmt gives vec![x; n] the layout of [x; n]; rustfmt breaks the vec! differently.

Why vec![x; n] then has the same layout as [x; n].
Details

apfmt lays out vec![x; n] like the array [x; n], matching what rustfmt does for arrays. rustfmt breaks the vec! over more lines, and without a trailing comma, as in other macro arguments.

Style Guide
Does not settle this.

A long element#edition 2024

Input
1fn main() {
2 let mut collectors = vec![SampleCollector::new(self.max_sample_size, self.max_fm_sketch_size, self.cm_sketch_depth, self.cm_sketch_width); columns_without_handle_len];
3}
apfmt c9342b5
1fn main() {
2 let mut collectors = vec![SampleCollector::new(
3 self.max_sample_size,
4 self.max_fm_sketch_size,
5 self.cm_sketch_depth,
6 self.cm_sketch_width,
7 ); columns_without_handle_len];
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let mut collectors = vec![
3 SampleCollector::new(
4 self.max_sample_size,
5 self.max_fm_sketch_size,
6 self.cm_sketch_depth,
7 self.cm_sketch_width
8 );
9 columns_without_handle_len
10 ];
11}

The generic arguments of a broken bound are block-indented #

mediumgenerics

apfmt indents the generic arguments of a broken bound one level; rustfmt indents them and the > one level deeper.

Why They are then like any other block-indented list.
Details

When a bound breaks inside its <>, apfmt indents the arguments one level from the bound and puts > at the indentation of the bound, like any other block-indented list. rustfmt indents the arguments and the > one level deeper, in where, in generics and after dyn.

Style Guide
Does not settle this.

In where#edition 2024

Input
1struct S<D>(D)
2where
3 D: Dispatch<PollItem = MessageHead<T::Outgoing>, PollBody = Bssssssss, RecvItem = MessageHead<T::Incoming>> + Unpin;
apfmt c9342b5
1struct S<D>(D)
2where
3 D: Dispatch<
4 PollItem = MessageHead<T::Outgoing>,
5 PollBody = Bssssssss,
6 RecvItem = MessageHead<T::Incoming>,
7 > + Unpin;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1struct S<D>(D)
2where
3 D: Dispatch<
4 PollItem = MessageHead<T::Outgoing>,
5 PollBody = Bssssssss,
6 RecvItem = MessageHead<T::Incoming>,
7 > + Unpin;

No space before the delimiter of a macro call with () #

mediummacrowhitespace

apfmt always removes a space before the ( of a macro call; rustfmt keeps it when it cannot parse the arguments.

Why The call looks the same whether its arguments parse or not.
Details

rustfmt keeps a space from the source in df! ( when it cannot parse the arguments. apfmt always removes it.

Style Guide
Does not settle this.

Arguments that do not parse#edition 2024

Input
1fn f() {
2 let df = df! (
3 "a" => [1, 2],
4 );
5 let df = df! (a, b);
6}
apfmt c9342b5
1fn f() {
2 let df = df!(
3 "a" => [1, 2],
4 );
5 let df = df!(a, b);
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let df = df! (
3 "a" => [1, 2],
4 );
5 let df = df!(a, b);
6}

The braces of a closure body are removed in macro arguments and around async #

mediumclosuremacro

apfmt removes the braces of a closure body in macro arguments and around async blocks with comments; rustfmt keeps them.

Why The Style Guide prefers closures without {}.
Details

"Use closures without the enclosing {}, if possible" (Style Guide). rustfmt keeps the braces in the arguments of a macro call and around an async block with a comment inside it. apfmt removes them in both, as anywhere else. A comment directly in the braces keeps them in both formatters.

Style Guide
Follows it: apfmt
Use closures without the enclosing {}, if possible

In macro arguments#edition 2024

Input
1fn main() {
2 fail_point!("before_clean_overlap_ranges", |_| { Ok(()) });
3}
apfmt c9342b5
1fn main() {
2 fail_point!("before_clean_overlap_ranges", |_| Ok(()));
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 fail_point!("before_clean_overlap_ranges", |_| { Ok(()) });
3}

Around async with a comment inside#edition 2024

Input
1fn main() {
2 let server = server::http(move |req| {
3 async move {
4 // not iamatoken
5 assert_eq!(1, 2);
6 http::Response::default()
7 }
8 });
9}
apfmt c9342b5
1fn main() {
2 let server = server::http(move |req| async move {
3 // not iamatoken
4 assert_eq!(1, 2);
5 http::Response::default()
6 });
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let server = server::http(move |req| {
3 async move {
4 // not iamatoken
5 assert_eq!(1, 2);
6 http::Response::default()
7 }
8 });
9}

Other comment placement #

lowcomment

In these other places, apfmt keeps comments closer to where they were written.

Why A comment stays where its author put it, spaced like the code around it.
Details

Style Guide
Does not settle this.

Comments around call arguments#edition 2024

rustfmt leaves the statement unformatted. apfmt formats it and keeps the comments in place.

Input
1fn main() {
2 f /* a */ ( /* b */ 1 /* c */, /* d */ 2 /* e */) /* f */;
3}
apfmt c9342b5
1fn main() {
2 f /* a */(/* b */ 1 /* c */, /* d */ 2 /* e */); /* f */
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted
1fn main() {
2 f /* a */ ( /* b */ 1 /* c */, /* d */ 2 /* e */) /* f */;
3}

Comments around if and else#edition 2024

rustfmt puts every comment on its own line. apfmt keeps them inline.

Input
1fn main() {
2 if /* c */ x /* d */ {
3 f();
4 } /* e */ else /* f */ {
5 g();
6 }
7}
apfmt c9342b5
1fn main() {
2 if /* c */ x /* d */ {
3 f();
4 } /* e */ else /* f */ {
5 g();
6 }
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 if
3 /* c */
4 x
5 /* d */
6 {
7 f();
8 }
9 /* e */
10 else
11 /* f */
12 {
13 g();
14 }
15}

A trailing comment after } in front of else#edition 2024

rustfmt moves the comment to its own line. apfmt keeps it after }.

Input
1fn main() {
2 if x { f(); } // trailing
3 else { g(); }
4}
apfmt c9342b5
1fn main() {
2 if x {
3 f();
4 } // trailing
5 else {
6 g();
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 if x {
3 f();
4 }
5 // trailing
6 else {
7 g();
8 }
9}

An own-line comment after (#edition 2024

rustfmt joins the comment with the arguments on one line. apfmt keeps it on its own line, and the list stays vertical.

Input
1fn main() {
2 f(
3 /* block */
4 a, b);
5 f(
6 // line
7 a, b);
8 f(/* same line */ a, b);
9}
apfmt c9342b5
1fn main() {
2 f(
3 /* block */
4 a, b,
5 );
6 f(
7 // line
8 a, b,
9 );
10 f(/* same line */ a, b);
11}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 f(/* block */ a, b);
3 f(
4 // line
5 a, b,
6 );
7 f(/* same line */ a, b);
8}

A trailing comment in a signature before where#edition 2024

rustfmt joins the parameters on the line of ( or moves the comment to its own line. apfmt keeps the parameters broken and the comment after ).

Input
1fn comment<T>(
2 a: T, // c
3) where T: Clone { body(); }
apfmt c9342b5
1fn comment<T>(
2 a: T, // c
3) where
4 T: Clone,
5{
6 body();
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn comment<T>(a: T, // c
2)
3where
4 T: Clone,
5{
6 body();
7}

An own-line comment below the trailing comment of the last item#edition 2024

rustfmt reprints the comment with its indentation from the source, aligned too far. apfmt indents it like the items.

Input
1fn main() {
2 match x {
3 ScreenInstruction::TogglePaneFrames(
4 _completion_tx, // the action ends here, dropping this will release anything
5 // waiting for it
6 ) => {}
7 }
8}
apfmt c9342b5
1fn main() {
2 match x {
3 ScreenInstruction::TogglePaneFrames(
4 _completion_tx, // the action ends here, dropping this will release anything
5 // waiting for it
6 ) => {}
7 }
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 match x {
3 ScreenInstruction::TogglePaneFrames(
4 _completion_tx, // the action ends here, dropping this will release anything
5 // waiting for it
6 ) => {}
7 }
8}

A block comment in front of an item or an attribute on the same line#edition 2024

rustfmt moves the comment to its own line. apfmt keeps it in front of the item; the Style Guide spaces an inline block comment like an identifier.

Input
1/* Before the first item */ fn f() {}
2fn g() {}
3/* Before an item */ fn h() {}
apfmt c9342b5
1/* Before the first item */ fn f() {}
2fn g() {}
3/* Before an item */ fn h() {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1/* Before the first item */
2fn f() {}
3fn g() {}
4/* Before an item */
5fn h() {}

A block comment in front of a match arm#edition 2024

rustfmt puts the comma of the previous arm on the next line, in front of the comment. apfmt keeps the comma after the previous arm.

Input
1fn main() {
2 match x { A => 1, /* b */ B => 2 }
3}
apfmt c9342b5
1fn main() {
2 match x {
3 A => 1,
4 /* b */ B => 2,
5 }
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 match x {
3 A => 1,
4 , /* b */ B => 2,
5 }
6}

A body that is only a comment#edition 2024

rustfmt writes struct F {/* c */}. apfmt writes struct F { /* c */ }, spaced like an item.

Input
1struct F { /* c */ }
apfmt c9342b5
1struct F { /* c */ }
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1struct F {/* c */}

An empty array with only a comment#edition 2024

rustfmt keeps the spaces. apfmt writes [/* c */], like f(/* c */).

Input
1fn main() {
2 let w = [ /* empty */ ];
3}
apfmt c9342b5
1fn main() {
2 let w = [/* empty */];
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let w = [ /* empty */ ];
3}

An empty function body with only an inline comment#edition 2024

rustfmt puts } on the next line. apfmt keeps the body on one line.

Input
1fn b() { /* c */ }
apfmt c9342b5
1fn b() { /* c */ }
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn b() { /* c */
2}

A line comment after the opening delimiter of an empty container#edition 2024

rustfmt moves the comment to its own line. apfmt keeps it on the line of the opening delimiter.

Input
1struct S { // c
2}
3struct T( // c
4);
apfmt c9342b5
1struct S { // c
2}
3struct T( // c
4);
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1struct S {
2 // c
3}
4struct T(
5 // c
6);

Comments of sorted imports #

lowusecomment

When imports are sorted, apfmt moves every comment with its import; rustfmt leaves some behind or mixes them up.

Why A comment describes its item, so it must not end up on another one.
Details

When imports are sorted, apfmt moves every comment with its item. rustfmt leaves some comments behind or mixes them up within a list. For comments that rustfmt drops, see "Comments are never dropped".

Style Guide
Does not settle this.
Related
Comments are never dropped

A trailing comment on an import that moves#edition 2024

rustfmt leaves the comment on the second line, where it now describes the wrong import. apfmt moves it with use d;.

Input
1use e;
2use d; // about d
apfmt c9342b5
1use d; // about d
2use e;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use d;
2use e; // about d

An own-line comment in front of the closing } of a sorted list#edition 2024

rustfmt moves the comment in front of other items. apfmt keeps it at the end.

Input
1use x::{
2 c, // c trailing
3 // about b
4 b,
5 /* about a */ a,
6 // closing
7};
apfmt c9342b5
1use x::{
2 /* about a */ a,
3 // about b
4 b, c, // c trailing
5 // closing
6};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use x::{
2 /* about a */ a,
3 // closing
4 // about b
5 b,
6 c, // c trailing
7};

A comment after the { of a sorted list#edition 2024

rustfmt moves the comment in front of the item that was first in the source. apfmt keeps it on the line of {.

Input
1use x::{ // first line
2 d, // d
3 c,
4 /* b */ b,
5};
apfmt c9342b5
1use x::{ // first line
2 /* b */ b, c, d, // d
3};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use x::{
2 /* b */ b,
3 c,
4 // first line
5 d, // d
6};

Widths are measured exactly #

lowwidth

apfmt applies width limits exactly; rustfmt is one or two columns stricter in some places.

Why A limit of 100 columns then means 100 columns everywhere.
Details

apfmt applies max_width and the width heuristics to the exact width of a line or a part of it. With the default settings, rustfmt is one or two columns stricter in these places:

  • A use item with a list fits on one line only within 98 columns. apfmt keeps it on one line up to max_width (100).
  • { follows a return type after broken parameters only within max_width minus the indentation of the line: ) -> Ret { must end within 96 columns at an indentation of 4 and 84 at 16, as if the indentation were counted twice. apfmt keeps it there up to max_width.
  • A chain ending with ? fits on one line only within chain_width - 1 (59). Without the ?, and in apfmt in both cases, the limit is chain_width (60). The whole line of such a chain also fits only within max_width - 1 (99).
  • Filled lists (the items of a broken use list, and arrays or arguments of simple items) are filled up to column 99. apfmt fills them up to max_width.
  • Nested hugs add up: rustfmt reserves a column for each inner ), so Ok(Bar(ppp( exactly within fn_call_width is not hugged.
  • The right side after a broken if let pattern stays on the line of }) only within 97 columns, or 95 for a chain ending with ?. apfmt keeps it there up to max_width.
Style Guide
Does not settle this.

A use list at 98 to 101 columns#edition 2024

Input
1use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtract};
2// 99 and 100 columns: one line (rustfmt breaks the list: its limit for a `use` is 98)
3use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtracto};
4use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtractor};
5// 101 columns: broken in both
6use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtractors};
apfmt c9342b5
1use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtract};
2// 99 and 100 columns: one line (rustfmt breaks the list: its limit for a `use` is 98)
3use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtracto};
4use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtractor};
5// 101 columns: broken in both
6use crate::update::new::indexer::settings_changes::{
7 DocumentsIndentifiers, SettingsChangeExtractors,
8};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use crate::update::new::indexer::settings_changes::{DocumentsIndentifiers, SettingsChangeExtract};
2// 99 and 100 columns: one line (rustfmt breaks the list: its limit for a `use` is 98)
3use crate::update::new::indexer::settings_changes::{
4 DocumentsIndentifiers, SettingsChangeExtracto,
5};
6use crate::update::new::indexer::settings_changes::{
7 DocumentsIndentifiers, SettingsChangeExtractor,
8};
9// 101 columns: broken in both
10use crate::update::new::indexer::settings_changes::{
11 DocumentsIndentifiers, SettingsChangeExtractors,
12};

A chain ending with ? at chain_width#edition 2024

Input
1fn f() -> Result<(), E> {
2 let f = env.aaaa(path).bbbbbbbbbbbbb(x).cccccccccccccccccccccccc(x);
3 let f = env.aaaa(path).bbbbbbbbbbbbb(x).cccccccccccccccccccccccc(x)?;
4 let file = env.new_writable_file(path, EnvOptions::new()).map_err(r2e)?;
5 if self.connection.handle_shutdown(&request).into_diagnostic()? {
6 return Ok(());
7 }
8 // 61 columns: broken in both
9 let f = env.aaaa(path).bbbbbbbbbbbbb(x).ccccccccccccccccccccccccc(x)?;
10 Ok(())
11}
apfmt c9342b5
1fn f() -> Result<(), E> {
2 let f = env.aaaa(path).bbbbbbbbbbbbb(x).cccccccccccccccccccccccc(x);
3 let f = env.aaaa(path).bbbbbbbbbbbbb(x).cccccccccccccccccccccccc(x)?;
4 let file = env.new_writable_file(path, EnvOptions::new()).map_err(r2e)?;
5 if self.connection.handle_shutdown(&request).into_diagnostic()? {
6 return Ok(());
7 }
8 // 61 columns: broken in both
9 let f = env
10 .aaaa(path)
11 .bbbbbbbbbbbbb(x)
12 .ccccccccccccccccccccccccc(x)?;
13 Ok(())
14}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() -> Result<(), E> {
2 let f = env.aaaa(path).bbbbbbbbbbbbb(x).cccccccccccccccccccccccc(x);
3 let f = env
4 .aaaa(path)
5 .bbbbbbbbbbbbb(x)
6 .cccccccccccccccccccccccc(x)?;
7 let file = env
8 .new_writable_file(path, EnvOptions::new())
9 .map_err(r2e)?;
10 if self
11 .connection
12 .handle_shutdown(&request)
13 .into_diagnostic()?
14 {
15 return Ok(());
16 }
17 // 61 columns: broken in both
18 let f = env
19 .aaaa(path)
20 .bbbbbbbbbbbbb(x)
21 .ccccccccccccccccccccccccc(x)?;
22 Ok(())
23}

A statement of exactly 100 columns#edition 2024

Input
1fn f() {
2 let meta = fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?;
3 let result: CompleteResult = test().run_with_data("let code; nu -n -c $code | complete", code)?;
4}
apfmt c9342b5
1fn f() {
2 let meta = fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?;
3 let result: CompleteResult = test().run_with_data("let code; nu -n -c $code | complete", code)?;
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let meta =
3 fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?;
4 let result: CompleteResult =
5 test().run_with_data("let code; nu -n -c $code | complete", code)?;
6}

Filled lists up to max_width#edition 2024

Input
1use crate::{CreateOrOpen, FieldsIdsMap, Filter, FilterableAttributesRule, Index, MustStopProcessing, Search, SearchResult, db_snap, obkv_to_json};
apfmt c9342b5
1use crate::{
2 CreateOrOpen, FieldsIdsMap, Filter, FilterableAttributesRule, Index, MustStopProcessing, Search,
3 SearchResult, db_snap, obkv_to_json,
4};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use crate::{
2 CreateOrOpen, FieldsIdsMap, Filter, FilterableAttributesRule, Index, MustStopProcessing,
3 Search, SearchResult, db_snap, obkv_to_json,
4};

{ after a return type#edition 2024

Input
1mod m {
2 fn x88(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
4 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
5 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
6 1
7 }
8 fn x92(
9 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
11 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
12 1
13 }
14 fn x96(
15 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
16 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
17 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
18 1
19 }
20 fn x100(
21 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
22 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
23 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
24 1
25 }
26 fn x101(
27 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
28 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
29 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
30 1
31 }
32}
apfmt c9342b5
1mod m {
2 fn x88(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
4 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
5 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
6 1
7 }
8 fn x92(
9 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
11 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
12 1
13 }
14 fn x96(
15 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
16 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
17 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
18 1
19 }
20 fn x100(
21 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
22 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
23 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
24 1
25 }
26 fn x101(
27 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
28 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
29 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
30 {
31 1
32 }
33}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1mod m {
2 fn x88(
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
4 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
5 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
6 1
7 }
8 fn x92(
9 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
11 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
12 1
13 }
14 fn x96(
15 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
16 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
17 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {
18 1
19 }
20 fn x100(
21 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
22 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
23 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
24 {
25 1
26 }
27 fn x101(
28 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Text,
29 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Text,
30 ) -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31 {
32 1
33 }
34}

The right side after a broken if let pattern#edition 2024

Input
1fn f() {
2 // 97 columns, also in rustfmt
3 if let Some(Foo {
4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
5 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
6 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
7 h();
8 }
9 // 98 to 100 columns
10 if let Some(Foo {
11 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
12 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
13 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
14 h();
15 }
16 if let Some(Foo {
17 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
18 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
19 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
20 h();
21 }
22 if let Some(Foo {
23 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
24 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
25 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
26 h();
27 }
28 // Moved, also in rustfmt
29 if let Some(Foo {
30 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
31 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
32 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
33 h();
34 }
35 // A chain ending with `?`, 95 and 96 columns
36 if let Some(Foo {
37 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
38 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
39 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
40 h();
41 }
42 if let Some(Foo {
43 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
44 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
45 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)? {
46 h();
47 }
48 // Without `?`
49 if let Some(Foo {
50 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
51 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
52 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc) {
53 h();
54 }
55}
apfmt c9342b5
1fn f() {
2 // 97 columns, also in rustfmt
3 if let Some(Foo {
4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
5 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
6 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
7 {
8 h();
9 }
10 // 98 to 100 columns
11 if let Some(Foo {
12 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
13 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
14 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
15 {
16 h();
17 }
18 if let Some(Foo {
19 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
20 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
21 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
22 {
23 h();
24 }
25 if let Some(Foo {
26 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
27 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
28 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
29 {
30 h();
31 }
32 // Moved, also in rustfmt
33 if let Some(Foo {
34 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
35 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
36 }) =
37 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
38 {
39 h();
40 }
41 // A chain ending with `?`, 95 and 96 columns
42 if let Some(Foo {
43 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
44 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
45 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
46 {
47 h();
48 }
49 if let Some(Foo {
50 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
51 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
52 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
53 {
54 h();
55 }
56 // Without `?`
57 if let Some(Foo {
58 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
59 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
60 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)
61 {
62 h();
63 }
64}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 // 97 columns, also in rustfmt
3 if let Some(Foo {
4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
5 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
6 }) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
7 {
8 h();
9 }
10 // 98 to 100 columns
11 if let Some(Foo {
12 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
13 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
14 }) =
15 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
16 {
17 h();
18 }
19 if let Some(Foo {
20 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
21 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
22 }) =
23 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
24 {
25 h();
26 }
27 if let Some(Foo {
28 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
29 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
30 }) =
31 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
32 {
33 h();
34 }
35 // Moved, also in rustfmt
36 if let Some(Foo {
37 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
38 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
39 }) =
40 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
41 {
42 h();
43 }
44 // A chain ending with `?`, 95 and 96 columns
45 if let Some(Foo {
46 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
47 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
48 }) = ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
49 {
50 h();
51 }
52 if let Some(Foo {
53 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
54 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
55 }) =
56 ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)?
57 {
58 h();
59 }
60 // Without `?`
61 if let Some(Foo {
62 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
63 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
64 }) =
65 ctx.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbb, ccccc)
66 {
67 h();
68 }
69}

Closure parameters break to avoid an overflow in the body #

lowclosureoverflow

apfmt breaks closure parameters to avoid an overflow in the body; rustfmt moves the closure to the next line and lets the line overflow.

Why apfmt stays within max_width and takes one more line. Neither layout is clearly better.
Details

When the parameters of a closure after = fit on the next line but a line of the body then overflows, apfmt keeps the closure on the line of = with its parameters aligned, so the body is indented one level less. rustfmt moves it to the next line and lets the line overflow.

Style Guide
Does not settle this.

A long comment in the body#edition 2024

Input
1fn f() {
2 {
3 let buf_writer = |thread_no, write_buffer: &mut Vec<_>, csv_serializer: &mut CsvSerializer| {
4 // and allows writing `pl.concat([df] * 100, rechunk=False).write_csv()` as the rechunk aa
5 let a = 1;
6 };
7 }
8}
apfmt c9342b51 line over 100
1fn f() {
2 {
3 let buf_writer = |thread_no,
4 write_buffer: &mut Vec<_>,
5 csv_serializer: &mut CsvSerializer| {
6 // and allows writing `pl.concat([df] * 100, rechunk=False).write_csv()` as the rechunk aa
7 let a = 1;
8 };
9 }
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn f() {
2 {
3 let buf_writer =
4 |thread_no, write_buffer: &mut Vec<_>, csv_serializer: &mut CsvSerializer| {
5 // and allows writing `pl.concat([df] * 100, rechunk=False).write_csv()` as the rechunk aa
6 let a = 1;
7 };
8 }
9}

Details of the aligned closure parameters #

lowclosure

Both align broken closure parameters, but differ in the return type, blank lines and broken patterns.

Why Aligning itself follows rustfmt; apfmt differs only in these details.
Details

Both formatters align closure parameters that do not fit on one line after |, although the Style Guide asks for block indentation and a trailing comma. apfmt differs in the details:

  • A return type goes on a line of its own, aligned with the parameters. rustfmt indents it one column past the statement after let.
  • Parameters with blank lines between them stay on the line of =, where rustfmt moves them.
  • A parameter pattern that breaks stays aligned.
Style Guide
Follows it: neither

A return type on its own line#edition 2024

Input
1fn main() {
2 let a = |(first_element, second_element, third_element): (Aaaaaaaaaa, Bbbbbbbbbbb, Ccccccccc)| -> Result<Vec<u8>, Error> {
3 body();
4 };
5}
apfmt c9342b5
1fn main() {
2 let a = |(
3 first_element,
4 second_element,
5 third_element,
6 ): (Aaaaaaaaaa, Bbbbbbbbbbb, Ccccccccc)| -> Result<Vec<u8>, Error> {
7 body();
8 };
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let a = |(first_element, second_element, third_element): (
3 Aaaaaaaaaa,
4 Bbbbbbbbbbb,
5 Ccccccccc,
6 )|
7 -> Result<Vec<u8>, Error> {
8 body();
9 };
10}

A parameter pattern that breaks#edition 2024

Input
1fn f() {
2 let h = |x, (name, Remote { url, search_api_key, write_api_key })| x;
3}
apfmt c9342b5
1fn f() {
2 let h = |x,
3 (
4 name,
5 Remote {
6 url,
7 search_api_key,
8 write_api_key,
9 },
10 )| x;
11}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let h = |x,
3 (
4 name,
5 Remote {
6 url,
7 search_api_key,
8 write_api_key,
9 },
10 )| x;
11}

Blank lines between parameters#edition 2024

Input
1fn main() {
2 let f = |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
3
4 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
5 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32| first_parameter_xxxxxxxxxxxxx + 1;
6 let f = |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
7
8 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
9 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32| -> u32 { first_parameter_xxxxxxxxxxxxx + 1 };
10 let f = |a: u32,
11
12 b: u32| a + b;
13}
apfmt c9342b5
1fn main() {
2 let f = |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
3
4 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
5 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32| first_parameter_xxxxxxxxxxxxx + 1;
6 let f = |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
7
8 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
9 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32|
10 -> u32 { first_parameter_xxxxxxxxxxxxx + 1 };
11 let f = |a: u32, b: u32| a + b;
12}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let f =
3 |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
4
5 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
6 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32| first_parameter_xxxxxxxxxxxxx + 1;
7 let f = |first_parameter_xxxxxxxxxxxxxxxxxxxxx: u32,
8
9 second_parameter_yyyyyyyyyyyyyyyyyyyyyyyyy: u32,
10 third_parameter_zzzzzzzzzzzzzzzzzzzzzzz: u32|
11 -> u32 { first_parameter_xxxxxxxxxxxxx + 1 };
12 let f = |a: u32, b: u32| a + b;
13}

A type annotation that does not fit goes on the next line #

lowlettypegive-up

apfmt moves a type that fits nowhere on the line of : to the next line, also for a let; rustfmt leaves such a let unformatted.

Why The statement gets formatted instead of being left as written.
Details

When a type does not fit, both formatters keep it on the line of : and break inside it if they can, although the Style Guide breaks after : first. If no layout on that line fits, apfmt moves the type to the next line, block-indented, including for a let. rustfmt does that only for const and static, and leaves such a let unformatted.

Style Guide
Follows it: neither

Long types#edition 2024

Input
1fn f() {
2 let name: aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd = Ddddddd::new(1);
3 let name: aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd;
4 let Foo { aaaaaaa, bbbbbbb }: aaaa::bbbbbbbbbb::cccccccccccccc::Ddddddddddddddddddddddddddddddd = x;
5}
apfmt c9342b5
1fn f() {
2 let name:
3 aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd =
4 Ddddddd::new(1);
5 let name:
6 aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd;
7 let Foo { aaaaaaa, bbbbbbb }:
8 aaaa::bbbbbbbbbb::cccccccccccccc::Ddddddddddddddddddddddddddddddd = x;
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted3 lines over 100
1fn f() {
2 let name: aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd = Ddddddd::new(1);
3 let name: aaaa::bbbbbbbbbb::cccccccccccccc::Dddddddddddddddddddddddddddddddddddddddddddddddddddddd;
4 let Foo { aaaaaaa, bbbbbbb }: aaaa::bbbbbbbbbb::cccccccccccccc::Ddddddddddddddddddddddddddddddd = x;
5}

The bounds of a return type break where the line does not fit, block-indented #

lowfntype

apfmt breaks return type bounds before every + and block-indents them; rustfmt overflows or keeps them at the indentation of fn.

Why This is the Style Guide rule for + in types.
Details

After broken parameters, a return type with + that does not fit on the line of ) is broken before every +. rustfmt leaves it on one line, over max_width.

With no parameters to break, apfmt block-indents the + lines of a broken impl type: "Break types with + by breaking before the + and block-indenting the subsequent lines" (Style Guide). rustfmt keeps them at the indentation of fn.

Style Guide
Follows it: apfmt
Break types with + by breaking before the + and block-indenting the subsequent lines

After broken parameters and without any#edition 2024

Input
1impl X {
2 // The line does not fit: broken before every `+`
3 pub fn lines(
4 &self,
5 aaaaaaaaaaaa: Text<'a>,
6 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSlice<'a>> + 'a {
7 1
8 }
9 // Only ` {` does not fit: on its own line
10 pub fn brace(
11 &self,
12 aaaaaaaaaaaa: Text<'a>,
13 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSl<'a>> + 'a {
14 1
15 }
16 // Without parameters to break: block-indented
17 fn no_params() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>> + ExactSizeIterator<Item = RopeSliceeeeee<'a>> + 'a { 1 }
18 fn no_params_wider() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>> + ExactSizeIterator<Item = RopeSliceeeeeeeeeeeeeeeeeeeeeeeeeee<'a>> + 'a { 1 }
19}
apfmt c9342b5
1impl X {
2 // The line does not fit: broken before every `+`
3 pub fn lines(
4 &self,
5 aaaaaaaaaaaa: Text<'a>,
6 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>>
7 + ExactSizeIterator<Item = RopeSlice<'a>>
8 + 'a {
9 1
10 }
11 // Only ` {` does not fit: on its own line
12 pub fn brace(
13 &self,
14 aaaaaaaaaaaa: Text<'a>,
15 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSl<'a>> + 'a
16 {
17 1
18 }
19 // Without parameters to break: block-indented
20 fn no_params() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>>
21 + ExactSizeIterator<Item = RopeSliceeeeee<'a>>
22 + 'a {
23 1
24 }
25 fn no_params_wider() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>>
26 + ExactSizeIterator<Item = RopeSliceeeeeeeeeeeeeeeeeeeeeeeeeee<'a>>
27 + 'a {
28 1
29 }
30}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1impl X {
2 // The line does not fit: broken before every `+`
3 pub fn lines(
4 &self,
5 aaaaaaaaaaaa: Text<'a>,
6 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSlice<'a>> + 'a
7 {
8 1
9 }
10 // Only ` {` does not fit: on its own line
11 pub fn brace(
12 &self,
13 aaaaaaaaaaaa: Text<'a>,
14 ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSl<'a>> + 'a
15 {
16 1
17 }
18 // Without parameters to break: block-indented
19 fn no_params() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>>
20 + ExactSizeIterator<Item = RopeSliceeeeee<'a>>
21 + 'a {
22 1
23 }
24 fn no_params_wider() -> impl DoubleEndedIterator<Item = RopeSliceeeeeee<'a>>
25 + ExactSizeIterator<Item = RopeSliceeeeeeeeeeeeeeeeeeeeeeeeeee<'a>>
26 + 'a {
27 1
28 }
29}

A return type followed by ; is broken when the ; does not fit #

lowfnoverflow

apfmt breaks a return type when the ; after it does not fit; rustfmt lets the line overflow.

Why The line stays within max_width.
Details

When a function has a body and ) -> Ret fits but { does not, both put { on its own line. Without a body, rustfmt leaves ) -> Ret; on one line even when the ; makes it exceed max_width. apfmt breaks the generic arguments of the return type.

Style Guide
Does not settle this.

A return type without a function body#edition 2024max_width = 80tab_spaces = 2

Input
1trait T {
2 fn workspace_external_import_map_loade(&self) -> Result<&WorkspaceExternalImportMapLoaderRc<TSys>, WorkspaceDiscoverError>;
3}
apfmt c9342b5
1trait T {
2 fn workspace_external_import_map_loade(
3 &self,
4 ) -> Result<
5 &WorkspaceExternalImportMapLoaderRc<TSys>,
6 WorkspaceDiscoverError,
7 >;
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 80
1trait T {
2 fn workspace_external_import_map_loade(
3 &self,
4 ) -> Result<&WorkspaceExternalImportMapLoaderRc<TSys>, WorkspaceDiscoverError>;
5}

A use list after a too long path is broken #

lowuseoverflow

apfmt breaks a use list after a path that is too long; rustfmt leaves the line too long.

Why Less of the line overflows, and the Style Guide says how to break a list.
Details

When use path::{a, b}; exceeds max_width because of a long path, rustfmt leaves the line too long. apfmt breaks the list, as the Style Guide describes: "If an import does require multiple lines ..., then break after the opening brace and before the closing brace, use a trailing comma, and block indent the names". Less of the line then overflows. The path itself is never broken.

Style Guide
Follows it: apfmt
If an import does require multiple lines

A path that fills the line#edition 2024

Input
1use aaaaaaaaaaaaaaaaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccc::{ddddddddddddddddd, e};
apfmt c9342b51 line over 100
1use aaaaaaaaaaaaaaaaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccc::{
2 ddddddddddddddddd, e,
3};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1use aaaaaaaaaaaaaaaaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccc::{ddddddddddddddddd, e};

A broken use list with a comment stays filled #

lowusecomment

apfmt fills a broken use list that has a comment; rustfmt puts its items one per line.

Why The list looks the same as a list without a comment. Neither layout is clearly better.
Details

rustfmt puts the items of a broken use list one per line when the list has a comment. apfmt fills them on lines as in a list without one, and a trailing comment ends its line. The Style Guide does not say which is right.

Style Guide
Does not settle this.

Own-line and trailing comments#edition 2024

Input
1use a::{
2 // New layout types
3 CommandOrPlugin as ProtobufCommandOrPlugin, DumpScreenPayload, EditFilePayload, FloatingPaneCoordinates,
4 FloatingPaneLayout as ProtobufFloatingPaneLayout,
5};
6use b::{
7 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccc, // t
8 ddddddddddddddddd,
9};
apfmt c9342b5
1use a::{
2 // New layout types
3 CommandOrPlugin as ProtobufCommandOrPlugin, DumpScreenPayload, EditFilePayload,
4 FloatingPaneCoordinates, FloatingPaneLayout as ProtobufFloatingPaneLayout,
5};
6use b::{
7 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
8 ccccccccccccccccccccccccccc, // t
9 ddddddddddddddddd,
10};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::{
2 // New layout types
3 CommandOrPlugin as ProtobufCommandOrPlugin,
4 DumpScreenPayload,
5 EditFilePayload,
6 FloatingPaneCoordinates,
7 FloatingPaneLayout as ProtobufFloatingPaneLayout,
8};
9use b::{
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
11 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
12 ccccccccccccccccccccccccccc, // t
13 ddddddddddddddddd,
14};

Imports that differ only in the alias are sorted #

lowuse

apfmt sorts imports that differ only in the alias; rustfmt keeps their source order.

Why The Style Guide version-sorts the names, and a is a prefix of a as b.
Details

rustfmt compares a, a as b and a as c as equal and keeps their source order. apfmt sorts them, with no alias first and then by the alias. The Style Guide version-sorts the names, and a is a prefix of a as b.

Style Guide
Follows it: apfmt

In a list#edition 2024

Input
1use a::{d as e, c, b as x, b};
apfmt c9342b5
1use a::{b, b as x, c, d as e};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::{b as x, b, c, d as e};

Separate imports#edition 2024

Input
1use a::b;
2use a as c;
3use a as b;
4use a;
5use a::*;
6use a::{c, d};
apfmt c9342b5
1use a;
2use a as b;
3use a as c;
4use a::b;
5use a::*;
6use a::{c, d};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a as c;
2use a as b;
3use a;
4use a::b;
5use a::*;
6use a::{c, d};

Normalized imports #

lowuse

apfmt normalizes imports at any depth and keeps duplicate names; rustfmt does the opposite in both.

Why The Style Guide's normalizations apply at any depth, and it does not ask to remove duplicates.
Details

apfmt applies the Style Guide's normalizations at any depth. It removes an empty b::{} in a list, where rustfmt leaves use a::{ x}; for use a::{x, b::{}};, and removes the braces of a list that has become a single item.

rustfmt removes duplicate names in a list (use a::{b, b}; becomes use a::{b};). apfmt keeps them, because the Style Guide does not ask for their removal.

rustfmt can fail on such imports with the error "left behind trailing whitespace". apfmt does not.

Style Guide
Follows it: apfmt

An empty nested list#edition 2024

Input
1use a::{x, b::{}};
apfmt c9342b5
1use a::x;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::{ x};

A list that becomes a single item#edition 2024

Input
1use a::{c, d::{}};
apfmt c9342b5
1use a::c;
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::{ c};

A duplicate name#edition 2024

Input
1use a::{b, b};
apfmt c9342b5
1use a::{b, b};
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1use a::{b};

An index that does not fit is block indented #

lowexpression

apfmt block-indents an index that does not fit; rustfmt breaks before [.

Why This is the Style Guide rule for indexing.
Details

An index that does not fit on one line is block-indented between the brackets and never broken before [, as in the Style Guide section "Array accesses, indexing, and slicing". rustfmt breaks before [.

Style Guide
Follows it: apfmt

Three indexes in a row#edition 2024

Input
1fn main() {
2 let refs = &mut *values[aaaaaaaa + bbbbbbbb * cccccccc - dddddddd][eeeeeeee * ffffffff + gggggggg][hhhhhhhh - iiiiiiii * jjjjjjjj + kkkkkkkk];
3}
apfmt c9342b5
1fn main() {
2 let refs = &mut *values[aaaaaaaa + bbbbbbbb * cccccccc - dddddddd][
3 eeeeeeee * ffffffff + gggggggg
4 ][hhhhhhhh - iiiiiiii * jjjjjjjj + kkkkkkkk];
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let refs = &mut *values[aaaaaaaa + bbbbbbbb * cccccccc - dddddddd]
3 [eeeeeeee * ffffffff + gggggggg][hhhhhhhh - iiiiiiii * jjjjjjjj + kkkkkkkk];
4}

A call of a chain result belongs to the chain #

lowchaincall

apfmt treats a call of a chain's result as part of the chain; rustfmt indents its arguments from the start of the chain.

Why The arguments belong to the last element, as an index does.
Details

In a call of a chain's result (a.b()(x), a.handlers[i](x)), the arguments follow the last element on its line, as an index does, and a broken argument list is block-indented from that line. rustfmt indents it from the start of the chain.

Style Guide
Does not settle this.

A call of an indexed field#edition 2024

Input
1fn main() {
2 let x = self.registered_event_handlers_by_kind.handlers_for_this_kind[event_index](first_argument_xxxxxxx, second_argument_yyyyyyyyyyyzzzzzz);
3}
apfmt c9342b5
1fn main() {
2 let x = self
3 .registered_event_handlers_by_kind
4 .handlers_for_this_kind[event_index](
5 first_argument_xxxxxxx,
6 second_argument_yyyyyyyyyyyzzzzzz,
7 );
8}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let x = self
3 .registered_event_handlers_by_kind
4 .handlers_for_this_kind[event_index](
5 first_argument_xxxxxxx,
6 second_argument_yyyyyyyyyyyzzzzzz,
7 );
8}

More arguments hug as a last argument #

lowcallhuggingmacro

apfmt also hugs a const block or a macro call it cannot parse as a last argument; rustfmt puts the arguments one per line.

Why A const block is like other blocks.
Details

The last of several call arguments may hug the call when it is a const block (f(a, const {), like other blocks. rustfmt puts the arguments one per line. A macro call that is copied unchanged may also hug an array or a call as its last item (&[first, json!({), where rustfmt puts the items one per line.

Style Guide
Does not settle this.

A const block#edition 2024

Input
1fn main() {
2 constant(argument, const { let size = std::mem::size_of::<SomeType>(); size * 2 });
3}
apfmt c9342b5
1fn main() {
2 constant(argument, const {
3 let size = std::mem::size_of::<SomeType>();
4 size * 2
5 });
6}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 constant(
3 argument,
4 const {
5 let size = std::mem::size_of::<SomeType>();
6 size * 2
7 },
8 );
9}

A copied macro call#edition 2024

Input
1fn main() {
2 request("a", &json!({
3 "actions": [{ "selector": { "id": "1" }, "action": { "type": "pin", "position": 000000 } }]
4 }));
5}
apfmt c9342b5
1fn main() {
2 request("a", &json!({
3 "actions": [{ "selector": { "id": "1" }, "action": { "type": "pin", "position": 000000 } }]
4 }));
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn main() {
2 request(
3 "a",
4 &json!({
5 "actions": [{ "selector": { "id": "1" }, "action": { "type": "pin", "position": 000000 } }]
6 }),
7 );
8}

A closure behind & counts as another closure argument #

lowcallclosurehugging

apfmt counts a closure behind & as another closure argument; rustfmt does not.

Why & does not change what the argument is.
Details

The last of several call arguments overflows if it is a closure and "there are no other closure arguments" (Style Guide). apfmt looks through & and &mut, both for the last argument and for the others, so &|a| a + 1 counts as another closure. rustfmt hugs the last closure then, while it breaks the same call without the &.

Style Guide
Follows it: apfmt
there are no other closure arguments

&|a| in front of a closure#edition 2024

Input
1fn main() {
2 ref_closure_first(&|a| a + 1, |b| {
3 f(b);
4 g(b);
5 });
6}
apfmt c9342b5
1fn main() {
2 ref_closure_first(
3 &|a| a + 1,
4 |b| {
5 f(b);
6 g(b);
7 },
8 );
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 ref_closure_first(&|a| a + 1, |b| {
3 f(b);
4 g(b);
5 });
6}

A callee is broken only where the arguments cannot be #

lowcall

apfmt breaks a callee only where the arguments cannot be broken; rustfmt may break inside its generic arguments.

Why This is the Style Guide preference.
Details

"Prefer not to break a line in the callee expression" (Style Guide), so apfmt breaks the arguments first. rustfmt breaks inside the generic arguments of a callee path when that saves lines.

A callee that cannot be on one line keeps the arguments on its last line (})(input)) in both formatters. The Style Guide would put them one per line ("or the callee is multi-line"), which would break the common pattern of a closure called immediately.

A callee in parentheses stays together in both formatters.

Style Guide
Follows it: apfmt
Prefer not to break a line in the callee expression

Generic arguments of a callee#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 let arr = match arr.validity() {
6 Some(validity) => _rolling_apply_agg_window_nulls::<rolling::nulls::MaxWindow<_>, _, _, _>(values, validity, offset_iter, None),
7 None => unreachable!(),
8 };
9 }
10 }
11 }
12}
apfmt c9342b5
1fn main() {
2 {
3 {
4 {
5 let arr = match arr.validity() {
6 Some(validity) => {
7 _rolling_apply_agg_window_nulls::<rolling::nulls::MaxWindow<_>, _, _, _>(
8 values,
9 validity,
10 offset_iter,
11 None,
12 )
13 }
14 None => unreachable!(),
15 };
16 }
17 }
18 }
19}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 let arr = match arr.validity() {
6 Some(validity) => _rolling_apply_agg_window_nulls::<
7 rolling::nulls::MaxWindow<_>,
8 _,
9 _,
10 _,
11 >(values, validity, offset_iter, None),
12 None => unreachable!(),
13 };
14 }
15 }
16 }
17}

A series of casts breaks before the first as only #

lowexpression

apfmt breaks a series of casts before the first as only; rustfmt breaks before a later as.

Why This is the Style Guide rule.
Details

The Style Guide says: "if chaining a series of as casts that require line-breaking, and line-breaking before the first as suffices to make the remainder fit on the next line, don't break before any subsequent as; instead, leave the series of types all on the same line". rustfmt breaks before a later as instead.

Both formatters break a single cast before as, and both allow as T to follow a broken operand on its last line.

Style Guide
Follows it: apfmt
if chaining a series of as casts that require line-breaking, and line-breaking before the first as suffices to make the remainder fit on the next line, don't break before any subsequent as; instead, leave the series of types all on the same line

Three casts#edition 2024

Input
1fn main() {
2 let cstr = very_long_expression_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() as *const str as *const [u8] as *const std::os::raw::c_char;
3}
apfmt c9342b5
1fn main() {
2 let cstr = very_long_expression_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
3 as *const str as *const [u8] as *const std::os::raw::c_char;
4}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let cstr = very_long_expression_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() as *const str
3 as *const [u8] as *const std::os::raw::c_char;
4}

where after broken generics of a function is on the line of ) #

lowwheregenerics

apfmt writes where on the line of ) after broken generics; rustfmt puts it on its own line.

Why This is the Style Guide rule.
Details

"If immediately following a closing bracket of any kind, write the keyword where on the same line" (Style Guide). apfmt writes ) where after any broken signature of a function without a return type. rustfmt does so only when the parameters are broken: after broken generics followed by (), it puts where on its own line.

After broken parameters, both write ) where.

Style Guide
Follows it: apfmt
If immediately following a closing bracket of any kind, write the keyword where on the same line

Broken generics with no parameters#edition 2024

Input
1fn generics_only<TTTTTTTTTTTTTTTTTTTTTTTTTT: Clone, UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU: Default, VVVVVVVVVVV>() where T: Clone { body(); }
apfmt c9342b5
1fn generics_only<
2 TTTTTTTTTTTTTTTTTTTTTTTTTT: Clone,
3 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU: Default,
4 VVVVVVVVVVV,
5>() where
6 T: Clone,
7{
8 body();
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn generics_only<
2 TTTTTTTTTTTTTTTTTTTTTTTTTT: Clone,
3 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU: Default,
4 VVVVVVVVVVV,
5>()
6where
7 T: Clone,
8{
9 body();
10}

A where predicate on lifetimes breaks after : #

lowwhereoverflow

apfmt breaks a long where predicate on lifetimes after :; rustfmt leaves the line too long.

Why It is then like other bounds, and the line stays within max_width.
Details

A where predicate on lifetimes that does not fit on its line breaks after :, block-indented, like other bounds. rustfmt leaves the line too long.

Style Guide
Does not settle this.

A long predicate#edition 2024

Input
1fn long<F>(f: F) where 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + 'ccccccccccccccccc { a }
apfmt c9342b5
1fn long<F>(f: F)
2where
3 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
4 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + 'ccccccccccccccccc,
5{
6 a
7}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn long<F>(f: F)
2where
3 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + 'ccccccccccccccccc,
4{
5 a
6}

An empty where is removed #

lowwhere

apfmt removes a where without predicates, keeping its comments; rustfmt keeps it in some places.

Why A where without predicates has no effect, and open issues in rustfmt propose removing it there too.
Details

apfmt removes a where without predicates from every item, as rustfmt does, except that rustfmt keeps it after a return type and writes where { at column 0 when the source has where { on its own line in an indented item. Both are open issues in rustfmt (#5407, #6385).

With a comment right after or in front of where, apfmt keeps the comment and removes where, while rustfmt keeps where (fn f() where /* c */ {}). Code under #[rustfmt::skip] and macro arguments are not changed.

Style Guide
Does not settle this.
References
rustfmt#5407, rustfmt#6385

After a return type#edition 2024

Input
1fn f<T>(a: T) -> T where {
2 a
3}
apfmt c9342b5
1fn f<T>(a: T) -> T {
2 a
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f<T>(a: T) -> T where {
2 a
3}

On its own line in an indented item#edition 2024

Input
1mod m {
2 fn g() -> T
3 where {
4 a
5 }
6}
apfmt c9342b5
1mod m {
2 fn g() -> T {
3 a
4 }
5}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1mod m {
2 fn g() -> T
3where {
4 a
5 }
6}

A comment right after where#edition 2024

Input
1fn f() where /* c */ {}
apfmt c9342b5
1fn f() /* c */ {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() where /* c */ {}

A comment in front of where#edition 2024

Input
1fn comment_before() /* f */ where {}
apfmt c9342b5
1fn comment_before() /* f */ {}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn comment_before() /* f */ where {}

The syntax of ~const is kept #

lowgenerics

apfmt keeps ~const as written; rustfmt rewrites it to [const].

Why Changing the syntax of a bound is not a matter of layout.
Details

apfmt keeps the syntax of the source: T: ~const Clone stays, while rustfmt rewrites it to T: [const] Clone.

Style Guide
Does not settle this.

A bound#edition 2024

Input
1fn k<T: ~const Clone>() { a }
apfmt c9342b5
1fn k<T: ~const Clone>() {
2 a
3}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn k<T: [const] Clone>() {
2 a
3}

A struct pattern field is not broken on the next line #

lowpatternstruct

apfmt keeps a struct pattern field that must break anyway on the line of its name; rustfmt moves it to the next line.

Why Moving it would indent its fields two levels.
Details

A field pattern that does not fit on the line of its name moves to the next line if it fits there on one line, in both formatters. A pattern that has to break anyway stays on the line of the name in apfmt. rustfmt moves it to the next line too, so its fields are indented two levels.

Style Guide
Does not settle this.

A nested struct pattern#edition 2024

Input
1fn main() {
2 let SplitConfig { unified_read_pool_thread_cpu_overload_threshold_ratio: Foo { aaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbb }, .. } = x;
3}
apfmt c9342b5
1fn main() {
2 let SplitConfig {
3 unified_read_pool_thread_cpu_overload_threshold_ratio: Foo {
4 aaaaaaaaaa,
5 bbbbbbbbbbbbbbbbbbbbbbbbbbbb,
6 },
7 ..
8 } = x;
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 let SplitConfig {
3 unified_read_pool_thread_cpu_overload_threshold_ratio:
4 Foo {
5 aaaaaaaaaa,
6 bbbbbbbbbbbbbbbbbbbbbbbbbbbb,
7 },
8 ..
9 } = x;
10}

else of a let-else after a single-line initializer #

lowlet

apfmt follows the Style Guide for else after a single-line initializer; rustfmt moves the initializer to the next line at exactly max_width.

Why This is the Style Guide rule; rustfmt keeps a column free for a ; that a let-else does not have there.
Details

"If the let statement components preceding the else can be formatted on a single line, but the else { does not fit on the same line, break the line before the else" (Style Guide). rustfmt keeps a column free for the ; of a plain let, so when the pattern and the initializer take exactly max_width, it moves the initializer to the next line.

else { follows the initializer only when its last line is just closing delimiters at the indentation of let (Style Guide). After a chain whose last element follows the closing delimiter, that line is ).method(), so else goes on its own line. rustfmt puts .method() else { on a line of its own. After a broken pattern, ) else { stays on the last line of the initializer, where rustfmt writes ) and else { on separate lines. A pattern that fits on one line is not broken to keep the initializer on the line of =.

Style Guide
Follows it: apfmt
If the let statement components preceding the else can be formatted on a single line, but the else { does not fit on the same line, break the line before the else
Related
A last chain element follows the closing delimiter

Exactly max_width wide#edition 2024

Input
1fn f() {
2 let Some(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa else {
3 return;
4 };
5 // The last line of the initializer is not just closing delimiters: `else` on its own line
6 let Some(xxxxxxxxxxxxxxxxxxxxxxxx) = some_function_name(aaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccc).unwrap_or_default() else {
7 return;
8 };
9}
apfmt c9342b5
1fn f() {
2 let Some(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3 else {
4 return;
5 };
6 // The last line of the initializer is not just closing delimiters: `else` on its own line
7 let Some(xxxxxxxxxxxxxxxxxxxxxxxx) = some_function_name(
8 aaaaaaaaaaaaaaaaaaa,
9 bbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
10 ccccccccccccccc,
11 ).unwrap_or_default()
12 else {
13 return;
14 };
15}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 let Some(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) =
3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4 else {
5 return;
6 };
7 // The last line of the initializer is not just closing delimiters: `else` on its own line
8 let Some(xxxxxxxxxxxxxxxxxxxxxxxx) = some_function_name(
9 aaaaaaaaaaaaaaaaaaa,
10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
11 ccccccccccccccc,
12 )
13 .unwrap_or_default() else {
14 return;
15 };
16}

After a broken pattern#edition 2024

Input
1fn f() {
2 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd } = x else { return; };
3 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd } = f(x) else { return; };
4 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd } = x? else { return; };
5 let Some(Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dd }) = x else { return; };
6 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd }: T = x else { return; };
7 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd } = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb() else { return; };
8 // The initializer ends with `)` at the indentation of `let`: `) else {` (rustfmt breaks before `else`)
9 let Foo { aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, dddd } = some_function(aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc) else { return; };
10}
apfmt c9342b51 line over 100
1fn f() {
2 let Foo {
3 aaaaaaaaaaaaaaaaaaaaa,
4 bbbbbbbbbbbbbbbbbbbbbbbbbb,
5 cccccccccccccccccccccccccc,
6 dddd,
7 } = x
8 else {
9 return;
10 };
11 let Foo {
12 aaaaaaaaaaaaaaaaaaaaa,
13 bbbbbbbbbbbbbbbbbbbbbbbbbb,
14 cccccccccccccccccccccccccc,
15 dddd,
16 } = f(x)
17 else {
18 return;
19 };
20 let Foo {
21 aaaaaaaaaaaaaaaaaaaaa,
22 bbbbbbbbbbbbbbbbbbbbbbbbbb,
23 cccccccccccccccccccccccccc,
24 dddd,
25 } = x?
26 else {
27 return;
28 };
29 let Some(Foo {
30 aaaaaaaaaaaaaaaaaaaaa,
31 bbbbbbbbbbbbbbbbbbbbbbbbbb,
32 cccccccccccccccccccccccccc,
33 dd,
34 }) = x
35 else {
36 return;
37 };
38 let Foo {
39 aaaaaaaaaaaaaaaaaaaaa,
40 bbbbbbbbbbbbbbbbbbbbbbbbbb,
41 cccccccccccccccccccccccccc,
42 dddd,
43 }: T = x
44 else {
45 return;
46 };
47 let Foo {
48 aaaaaaaaaaaaaaaaaaaaa,
49 bbbbbbbbbbbbbbbbbbbbbbbbbb,
50 cccccccccccccccccccccccccc,
51 dddd,
52 } = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb()
53 else {
54 return;
55 };
56 // The initializer ends with `)` at the indentation of `let`: `) else {` (rustfmt breaks before `else`)
57 let Foo {
58 aaaaaaaaaaaaaaaaaaaaa,
59 bbbbbbbbbbbbbbbbbbbbbbbbbb,
60 cccccccccccccccccccccccccc,
61 dddd,
62 } = some_function(
63 aaaaaaaaaaaaaaaaaaaaaaaaa,
64 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
65 cccccccccccccccccccccccc,
66 ) else {
67 return;
68 };
69}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn f() {
2 let Foo {
3 aaaaaaaaaaaaaaaaaaaaa,
4 bbbbbbbbbbbbbbbbbbbbbbbbbb,
5 cccccccccccccccccccccccccc,
6 dddd,
7 } = x
8 else {
9 return;
10 };
11 let Foo {
12 aaaaaaaaaaaaaaaaaaaaa,
13 bbbbbbbbbbbbbbbbbbbbbbbbbb,
14 cccccccccccccccccccccccccc,
15 dddd,
16 } = f(x)
17 else {
18 return;
19 };
20 let Foo {
21 aaaaaaaaaaaaaaaaaaaaa,
22 bbbbbbbbbbbbbbbbbbbbbbbbbb,
23 cccccccccccccccccccccccccc,
24 dddd,
25 } = x?
26 else {
27 return;
28 };
29 let Some(Foo {
30 aaaaaaaaaaaaaaaaaaaaa,
31 bbbbbbbbbbbbbbbbbbbbbbbbbb,
32 cccccccccccccccccccccccccc,
33 dd,
34 }) = x
35 else {
36 return;
37 };
38 let Foo {
39 aaaaaaaaaaaaaaaaaaaaa,
40 bbbbbbbbbbbbbbbbbbbbbbbbbb,
41 cccccccccccccccccccccccccc,
42 dddd,
43 }: T = x
44 else {
45 return;
46 };
47 let Foo {
48 aaaaaaaaaaaaaaaaaaaaa,
49 bbbbbbbbbbbbbbbbbbbbbbbbbb,
50 cccccccccccccccccccccccccc,
51 dddd,
52 } = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb()
53 else {
54 return;
55 };
56 // The initializer ends with `)` at the indentation of `let`: `) else {` (rustfmt breaks before `else`)
57 let Foo {
58 aaaaaaaaaaaaaaaaaaaaa,
59 bbbbbbbbbbbbbbbbbbbbbbbbbb,
60 cccccccccccccccccccccccccc,
61 dddd,
62 } = some_function(
63 aaaaaaaaaaaaaaaaaaaaaaaaa,
64 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
65 cccccccccccccccccccccccc,
66 )
67 else {
68 return;
69 };
70}

A pattern is not broken to keep the initializer on the line#edition 2024

Input
1fn f() {
2 for (spec, obj) in &children {
3 let Some(child) = deno_core::cppgc::try_unwrap_cppgc_object::<ContextifyModuleXxxxxxxxxxxxxx>(scope, (*obj).into()) else {
4 continue;
5 };
6 let (aaaaaaa, bbbbbbb) = deno_core::cppgc::try_unwrap_cppgc_object_with_long_name(scope, (*obj).into()) else {
7 continue;
8 };
9 let Some(child): Option<Child> = deno_core::cppgc::try_unwrap_cppgc_object::<Module>(scope, (*obj).into()) else {
10 continue;
11 };
12 }
13}
apfmt c9342b5
1fn f() {
2 for (spec, obj) in &children {
3 let Some(child) =
4 deno_core::cppgc::try_unwrap_cppgc_object::<ContextifyModuleXxxxxxxxxxxxxx>(
5 scope,
6 (*obj).into(),
7 )
8 else {
9 continue;
10 };
11 let (aaaaaaa, bbbbbbb) =
12 deno_core::cppgc::try_unwrap_cppgc_object_with_long_name(scope, (*obj).into())
13 else {
14 continue;
15 };
16 let Some(child): Option<Child> =
17 deno_core::cppgc::try_unwrap_cppgc_object::<Module>(scope, (*obj).into())
18 else {
19 continue;
20 };
21 }
22}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn f() {
2 for (spec, obj) in &children {
3 let Some(child) = deno_core::cppgc::try_unwrap_cppgc_object::<ContextifyModuleXxxxxxxxxxxxxx>(
4 scope,
5 (*obj).into(),
6 ) else {
7 continue;
8 };
9 let (aaaaaaa, bbbbbbb) =
10 deno_core::cppgc::try_unwrap_cppgc_object_with_long_name(scope, (*obj).into())
11 else {
12 continue;
13 };
14 let Some(child): Option<Child> =
15 deno_core::cppgc::try_unwrap_cppgc_object::<Module>(scope, (*obj).into())
16 else {
17 continue;
18 };
19 }
20}

The right side of an if let guard moves after = as in if let #

lowmatchlet

apfmt moves the right side of an if let guard after =, as in if let; rustfmt breaks the pattern instead.

Why apfmt reads a match arm guard the same way as an if. Such guards are rare in practice.
Details

"Prefer breaking after the = for any let sub-expression in an if or while expression that does not fit" (Style Guide). apfmt reads a match arm guard the same way: the right side moves to the next line if it fits on one line there. rustfmt does so in if let, but in a guard it breaks the pattern.

Style Guide
Follows it: apfmt
Prefer breaking after the = for any let sub-expression in an if or while expression that does not fit

Guards of several shapes#edition 2024

Input
1fn main() {
2 match x {
3 // The right side does not fit on one line on the next line: both tuples break, as in `if let`
4 A if let (Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbbbbbbbbbbbbbbbbb, Ccccccccccccccc) = (aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccc) => { 1 }
5 // It fits there: it moves after `=`, as in `if let`
6 A if let Some(Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = compute(aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) => { 2 }
7 // A chain breaks on the line of `=`
8 A if let Some(Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = self.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.compute_something(aaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) => { 3 }
9 // A let chain is not affected
10 A if let Some(a) = b && let (Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbbbbbbbbbbbbbbbbb, Cccc) = (aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccc) => { 4 }
11 }
12}
apfmt c9342b51 line over 100
1fn main() {
2 match x {
3 // The right side does not fit on one line on the next line: both tuples break, as in `if let`
4 A if let (
5 Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
6 Bbbbbbbbbbbbbbbbbbbbbbbbbbbb,
7 Ccccccccccccccc,
8 ) = (
9 aaaaaaaaaaaaaaaaaaaaaaaaa,
10 bbbbbbbbbbbbbbbbbbbbbb,
11 cccccccccccccccc,
12 ) =>
13 {
14 1
15 }
16 // It fits there: it moves after `=`, as in `if let`
17 A if let Some(Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =
18 compute(aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) =>
19 {
20 2
21 }
22 // A chain breaks on the line of `=`
23 A if let Some(Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = self
24 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
25 .compute_something(aaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) =>
26 {
27 3
28 }
29 // A let chain is not affected
30 A if let Some(a) = b
31 && let (Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbbbbbbbbbbbbbbbbb, Cccc) = (
32 aaaaaaaaaaaaaaaaaaaaaaaaa,
33 bbbbbbbbbbbbbbbbbbbbbb,
34 cccccccccccccccc,
35 ) =>
36 {
37 4
38 }
39 }
40}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)1 line over 100
1fn main() {
2 match x {
3 // The right side does not fit on one line on the next line: both tuples break, as in `if let`
4 A if let (
5 Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
6 Bbbbbbbbbbbbbbbbbbbbbbbbbbbb,
7 Ccccccccccccccc,
8 ) = (
9 aaaaaaaaaaaaaaaaaaaaaaaaa,
10 bbbbbbbbbbbbbbbbbbbbbb,
11 cccccccccccccccc,
12 ) =>
13 {
14 1
15 }
16 // It fits there: it moves after `=`, as in `if let`
17 A if let Some(
18 Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
19 ) = compute(aaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) =>
20 {
21 2
22 }
23 // A chain breaks on the line of `=`
24 A if let Some(Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = self
25 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
26 .compute_something(aaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb) =>
27 {
28 3
29 }
30 // A let chain is not affected
31 A if let Some(a) = b
32 && let (Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbbbbbbbbbbbbbbbbb, Cccc) = (
33 aaaaaaaaaaaaaaaaaaaaaaaaa,
34 bbbbbbbbbbbbbbbbbbbbbb,
35 cccccccccccccccc,
36 ) =>
37 {
38 4
39 }
40 }
41}

A loop as a match arm body is in a block #

lowmatchloop

apfmt puts a loop as a match arm body in a block; rustfmt keeps it on the line of =>.

Why The Style Guide puts control-flow expressions in a block, and loop is one.
Details

The Style Guide puts a control-flow expression (if, loop, while, for) in a block as a match arm body. rustfmt does so for all but loop, which it keeps on the line of =>.

Style Guide
Follows it: apfmt

Each kind of control flow#edition 2024

Input
1fn f() {
2 match x {
3 R => loop { break },
4 S => while a { b },
5 T => for x in xs { y },
6 U => if a { b } else { c },
7 }
8}
apfmt c9342b5
1fn f() {
2 match x {
3 R => {
4 loop {
5 break;
6 }
7 }
8 S => {
9 while a {
10 b
11 }
12 }
13 T => {
14 for x in xs {
15 y
16 }
17 }
18 U => {
19 if a {
20 b
21 } else {
22 c
23 }
24 }
25 }
26}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 match x {
3 R => loop {
4 break;
5 },
6 S => {
7 while a {
8 b
9 }
10 }
11 T => {
12 for x in xs {
13 y
14 }
15 }
16 U => {
17 if a {
18 b
19 } else {
20 c
21 }
22 }
23 }
24}

Only unsafe blocks are on one line as statements #

lowblock

apfmt keeps only unsafe blocks on one line as statements; rustfmt also keeps async and const blocks on one line.

Why This is the Style Guide rule.
Details

A single-line block is "either used in expression position (not statement position) or is an unsafe block in statement position" (Style Guide). rustfmt breaks a plain block statement too, but puts other blocks, async { 1 }; and const { 1 };, on one line.

Style Guide
Follows it: apfmt
either used in expression position (not statement position) or is an unsafe block in statement position

Block statements#edition 2024

Input
1fn f() {
2 { f() }
3 { g() };
4 async { 1 };
5 unsafe { f() }
6 h();
7}
apfmt c9342b5
1fn f() {
2 {
3 f()
4 }
5 {
6 g()
7 };
8 async {
9 1
10 };
11 unsafe { f() }
12 h();
13}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 {
3 f()
4 }
5 {
6 g()
7 };
8 async { 1 };
9 unsafe { f() }
10 h();
11}

Or-patterns of single tokens are filled #

lowmatchpatterncomment

apfmt fills or-patterns of single tokens on lines whatever their width; rustfmt limits each alternative to 20 characters.

Why The Style Guide fills small alternatives, with no limit on their width.
Details

The Style Guide fills an or-pattern on lines when every alternative is small (a single token, & of one, or (one,)). rustfmt also requires each alternative to be at most 20 characters wide, so it puts longer names one per line, and it leaves room for => on every line of the pattern.

With a comment among the alternatives, a pattern that does not fit on one line has one alternative per line in apfmt, as a pattern with larger alternatives does. rustfmt leaves such a pattern as written, including its spacing. The Style Guide does not mention comments here.

Style Guide
Follows it: apfmt

Long and short names#edition 2024

Input
1fn f() {
2 match x {
3 Fffffffffffffffffffff | Gggggggggggggggggggggggg | Hhhhhhhhhhhhhhhhhhhhhhhh | Iiiiiiiiiiiiiiiii => 2,
4 Jjjj | Kkkk | Llll | Mmmm | Nnnn | Oooo | Pppp | Qqqq | Rrrr | Ssss | Tttt | Uuuu | Vvvv | Wwww => 3,
5 _ => 4,
6 }
7}
apfmt c9342b5
1fn f() {
2 match x {
3 Fffffffffffffffffffff | Gggggggggggggggggggggggg | Hhhhhhhhhhhhhhhhhhhhhhhh
4 | Iiiiiiiiiiiiiiiii => 2,
5 Jjjj | Kkkk | Llll | Mmmm | Nnnn | Oooo | Pppp | Qqqq | Rrrr | Ssss | Tttt | Uuuu | Vvvv
6 | Wwww => 3,
7 _ => 4,
8 }
9}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 match x {
3 Fffffffffffffffffffff
4 | Gggggggggggggggggggggggg
5 | Hhhhhhhhhhhhhhhhhhhhhhhh
6 | Iiiiiiiiiiiiiiiii => 2,
7 Jjjj | Kkkk | Llll | Mmmm | Nnnn | Oooo | Pppp | Qqqq | Rrrr | Ssss | Tttt | Uuuu
8 | Vvvv | Wwww => 3,
9 _ => 4,
10 }
11}

With comments among the alternatives#edition 2024

Input
1fn f() {
2 match x {
3 // An own-line comment
4 "_"
5 // c
6 |"a"| "b" |"c"| "d" => 1,
7 // A comment ending the line of an alternative
8 'a'|'b' // t
9 | 'c' => 2,
10 // Behind the operator
11 'd' | // t
12 'e'|'f' => 3,
13 'g'|
14 // c
15 'h'|'i' => 4,
16 // After every alternative
17 'j' // j
18 | 'k' // k
19 | 'l' => 5,
20 // On one line where it fits, also with a block comment
21 'm' /* c */ |'n'|'o' => 6,
22 // Without comments, filled
23 "abstract" | "as" | "async" | "await" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" => 7,
24 _ => 8,
25 }
26}
apfmt c9342b5
1fn f() {
2 match x {
3 // An own-line comment
4 "_"
5 // c
6 | "a"
7 | "b"
8 | "c"
9 | "d" => 1,
10 // A comment ending the line of an alternative
11 'a'
12 | 'b' // t
13 | 'c' => 2,
14 // Behind the operator
15 'd' // t
16 | 'e'
17 | 'f' => 3,
18 'g'
19 // c
20 | 'h'
21 | 'i' => 4,
22 // After every alternative
23 'j' // j
24 | 'k' // k
25 | 'l' => 5,
26 // On one line where it fits, also with a block comment
27 'm' /* c */ | 'n' | 'o' => 6,
28 // Without comments, filled
29 "abstract" | "as" | "async" | "await" | "become" | "box" | "break" | "const" | "continue"
30 | "crate" | "do" => 7,
31 _ => 8,
32 }
33}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)left unformatted1 line over 100
1fn f() {
2 match x {
3 // An own-line comment
4 "_"
5 // c
6 |"a"| "b" |"c"| "d" => 1,
7 // A comment ending the line of an alternative
8 'a'|'b' // t
9 | 'c' => 2,
10 // Behind the operator
11 'd' | // t
12 'e'|'f' => 3,
13 'g'|
14 // c
15 'h'|'i' => 4,
16 // After every alternative
17 'j' // j
18 | 'k' // k
19 | 'l' => 5,
20 // On one line where it fits, also with a block comment
21 'm' /* c */ |'n'|'o' => 6,
22 // Without comments, filled
23 "abstract" | "as" | "async" | "await" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" => 7,
24 _ => 8,
25 }
26}

todo! and unimplemented! are format-string macros #

lowmacro

apfmt treats todo! and unimplemented! as format-string macros; rustfmt does not.

Why Both macros take a format string, so the Style Guide layout applies to them.
Details

The Style Guide has a layout for macros that take a format string: the arguments in front of the format string on one line, the format string on its own line, and the arguments after it on one line, when they are all simple. rustfmt has a fixed list of such macros that does not include todo! and unimplemented!, so it puts their arguments one per line.

Style Guide
Follows it: apfmt

Both macros#edition 2024

Input
1fn f() {
2 todo!("a very long format string with {} and {} and {} placeholders xxxxxxxxxxxxxxxxxxx", e, g);
3 unimplemented!("a very long format string with {} and {} and {} placeholders xxxxxxxxxx", e, g);
4}
apfmt c9342b5
1fn f() {
2 todo!(
3 "a very long format string with {} and {} and {} placeholders xxxxxxxxxxxxxxxxxxx",
4 e, g
5 );
6 unimplemented!(
7 "a very long format string with {} and {} and {} placeholders xxxxxxxxxx",
8 e, g
9 );
10}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn f() {
2 todo!(
3 "a very long format string with {} and {} and {} placeholders xxxxxxxxxxxxxxxxxxx",
4 e,
5 g
6 );
7 unimplemented!(
8 "a very long format string with {} and {} and {} placeholders xxxxxxxxxx",
9 e,
10 g
11 );
12}

{ after an unsafe block ending a broken head #

lowifblock

apfmt puts { on its own line after an unsafe block ending a broken head; rustfmt writes } {.

Why It is then like any broken control line. Neither layout is clearly better.
Details

When a broken control line ends with an unsafe block, apfmt puts { on its own line, as after any broken control line. rustfmt puts it after the closing }, as } {. apfmt keeps a block on its operator's line only for a plain block as the last operand.

Style Guide
Does not settle this.

An unsafe operand#edition 2024

Input
1fn main() {
2 {
3 {
4 {
5 {
6 let (b, count) = if count == 0 && unsafe { std::ptr::eq(b.as_ptr().add(b.len()), bytes.as_ptr().add(bytes.len())) } {
7 1
8 } else {
9 2
10 };
11 }
12 }
13 }
14 }
15}
apfmt c9342b5
1fn main() {
2 {
3 {
4 {
5 {
6 let (b, count) = if count == 0
7 && unsafe {
8 std::ptr::eq(b.as_ptr().add(b.len()), bytes.as_ptr().add(bytes.len()))
9 }
10 {
11 1
12 } else {
13 2
14 };
15 }
16 }
17 }
18 }
19}
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {
2 {
3 {
4 {
5 {
6 let (b, count) = if count == 0
7 && unsafe {
8 std::ptr::eq(b.as_ptr().add(b.len()), bytes.as_ptr().add(bytes.len()))
9 } {
10 1
11 } else {
12 2
13 };
14 }
15 }
16 }
17 }
18}

An empty file stays empty #

lowwhitespace

apfmt leaves an empty file empty; rustfmt writes a single line break.

Why Nothing is added to a file without code or comments.
Details

A file with no code or comments (empty, or only whitespace) is formatted to an empty file. rustfmt writes a single line break. Any other output ends with exactly one line break in both formatters.

Style Guide
Does not settle this.

An empty file#edition 2024

Input
(empty file)
apfmt c9342b5
(empty file)
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1

A file of only whitespace#edition 2024

Input
1
2··
apfmt c9342b5
(empty file)
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1

newline_style = "Auto" keeps the line endings of the file #

lowwhitespaceconfig

With newline_style = "Auto", apfmt keeps the line endings of the file; rustfmt converts \r\n to \n when it changes anything.

Why That is what the option is documented to do.
Details

rustfmt documents Auto (the default) as "Use the line ending style of the first line ending found in the file". In practice, it always writes \n when formatting changes anything in the file, so a file with \r\n line endings is converted unless it is already formatted. apfmt does what the option says and writes the line endings of the first line of the source, so such a file keeps \r\n on every line. Unix, Windows and Native behave as in rustfmt.

Style Guide
Does not settle this.

A file with \r\n line endings that needs formatting#edition 2024

Input
1fn main() { }␍
2fn g() { }␍
apfmt c9342b5
1fn main() {}␍
2fn g() {}␍
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {}
2fn g() {}

A file with \r\n line endings that is already formatted#edition 2024

rustfmt leaves such a file as it is, so both keep \r\n.

Input
1fn main() {}␍
2fn g() {}␍
apfmt c9342b5 · rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
1fn main() {}␍
2fn g() {}␍