Commit Graph

2406 Commits

Author SHA1 Message Date
Michael Bebenita
c2ae39e77a Add max_width option for all heuristics.
This is useful when working with very small max_widths like 79 chars.
2018-07-17 13:17:36 -04:00
Nick Cameron
b28a0cd6e6 Fix an anomaly with comments and array literals
Closes #2842
2018-07-17 15:40:19 +12:00
Nick Cameron
d911b640d1
Merge pull request #2823 from fwalch/default-newline-style
Change default newline style to "Native"
2018-07-17 11:18:10 +12:00
Stéphane Campinas
86018133a0
removed unused max_width argument of rewrite_string function 2018-07-14 19:33:26 +02:00
Stéphane Campinas
472a2ed0f6
fix rewrite_string when a line feed is present in a sequence of whitespaces, resulting in strange formatting 2018-07-14 19:22:31 +02:00
Nick Cameron
229a55248b address reviewer comments 2018-07-12 22:21:07 +12:00
Nick Cameron
486f8fd8e7 Fixup formatting of tests and source 2018-07-12 21:37:28 +12:00
Nick Cameron
a4cdb68925 Improve formatting of series of binop expressions
This commit changes the handling of binops (and potentially other pairs), where
the expressions are logically a list, e.g., `a + b + c`. It makes the single
line vs multi-line approaches explicit and introduces a lowering step.

This improves formatting in a number of places, mostly improving consistency of
formatting with very short sub-expressions, but also some weird indentation.

Closes #2802
2018-07-12 21:37:28 +12:00
Nick Cameron
b68fd9e6bf Move pair handling to its own module 2018-07-12 21:37:28 +12:00
Nick Cameron
b6ea973d19 Factor out PairParts::infix 2018-07-12 21:37:28 +12:00
Seiichi Uchida
60ce411b53 Format async closure 2018-07-09 23:20:53 +09:00
Eric Huss
800e488de8 Fix help for --help=file-lines
Due to the way getopts works, it requires the equals sign.
2018-07-05 22:50:23 -07:00
Florian Walch
363363d066 test: Assert CRLF line endings on Windows 2018-07-02 23:43:59 +02:00
Florian Walch
9d8f3812cc Change default newline style to "Native"
Fixes #2626.
2018-07-02 23:16:17 +02:00
Nick Cameron
5e5992517d Update rustc-ap-syntax 2018-07-02 09:34:55 +12:00
Nick Cameron
d5cb93216b
Merge pull request #2822 from topecongiro/issue-2782
Avoid panicking on deeply nested expressions
2018-07-01 14:38:30 +12:00
topecongiro
ebb1626264 Flatten multiple empty blocks at once 2018-07-01 10:51:36 +09:00
topecongiro
54af8b578e Factor out block_can_be_flattened 2018-07-01 10:49:05 +09:00
topecongiro
e7c6c29562 Avoid panicking on deeply nested expressions 2018-07-01 10:46:32 +09:00
topecongiro
5a3640da69 Return the trimmed original snippet when formatting macro def failed 2018-07-01 09:59:53 +09:00
Nick Cameron
888abbb0ec
Merge pull request #2820 from scampi/defaults
[wip] remove some defaults
2018-07-01 10:57:31 +12:00
Stéphane Campinas
f7a25a1177
warn on use of default value for an option 2018-06-30 17:03:18 +02:00
topecongiro
57a6cae49f Fix span bug when searching for the closing paren 2018-06-30 19:21:15 +09:00
topecongiro
bc16d8864a Fix compile error from breaking changes in libsyntax 2018-06-30 15:53:28 +09:00
Seiichi Uchida
cc2afeca9e Fix compile errors from breaking changes 2018-06-28 16:26:10 +09:00
Nick Cameron
3abebf95ce Apply short function call heuristic to attributes
Closes #2620
2018-06-26 15:18:17 +12:00
Nick Cameron
42f03458dd Refactor and fixup attribute formatting
Preserves trailing commas (except in derives where we follow function args).
Correctly uses `#` vs `#!` for derives.
Uses block indent for derives, fixes #2805.
2018-06-26 15:18:17 +12:00
Nick Cameron
be4d37da4b Indent a match guard if the pattern is multiline
Closes #2377
2018-06-26 15:18:17 +12:00
Seiichi Uchida
3027c21371 Handle raw identifiers 2018-06-25 23:36:45 +09:00
Nick Cameron
ca1c13a896
Merge pull request #2804 from Mike-Baker/mb-strip-vert-in-match-arms
Strip leading `|` in match arm patterns
2018-06-25 21:02:24 +12:00
topecongiro
e5e1e0cea8 Fix compile errors from breaking changes in libsyntax
cc https://github.com/rust-lang/rust/pull/48149.
2018-06-25 15:24:00 +09:00
Mike Baker
1d4b988414 Strip leading | in match arm patterns
This addresses issue #2621

