Commit graph

411 commits

Author SHA1 Message Date
Nick Cameron
3d4bc8c84a Merge pull request #1033 from marcusklaas/assignment-break
Add test for general assignment breaks
2016-06-05 18:06:08 +01:00
Marcus Klaas
05188deadc Add test for general assignment breaks 2016-06-04 11:00:01 +02:00
Marcus Klaas
b3488c6186 Fix constraints on pattern formatting of else arms 2016-06-03 23:18:19 +02:00
Nick Cameron
0087306761 Merge pull request #1016 from rust-lang-nursery/try-double-indent
Treat chains with just expr? specially.
2016-06-01 12:28:36 +01:00
lqd
b6263735b1 Add support for the default keyword (#1025)
Adds support for Defaultness on impl methods.
Fixes #945
2016-05-31 19:48:49 +02:00
Kamal Marhubi
9fa5a91fc5 visitor: Handle specified line ranges in visit_stmt
This commit adds a very rough implementation of handling the specified
line ranges in `config.file_lines_map` for statements. It reformats a
statement if its span is fully contained in the set of lines specified
for the file.

The implementation here is intended as a proof of concept, and
demonstration that the machinery added in the preceding commits is
functional. A final implementation would likely hook in via the
`Rewrite` trait.

Refs #434
2016-05-31 01:33:11 +02:00
Marcus Klaas
98c0570a28 Format non-statement if-else expressions on a single line 2016-05-29 17:58:38 +02:00
Nick Cameron
bbb6038b92 Treat chains with just expr? specially.
Fixes #1004
2016-05-29 09:32:48 +01:00
Kamal Marhubi
66cac1f3e9 Handle pub(restricted) (#1013)
* Handle pub(restricted)

This commit properly handles pub(restricted) as introduced in RFC 1422
[0]. The syntax support was added in #971, but they were not correctly
formatted.

[0] https://github.com/rust-lang/rfcs/blob/master/text/1422-pub-restricted.md

Fixes #970

* Drop #[inline] attribute on format_visibility

* Make newly non-failing functions return String

The change to `format_visibiilty` means that `format_header` and
`format_unit_struct` can no longer fail. Their return type is updated to
reflect that.
2016-05-28 00:58:25 +02:00
Nick Cameron
6e01fac285 Merge pull request #1008 from rust-lang-nursery/hrtb
Don't ignore universal quantification in function types
2016-05-28 10:08:00 +12:00
Nick Cameron
0fae34dfa1 Don't ignore universal quantification in function types
Fixes #1006
2016-05-27 15:09:04 -07:00
Nick Cameron
d633e831ba Merge pull request #1009 from rust-lang-nursery/fn-args-1
Fix off by 2 error in function sigs
2016-05-28 10:04:04 +12:00
Nick Cameron
882ef8cc82 Fix off by 2 error in function sigs
Fixes #1000

This is a little conservative in some cases, but better than being wrong in others.
2016-05-27 15:05:15 -07:00
Nick Cameron
d6bcfceb7e Don't put a newline before ? when it is the second sub-expression in a chain (#1012)
Fixes #1003
2016-05-27 10:33:19 +02:00
Nick Cameron
775de8a62b Optionally put short struct variants on one line (#997)
Closes #418
2016-05-18 22:38:49 +02:00
Nick Cameron
9589cac62d Format inline attributes on out-of-line modules (#996)
Fixes #838
2016-05-18 22:36:59 +02:00
Srinivas Reddy Thatiparthy
952a6beb51 change normalise spelling to American version - normalize as American english is more common across programming community 2016-05-15 22:24:46 +05:30
Marcus Klaas
eae2921e14 Bootstrap it. Hard. 2016-05-12 21:50:43 +02:00
Marcus Klaas
cd158cecc8 Add try macro to try shorthand conversion tests 2016-05-12 21:15:06 +02:00
Marcus Klaas
ee7b5805fc Format try shorthand 2016-05-09 20:07:59 +02:00
Aaron Gallagher
96d59366fc Don't misplace the :: on associated items.
The rewritten location of the :: on global paths for qpaths was wrong.
2016-05-02 17:11:22 -07:00
Nick Cameron
c696dcf8da Handle attributes on modules (#968)
* Handle attributes (including doc comments) on inline modules

Closes #22
Closes #684

* Tweak the rules for changing indentation in comments (to do it less often).
2016-05-02 10:54:25 +02:00
Nick Cameron
de2b8d98ea Merge pull request #960 from rust-lang-nursery/big-closures
Block indent large closures and field/method chains
2016-04-28 09:49:08 +12:00
Nick Cameron
fcd2021583 Add visual indent tests for chains 2016-04-28 08:08:54 +12:00
Nick Cameron
9188ec0f7f Bail out on recovered errors. (#965)
Closes #915
Closes #930
Closes #931
2016-04-27 21:08:44 +02:00
Nick Cameron
a9c3108c9c Change defaults and update tests and source
New defaults are `Tabbed` for `chain_indent` and `chain_base_indent`, and `5` for `closure_block_indent_threshold`.
2016-04-22 19:18:48 +12:00
Nick Cameron
9761cf71d8 Tests 2016-04-22 18:53:39 +12:00
mrBliss
b0755581ca Format visibility of associated consts (#953)
Fixes #951.
2016-04-19 20:19:14 +02:00
Marcus Klaas
f364a7ec43 Add option to force explicit extern ABI's 2016-04-18 18:39:40 +02:00
Thia Wyrod
d773cc5327
Added loop/match brace style control option
This adds Allman style loop/match braces as an alternative to the current
default style.
2016-04-17 14:52:04 -06:00
Thia Wyrod
5bd6036218
Added option to configure if/else brace style 2016-04-17 14:48:51 -06:00
Marcus Klaas
63f0fc9641 Fix off-by-one error in pattern formatting 2016-04-16 22:42:52 +02:00
Nick Cameron
41e037da7e Merge pull request #941 from marcusklaas/type-ascription
Format type ascription
2016-04-16 16:42:56 +12:00
Marcus Klaas
d98e22c971 Check length of break and continue expressions 2016-04-15 18:11:29 +02:00
Marcus Klaas
45a83d18cc Format type ascription 2016-04-15 17:56:43 +02:00
Nick Cameron
7a758ea20a Fix closures again (#937)
* Fix closures again

Closes #934

Oh god, the rules for parsing closures are even more messed up than I thought - whether or not there is an inner block or depends not only on if there are braces, but also if there is a return type for the closure (!) and if there are statements in the block.

* Fix overflow
2016-04-15 10:52:08 +02:00
Nick Cameron
7bda8659ec Merge pull request #935 from marcusklaas/issue-770
Add regression test for issue 770
2016-04-15 08:13:26 +12:00
Marcus Klaas de Vries
320df84e96 Fix brace indentation for impl items (#927) 2016-04-14 20:42:38 +02:00
Marcus Klaas
ba9d64aba5 Add regression test for issue 770 2016-04-14 20:41:23 +02:00
Nick Cameron
c7780fdfd8 Be careful about where we change braces in closures
And some general refactoring of closure code.

Fixes #863
2016-04-14 09:05:42 +12:00
Nick Cameron
eadc878de0 Handle variadic function types
Closes #842
2016-04-12 10:47:35 +12:00
Nick Cameron
2f5f0a454a Merge pull request #912 from rust-lang-nursery/pat-simple-mixed
Change the logic around breaking multiple patterns in match arms
2016-04-12 10:47:08 +12:00
Nick Cameron
ce97bc08be Merge pull request #896 from erikjohnston/fn_arg_one_line
Add fn_arg_one_line option
2016-04-12 10:44:01 +12:00
Nick Cameron
5dc3283e49 Reviewer comments - mostly fix rewrite_guard 2016-04-12 10:30:57 +12:00
Nick Cameron
afc8be1d79 Change the logic around breaking multiple patterns in match arms
Refactor to use the list code, don't preserve original stacking-ness, base vertical vs mixed formatting on complexity of the patterns.

Closes #386
2016-04-12 09:23:37 +12:00
Nick Cameron
492b26cf04 Empty structs and struct lits (#920)
* Handle empty struct lits

Closes #835

* Don't crash on empty struct defs.

Not a great fix, but better than crashing.
2016-04-11 21:05:54 +02:00
Nick Cameron
7ac354fd09 Don't be so aggressie about line-breaking strings (#911)
We will no longer break in the middle of words, only at whitespace or punctuation.

This means we sometimes over-run, but that seems better than some of the bad splits we see.

Closes #369
2016-04-11 20:45:47 +02:00
Erik Johnston
4c9dd747bf Fix long generic indent 2016-04-07 20:29:05 +01:00
Erik Johnston
4edc6f1a4e Add variant to fn_args_layout 2016-04-07 20:01:16 +01:00
Erik Johnston
57847e451a Add fn_arg_one_line option
If set, arguments will be kept on one line if they fit. Currently only
applies when `fn_args_layout` is set to `Block`.

This commit also fixes a bug where newlines were inserted inbetween
argument brackets when there were no arguments and `fn_args_layout` was
set to `Block`.
2016-04-02 00:25:35 +01:00
Erik Johnston
8219d15291 Fix incorrect indent with fn_args_layout: Block
The closing parenthesis for the arg list was written on a new line
without first applying the appropriate indent.
2016-04-01 23:01:49 +01:00
Nick Cameron
5b11d2e80f Merge pull request #892 from marcusklaas/closed-ranges
Format closed ranges
2016-03-31 13:47:09 +13:00
Marcus Klaas de Vries
50820c6a43 Merge pull request #883 from marcusklaas/macro-with-name
Properly format macro's with an extra ident
2016-03-30 02:03:28 +02:00
Marcus Klaas
9eee93306a Format closed ranges 2016-03-29 23:58:45 +02:00
Marcus Klaas
9e5c0390a0 Properly format macro's with an extra ident 2016-03-29 23:16:40 +02:00
Nick Cameron
cfc9f70116 Merge pull request #885 from marcusklaas/empty-trait-type-params
Remove trailing whitespace for fn types /w non-unit return
2016-03-29 08:17:52 +13:00
Nick Cameron
7d66861b82 Merge pull request #882 from marcusklaas/empty-makro-issues
Fix issues with empty macros with curly braces
2016-03-29 08:14:27 +13:00
Marcus Klaas
0142191e51 Remove trailing whitespace for fn types /w non-unit return 2016-03-27 20:40:23 +02:00
Marcus Klaas
0e0cf976c9 Fix issues with empty macros with curly braces 2016-03-27 13:44:40 +02:00
Marcus Klaas
03bf1ceeb9 Fix tuple destructuring in impl fns 2016-03-27 13:07:28 +02:00
Marcus Klaas de Vries
8fd95df54a Merge pull request #868 from rust-lang-nursery/tuple-wide
Don't apply the function args heuristic to tuple lits.
2016-03-24 14:57:24 +01:00
Marcus Klaas de Vries
ca757183fe Merge pull request #864 from Venti-/fn-density
Add option for vertical function argument list
2016-03-22 10:14:04 +01:00
Marcus Klaas de Vries
6f2bb908bb Merge pull request #866 from rust-lang-nursery/empty-extern
Keep empty extern blocks on one line
2016-03-16 18:06:25 +01:00
Connor Brewster
0a665aaceb Fixed nitpicks
Removed unneeded comment
Commented line wrapping conditions
Removed prefix param on `rewrite_associated_type`
Merged `rewrite_associated_static` into `rewrite_static`
Added extra tests
2016-03-15 14:08:12 -06:00
Connor Brewster
2793b4090c Added tests 2016-03-14 20:05:20 -06:00
Nick Cameron
9d8ce54428 Don't apply the function args heuristic to tuple lits.
Closes #450
Closes #510
2016-03-14 20:51:06 +13:00
Nick Cameron
96a2f25788 Keep empty extern blocks on one line
Closes #462
2016-03-14 18:55:55 +13:00
Ari Koivula
8d299210a6 Add independent test for Vertical rustfmt-fn_args_density 2016-03-14 04:03:33 +02:00
Ari Koivula
f4171e97eb Add test for vertical fn_args_density 2016-03-14 02:02:37 +02:00
Connor Brewster
3163071c75 Updated to latest rustfmt 2016-03-12 11:09:27 -07:00
Connor Brewster
35dfcc0078 Adding trait formatting
trait header formatting finished
generic formatting finished
added basic trait bounds formatting
2016-03-11 14:18:30 -07:00
Amanieu d'Antras
ef03dcaa7f Add a test for #850 2016-03-09 02:44:01 -08:00
Vincent Esche
a0567d4063 Fix for issue #811 (falsely inserted "::" in paths with parameterized trait cast). 2016-03-01 16:39:43 +01:00
Nick Cameron
d86cfb357a Format all patterns (well, except macros)
Fixes #18
Fixes #672
2016-02-12 14:59:13 +13:00
Marcus Klaas de Vries
9c969ca6fb Merge pull request #786 from rust-lang-nursery/str-leave
Don't reformat strings if we don't have to.
2016-02-03 06:11:01 +01:00
Kamal Marhubi
2b991bc260 tests: Use Result::expect() throughout
`Result::expect()` was added in Rust 1.4. Using it tidies up the code,
and also helps by printing error details, eg, printing syntax error
details if a regex fails to compile. It adds a colon followed by the
`Debug` output from any error, making the periods in messages
unnecessary.
2016-01-31 13:10:09 -05:00
Nick Cameron
a0e85f9a5f Put empty modules on one line
Fixes #463
2016-01-28 19:53:41 +13:00
Nick Cameron
02302d2800 Don't reformat strings if we don't have to.
Specifically if no line exceeds the allowed width and we aren't moving the string to a new offset
2016-01-28 19:14:08 +13:00
DarkDrek
feb09a42f5 Fix #784 2016-01-27 02:18:05 +01:00
Nick Cameron
4344c51c80 Merge pull request #783 from jwazny/issue-588
Added where_trailing_comma option.
2016-01-26 22:23:05 +13:00
Jeremy Wazny
d23628c91b Added tests. 2016-01-26 16:55:51 +11:00
Kevin Yeh
7fc70a1753 Add item macro tests 2016-01-24 13:11:18 -06:00
Kevin Yeh
f01ed6f507 Format item macros 2016-01-22 13:43:18 -06:00
Nick Cameron
f0ca7aec24 Fix an off-by-one error due to the comma in a struct lit field
Also allows splitting the field expression on a new line after the field name.

Fixes #698
2016-01-14 20:26:15 +13:00
Marcus Klaas de Vries
ba465e0fc2 Merge pull request #766 from ConnorGBrewster/fix-#489
Added option for tighter punctuation in types. fixes #489
2016-01-12 22:52:34 +01:00
Marcus Klaas de Vries
4cefecb495 Merge pull request #768 from DarkDrek/amend-to-fix-#447
fixes parsing issue #767
2016-01-12 21:53:19 +01:00
Connor Brewster
7f8b9bd356 Added test case 2016-01-12 13:51:32 -07:00
Marcus Klaas de Vries
b99e8eda29 Merge pull request #757 from ConnorGBrewster/fix-#650
Fix for #650
2016-01-12 21:17:45 +01:00
DarkDrek
937e26d4e1 fixes parsing issue #767 2016-01-12 21:13:59 +01:00
Connor Brewster
d7a3256d40 If where is on the same line as the impl, { is put on the same line fixes #650
factored if clause into a separate function
2016-01-11 21:26:45 -07:00
DarkDrek
20ccc7bf8e Removed the failing test part since it will work when #754 is accepted 2016-01-12 03:09:19 +01:00
DarkDrek
4da91e7df2 Handle more possible comment position for if else
Extended the test with the new possiblecomment positions
2016-01-12 03:08:48 +01:00
DarkDrek
b0eb0f5daa Keep comments between if and else blocks. Fixes #447 2016-01-12 03:08:16 +01:00
Connor Brewster
6b741a7194 Where clause is on same line as fn if fn is empty fix-#760
only applies if fn_empty_single_line is set to true
2016-01-10 22:06:06 -07:00
Gaëtan Cassiers
9f98f725cb Detect when comments disappear
When the reformatted code doesn't contain the same quantity of comments
as the original code, use the original code instead of the reformatted
code.
This is done for all expressions and `let` statements.

This should be used at the finest grained level possible, to avoid that
a small disappearing comment prevents a big chunk of code to be
reformatted.

Kind of fixes (avoid disappearing comments, but prevents a good
formatting is such case) #285 #225 #563 #743
2016-01-10 15:20:58 +01:00
Seo Sanghyeon
16b348dd9c Add commas after skipped arms when needed 2016-01-08 22:15:54 +09:00
Seo Sanghyeon
f9f7235c1b Trailing commas for wildcard arms 2016-01-06 11:02:01 +09:00
Marcus Klaas
291aa1b228 Make fn argument formatting more resilient for complex self types 2015-12-27 14:25:37 +01:00
Nick Cameron
71508b310b Merge pull request #728 from marcusklaas/typed-mut-self
format typed mut self
2015-12-27 09:18:20 +13:00
Marcus Klaas
954dd0869e Preserve mutability for typed self arguments 2015-12-25 19:07:51 +01:00