Skip to content

rustfmt will format comment even not covered by file-lines option #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BusyJay opened this issue Apr 9, 2017 · 3 comments
Closed

rustfmt will format comment even not covered by file-lines option #1445

BusyJay opened this issue Apr 9, 2017 · 3 comments
Labels
a-comments bug Panic, non-idempotency, invalid code, etc.

Comments

@BusyJay
Copy link
Contributor

BusyJay commented Apr 9, 2017

Consider following file

struct A {
t: i64
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
                                         // test
    }
}

If I format it using command rustfmt --write-mode=diff --file-lines '[{"file": "src/lib.rs", "range": [0, 2]}]' src/lib.rs, only first two lines should be formatted, but I got these output:

Warning: Extra file listed in file_lines option '/tmp/testfmt/src/lib.rs'
Diff in src/lib.rs at line 1:
 struct A {⏎
-t: i64⏎
+    t: i64,⏎
 }⏎
 ⏎
 #[cfg(test)]⏎
Diff in src/lib.rs at line 6:
 mod tests {⏎
     #[test]⏎
     fn it_works() {⏎
-                                         // test⏎
+        // test⏎
     }⏎
 }⏎

It tries to format the comment at L9 too.

@nrc nrc added bug Panic, non-idempotency, invalid code, etc. a-comments labels Apr 9, 2017
@kamalmarhubi
Copy link
Contributor

As mentioned in #1514 (comment) I'm not so sure this is a bug as much as incomplete implementation. I had named the flag --experimental-file-lines but changed it to --file-lines during review.

@fintelia
Copy link
Contributor

No, rustfmt shouldn't try to format code blatantly outside of file_lines. However, I believe this issue was resolved by #1510.

@topecongiro
Copy link
Contributor

Closed via #1510.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

5 participants