This commit turns out to be a partial revert of
ea3c01e337

The rationale is that a `|` character preceding a match pattern is not
semantically relevant and therefore should be considered a
style/formatting choice.

A discussion concluded that the best way to emit consistent formatting
here was to strip the leading `|`

This removes the match_with_beginning_vert test because it was asserting
the old behaviour which has been changed, it adds a new test
(issue_2621) which should be a more comprehensive check of the behavior
of `|` in match arms.

Discussion at https://github.com/rust-lang-nursery/fmt-rfcs/issues/119
2018-06-25 00:53:15 +01:00
Nick Cameron
87edd75ecf TODO -> FIXME
Or just delete

Closes #25
2018-06-22 14:42:27 +12:00
Nick Cameron
1ead31ae9d
Merge pull request #2795 from jechase/issue-2794
Add test and fix for #2794
2018-06-20 10:35:16 +12:00
Nick Cameron
fb5513564e
Merge pull request #2785 from wada314/issue-2728
Fix #2728.
2018-06-20 10:32:46 +12:00
Josh Chase
ee5ff2d9e8 Add flag to the ListFormatting struct for nested imports 2018-06-19 12:13:35 -04:00
Josh Chase
2077855e00 Remove NestedImport tactic 2018-06-19 12:13:26 -04:00
Shohei Wada
036244cdce Fix #2728. 2018-06-19 20:51:49 +09:00
Nick Cameron
488e6fda12 Remove some unnecessary pubs 2018-06-19 14:36:50 +12:00
Nick Cameron
261238ea51 Change use_small_heuristics to an enum and stabilise
Since it is now an enum, we can be future compatible since we can add variants
for different heuristics.

Closes #1974
2018-06-19 13:28:27 +12:00
Seiichi Uchida
0ec1533054
Merge pull request #2779 from thibaultdelor/stableApi
Improve end lines handling
2018-06-11 11:38:26 +09:00
Tibo Delor
2e90c4314c
Stop delaying Trailing whitespace error reporting 2018-06-10 14:19:09 +10:00
Tibo Delor
42efae5944
Clean Up code where last whitspace tracking isn't used 2018-06-10 14:07:33 +10:00
Tibo Delor
6b00b8b302
Move newline logic inside the formatting process.
Why?:
 - Conceptually it sounds right
 - Absolutely all write modes where doing it anyway
 - It was done several times in some in case
 - It greatly simplify the code
