rust-lang / rust-lang/rustfmt

Incorrect indentation for multiline logical expression

Open
#3,167 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-binary-ops A-comments I-poor-formatting P-medium
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Before:

     // http://tools.ietf.org/html/rfc6265#section-5.1.4
     pub fn path_match(request_path: &str, cookie_path: &str) -> bool {
         // A request-path path-matches a given cookie-path if at least one of
         // the following conditions holds:
         // The cookie-path and the request-path are identical.
         request_path == cookie_path ||

         (request_path.starts_with(cookie_path) && (
             // The cookie-path is a prefix of the request-path, and the last
             // character of the cookie-path is %x2F ("/").
             cookie_path.ends_with("/") ||
             // The cookie-path is a prefix of the request-path, and the first
             // character of the request-path that is not included in the cookie-
             // path is a %x2F ("/") character.
             request_path[cookie_path.len()..].starts_with("/")
         ))
    }

After:

     // http://tools.ietf.org/html/rfc6265#section-5.1.4
     pub fn path_match(request_path: &str, cookie_path: &str) -> bool {
         // A request-path path-matches a given cookie-path if at least one of
         // the following conditions holds:
         // The cookie-path and the request-path are identical.
         request_path == cookie_path ||
            (request_path.starts_with(cookie_path) &&
                (
                    // The cookie-path is a prefix of the request-path, and the last
                    // character of the cookie-path is %x2F ("/").
                    cookie_path.ends_with("/") ||
            // The cookie-path is a prefix of the request-path, and the first
            // character of the request-path that is not included in the cookie-
            // path is a %x2F ("/") character.
            request_path[cookie_path.len()..].starts_with("/")
               ))
    }

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

Reproduce the issue by running rustfmt on the Rust snippet in the report and compare the output with the expected indentation. Trace the formatter entry point responsible for multiline logical expressions, then add or update coverage for this example and verify the formatted output matches the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.