rust-lang / rust-lang/rustfmt

My code needs two passes to be formatted correctly

Open
#5,193 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-matches C-bug only-with-option
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

When making the following change from https://github.com/msrd0/gotham_restful/tree/5181b4b448003a06e01d50609371a9578db9d067, rustfmt (rustfmt 1.4.38-nightly (5e57faa 2022-01-19)) needs two passes to correctly format the code:

My Change:

$ git diff src/openapi/router.rs |cat
diff --git a/src/openapi/router.rs b/src/openapi/router.rs
index dbcecb8a5..ec5fdcc21 100644
--- a/src/openapi/router.rs
+++ b/src/openapi/router.rs
@@ -137,8 +137,7 @@ macro_rules! implOpenapiRouter {
 					Method::PATCH => item.patch = Some(op),
 					Method::TRACE => item.trace = Some(op),
 					method => warn!(
-						"Ignoring unsupported method '{}' in OpenAPI Specification",
-						method
+						"Ignoring unsupported method '{method}' in OpenAPI Specification"
 					)
 				};
 				(self.0).openapi_builder.add_path(path, item);

First Pass of rustfmt:

$ git diff src/openapi/router.rs |cat
diff --git a/src/openapi/router.rs b/src/openapi/router.rs
index dbcecb8a5..e81e0640f 100644
--- a/src/openapi/router.rs
+++ b/src/openapi/router.rs
@@ -136,10 +136,9 @@ macro_rules! implOpenapiRouter {
 					Method::HEAD => item.head = Some(op),
 					Method::PATCH => item.patch = Some(op),
 					Method::TRACE => item.trace = Some(op),
-					method => warn!(
-						"Ignoring unsupported method '{}' in OpenAPI Specification",
-						method
-					)
+					method => {
+						warn!("Ignoring unsupported method '{method}' in OpenAPI Specification")
+					},
 				};
 				(self.0).openapi_builder.add_path(path, item);
 

Second Pass of rustfmt:

$ git diff src/openapi/router.rs |cat
diff --git a/src/openapi/router.rs b/src/openapi/router.rs
index dbcecb8a5..33937d612 100644
--- a/src/openapi/router.rs
+++ b/src/openapi/router.rs
@@ -136,10 +136,9 @@ macro_rules! implOpenapiRouter {
 					Method::HEAD => item.head = Some(op),
 					Method::PATCH => item.patch = Some(op),
 					Method::TRACE => item.trace = Some(op),
-					method => warn!(
-						"Ignoring unsupported method '{}' in OpenAPI Specification",
-						method
-					)
+					method => {
+						warn!("Ignoring unsupported method '{method}' in OpenAPI Specification")
+					}
 				};
 				(self.0).openapi_builder.add_path(path, item);
 

Notice the }, was changed to } in the second pass.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in src/openapi/router.rs and run rustfmt 1.4.38-nightly on the shown change. Compare the first and second formatting passes, focusing on the macro arm where the unsupported-method warning changes from }, to }. Done means one rustfmt pass produces stable output for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.