2018-06-10 00:25:47 +10:00
Tibo Delor
8c32a9d909
Parse Error return an Error instead of a successful empty response 2018-06-10 00:25:06 +10:00
Nick Cameron
34067a1c4c
Merge pull request #2775 from topecongiro/macro-def-with-complex-macro
Change format_snippet to return None when it has failed to format macro call
2018-06-08 08:50:35 +12:00
Seiichi Uchida
19054347ca Fix test failures 2018-06-07 15:20:01 +09:00
Seiichi Uchida
c95fa8cbe2 Return None when the formatting of macro failed in format_snippet 2018-06-07 12:33:33 +09:00
Seiichi Uchida
d1477ca1de Add a field in Summary for notiyfing about formatting failure of macro 2018-06-07 12:32:58 +09:00
Seiichi Uchida
94e68b1eb6 Set the flag in RewriteContext when rewriting macro call failed 2018-06-07 12:32:10 +09:00
csmoe
c791a54ff4 repair break_label format 2018-06-07 11:21:52 +08:00
Nick Cameron
da30d235a4
Merge pull request #2771 from topecongiro/issue-2746
Fix poor formatting of impls
2018-06-06 14:38:42 +12:00
Nick Cameron
576e9af0ae
Merge pull request #2769 from topecongiro/issue-2765
Put each nested import on its own line
2018-06-06 14:37:25 +12:00
Seiichi Uchida
a4db62368b Respect empty_item_single_line config option when formatting empty impls 2018-06-06 10:55:25 +09:00
Seiichi Uchida
d51b99f5d7 Put the where clause next to the closing bracket only when it is not indented 2018-06-06 10:54:40 +09:00
Seiichi Uchida
2e4376d29c Do not put where clause on a single with multi-lined type 2018-06-06 10:46:49 +09:00
Seiichi Uchida
8d01496c9e Remove unreachable lines 2018-06-06 10:46:18 +09:00
Seiichi Uchida
42ab258757 Put each nested import on its own line
while putting non-nested imports on the same line as much as possible.
2018-06-05 19:58:44 +09:00
Nick Cameron
f545dfe95e Fix tests 2018-06-05 20:58:02 +12:00
Nick Cameron
95b4978baa
Merge pull request #2767 from topecongiro/issue-2759
Fix breaking code block with `#` in doc comments
2018-06-05 20:28:32 +12:00
king6cong
56a3d039ce update rustfmt flags that should work without targets 2018-06-05 15:43:48 +08:00
Seiichi Uchida
604764abe1 Trim custom comment prefix even when we failed to format code block 2018-06-05 15:58:14 +09:00
Seiichi Uchida
1b4778d0bc Handle code block with indented escapce character 2018-06-05 15:57:49 +09:00
Seiichi Uchida
a70213b009 Trim custom comment prefixes from code block without closing backticks 2018-06-05 15:57:03 +09:00
Nick Cameron
d9149fb52e
Merge pull request #2741 from csmoe/where_brace
Remove newline in empty impl
2018-06-05 18:04:22 +12:00
Seiichi Uchida
b4987d848b Allow using mixed layout with comments 2018-06-05 13:43:01 +09:00
csmoe
faa41168a9 format exceeded comments 2018-06-05 07:35:51 +08:00
csmoe
8874c95a00 recover suppressed comma 2018-06-04 19:10:09 +08:00
csmoe
0468c134f4 snuggle where 2018-05-31 18:33:45 +08:00
csmoe
8536c288f2 suppress and compress 2018-05-31 17:58:48 +08:00
Seiichi Uchida
2f65852946 Do not insert spaces around braces with empty body or multiple lines 2018-05-30 08:44:57 +09:00
Seiichi Uchida
966fe8d705 Fix treating the delimiter right after repeat as repeat as well 2018-05-30 08:44:57 +09:00
Alex Butler
f390626778 Update rustc-ap-* -> 149 (#2748) 2018-05-30 08:22:49 +09:00
Alex Butler
cd925f0140
Add mercy for devs that run cargo test without building 2018-05-29 00:38:47 +01:00
Alex Butler
5473c3fd92 Update rustc-ap-* -> 148 2018-05-28 23:41:08 +01:00
Nick Cameron
173ae0d7b9 0.8.2 2018-05-28 11:47:21 +12:00
Nick Cameron
d930617cbe Make Range public
0.8.1
2018-05-28 11:30:58 +12:00
Nick Cameron
8674ab9a42 FIXME for <- 2018-05-28 11:15:15 +12:00
Nick Cameron
0a2ec411ae
Merge pull request #2739 from thibaultdelor/fixWindowsTest
Fix test failing on windows due to crlf
2018-05-28 10:13:09 +12:00
Nick Cameron
1d5da1011f
Merge pull request #2733 from topecongiro/issue-2727
Trim unnecessary whitespaces between a macro call and a semicolon
2018-05-28 10:12:23 +12:00
topecongiro
8fea1fcfe5 Add a comment to describe hack 2018-05-28 06:44:52 +09:00
Tibo
33a46581f7
Fix test failing on windows due to crlf 2018-05-27 03:20:02 +10:00
Pazzaz
f711078126 Seperate and optimize grapheme conditions 2018-05-24 21:32:01 +02:00
Pazzaz
a1d137116b Avoid unnecessary comparisons with cur_end 2018-05-24 21:32:01 +02:00
topecongiro
eedd275cd9 Do not call format_missing_inner in a common case
We use `format_missing()` to extract a missing comment between a macro
(or alike) and a trailing semicolon. This commit just tries to avoid calling
`format_missing_inner` in the common case where there is no such comment.

This is a hack, ideally we should fix a possible bug in `format_missing_inner`
or refactor `visit_mac` and `rewrite_macro`, but this should suffice to fix the
issue.
2018-05-24 00:14:05 +09:00
topecongiro
5d067f16e0 Format code block with sharp prefix
by hiding lines with a leading `#` behind a custom comment.
2018-05-23 23:30:07 +09:00
topecongiro
f1974e2209 Handle code block in doc comment without rust prefix 2018-05-23 23:29:28 +09:00
Nick Cameron
353816c596
Merge pull request #2730 from topecongiro/issue-2704
Disallow combining a method call with prefix or suffix
2018-05-23 20:10:49 +12:00
topecongiro
8cb2b8e909 Cargo fmt 2018-05-23 07:22:59 +09:00
topecongiro
fbcc886338 Disallow combining a method call with prefix or suffix 2018-05-23 07:22:42 +09:00
topecongiro
a6b32d944c Fix breaking changes from introducing AnonConst 2018-05-23 06:04:32 +09:00
Seiichi Uchida
1b3257df8b
Merge pull request #2726 from csmoe/label_break
Format label break
2018-05-22 07:16:05 +09:00
csmoe
64768cf932 fix label prefix 2018-05-21 22:37:55 +08:00
csmoe
150765d755 format label break 2018-05-21 13:30:07 +08:00
Nick Cameron
632fab4c95 documentation 2018-05-21 15:54:56 +12:00
Nick Cameron
6541be3c6f Replace use_colored_tty with iatty crate 2018-05-21 15:32:27 +12:00
Nick Cameron
9a7fac63c8 Remove format_and_emit_report from the API
Also changes the header/footer stuff
2018-05-21 15:09:17 +12:00
Nick Cameron
95d6b64829 Replace WriteMode with EmitMode and backup bool 2018-05-21 14:14:09 +12:00
Nick Cameron
843c12601a Use our own FileName struct rather than exporting libsyntax's 2018-05-21 12:08:39 +12:00
Nick Cameron
539d4d9665 Refactor CliOptions 2018-05-21 11:27:25 +12:00
Nick Cameron
abb253df8b Rationalise result and error types 2018-05-21 08:58:53 +12:00
Nick Cameron
432b1cb253 Rationalise error types
cc #2639
2018-05-21 08:58:53 +12:00
Nick Cameron
760af6cfc9 Make format_snippet and format_code_block private
cc #2639
2018-05-21 08:58:53 +12:00
Nick Cameron
e83c7ff005
Merge pull request #2723 from topecongiro/rustc-ap-syntax
Update rustc-ap-syntax
2018-05-19 11:47:36 +12:00
topecongiro
912e4bdc90 Fix breaking changes from rustc-ap-syntax
cc https://github.com/rust-lang/rust/pull/50045.
2018-05-19 08:43:00 +09:00
Thomas Lively
5d56adb10c Fix position of auto in auto trait declaration 2018-05-18 17:25:33 -04:00
Nick Cameron
2ee8b0e4c5 Remove remove_blank_lines_at_start_or_end_of_block
cc #1974
2018-05-18 16:56:55 +12:00
Nick Cameron
dd9c15ad01 Unstabilise unstable_features
cc #1974
2018-05-18 16:53:08 +12:00
Nick Cameron
a70f71610c stabilise remove_nested_parens and set default to true 2018-05-18 16:46:22 +12:00
Nick Cameron
8afe367510 stabilise shorthand options
cc #1974
2018-05-18 16:38:09 +12:00
Nick Cameron
d726492e65 Remove spaces_within_parens_and_brackets
cc #1974
2018-05-18 16:35:09 +12:00
Nick Cameron
7b6d2b4699 Stabilise reorder_imports and reorder_modules 2018-05-18 16:04:09 +12:00
Nick Cameron
416bc4c353 Unstabilise comments options
cc #1974
2018-05-18 16:02:05 +12:00
Nick Cameron
1452349966 Exit with 1 for license check in --check mode
Closes #2707
2018-05-18 15:30:32 +12:00
Shotaro Yamada
d1e2b80fb9 Use saturating_sub 2018-05-15 20:41:43 +09:00
Nick Cameron
390a284851 Give a deprecation warning on rustfmt_skip and an error on rustfmt:: other than skip 2018-05-14 18:10:46 +12:00
Nick Cameron
51f566062f Update uses of rustfmt_skip to rustfmt::skip 2018-05-14 16:25:10 +12:00
Nick Cameron
de950c2973 Skip on rustfmt::skip as well as rustfmt_skip 2018-05-14 16:13:21 +12:00
Nick Cameron
7eb8bdbbd2 Format attributes with paths 2018-05-14 16:04:15 +12:00
Nick Cameron
a3c85cdc41 Reorder the --help message 2018-05-14 11:07:54 +12:00
Nick Cameron
6d0695303a Make some write modes unstable 2018-05-14 10:55:16 +12:00
Nick Cameron
3b23a98d00 Support unstable options
cc #1976
2018-05-14 10:20:51 +12:00
Nick Cameron
5d9f5aa05a Replace --write-mode with --emit
cc #1976
2018-05-13 14:13:24 +12:00
Nick Cameron
8396da1882 Add --backup flag 2018-05-13 13:18:08 +12:00
Pazzaz
1c1763c7ae Remove unnecessary use of Box in format_function_type 2018-05-12 10:53:06 +02:00
Seiichi Uchida
1b1eccc553
Fix build failure (#2699) 2018-05-12 10:36:34 +09:00
Nick Cameron
eca7796fb1 Replace --dump-minimal-config and --dump-default-config with --print-config
cc #1976
2018-05-11 20:43:08 +12:00
Nick Cameron
4d9de48e06 Add --check flag.
cc #1976
2018-05-11 20:26:00 +12:00
Nick Cameron
798bffb8b1 --help options
cc #1976
2018-05-11 20:12:16 +12:00
Nick Cameron
1869888b1a Remove --verbose-diff
Use `--verbose` instead

cc #1976
2018-05-11 13:58:34 +12:00
Nick Cameron
55ac062da0 Add --quiet flag, remove Plain write mode
cc #1976
2018-05-11 13:50:30 +12:00
Nick Cameron
5dba81bbbf
Merge pull request #2687 from Marwes/issue_2641
fix: Don't insert an extra brace in macros with native newlines
2018-05-09 13:18:27 +12:00
Nick Cameron
659d0c9741
Merge pull request #2684 from topecongiro/issue-2175
Apply small parent heuristic only when the chain is at the beginning of the line
2018-05-09 13:16:26 +12:00
Alex Crichton
47742807f7 Ensure tests pass on the beta compiler
Also add a travis matrix entry for emulating the beta tests
2018-05-08 18:05:08 -07:00
Markus Westerlind
4c9ef93df7 fix: Don't insert an extra brace in macros with native newlines
Due to `format_snippet` formatting the input with \r\n the subtraction
would wouldn't give a length that removed the }

Fixes #2641
2018-05-08 20:34:44 +02:00
Alex Crichton
a72be170d7 Fix rustfmt tests in the Rust repo
Two tests were executing `cargo run` but `cargo` is not ambiently available to
execute. Instead it's best to execute the rustfmt binary directly, which is
always assembled as part of `cargo test`.
2018-05-08 07:32:00 -07:00
topecongiro
bd25c7d0f7 Cargo fmt 2018-05-08 06:25:48 +09:00
topecongiro
0ec311ee07 Apply small parent rule only when there is small offset 2018-05-08 06:25:06 +09:00
Nick Cameron
f46f4b5f66
Merge pull request #2675 from flodiebold/non-modrs-mods
Fix handling of modules in non_modrs_mods style
2018-05-07 11:23:14 +12:00
Nick Cameron
bd7ae5e89b
Merge pull request #2682 from topecongiro/issue-2670
Do not duplicate attributes on use items
2018-05-07 11:21:02 +12:00
Nick Cameron
4bbd5c4ae5
Merge pull request #2681 from topecongiro/issue-2680
Error on self_tests when there are lines that exceed max width
2018-05-07 11:20:33 +12:00
Florian Diebold
e65aa302d3 Turn the nonmodrs-mods test into a standard idempotence test
We need to skip children on foo.rs, since the parser will not find bar from that
file, but with that, the test works fine.
2018-05-06 13:08:43 +02:00
topecongiro
e59ceaf954 Do not duplicate attributes on use items 2018-05-06 17:01:14 +09:00
Florian Diebold
215baae223 Add a test for non-mod.rs mods 2018-05-06 09:58:03 +02:00
Florian Diebold
cf573e8157 Fix handling of modules in non_modrs_mods style
We need to keep track of the module relative to which we're resolving paths,
instead of always passing None.

Fixes #2673.
2018-05-06 09:58:03 +02:00
topecongiro
51c07f4335 Fix up lines exceeding max width 2018-05-06 16:17:09 +09:00
topecongiro
5f05987211 Use rustfmt.toml when running self_tests 2018-05-06 16:16:58 +09:00
topecongiro
1f738ea208 Cargo fmt 2018-05-06 15:22:29 +09:00
topecongiro
f8439ce8fe Put operands on its own line when each fits in a single line 2018-05-06 15:22:17 +09:00
topecongiro
f885039e6c Do not overflow a long item
Take the first line's width of a single item into account when
trying to overflow something.

Closes #2676.
2018-05-06 12:12:16 +09:00