Commit Graph

282 Commits

Author SHA1 Message Date
Eli Friedman
1c235de97d Fix crash speculatively parsing macro arguments as expressions.
The problem is essentially that if we try to parse a token tree using a
CodeMap different from the one the tree was originally parsed with,
spans become nonsense. Since CodeMaps can't be cloned, we're basically
forced to use the original ParseSess for additional parsing.

Ideally, rustfmt would be a bit more clever and figure out how to parse
macro arguments based on the definition of the macro itself, rather than
just guessing that a particular token sequence looks like an expression,
but this is good enough for now.

Fixes #538.
2015-10-27 23:41:32 -07:00
Marcus Klaas
d122ad5adc Address some issues with multiline patterns in let statements 2015-10-24 13:13:15 +02:00
Ravi Shankar
d135217db2 show rustfmt coverage! 2015-10-24 15:22:37 +05:30
Eli Friedman
be9e7dc689 Don't use visit::walk_*. Instead, recurse by hand.
This is much more straightforward to understand given how rustfmt
rewriting works, and it avoids walking into expressions in unexpected
places.

Fixes #513. Fixes #514.
2015-10-21 13:46:13 -07:00
Marcus Klaas
e8447a8210 Fix large block comments 2015-10-19 23:06:36 +02:00
Marcus Klaas
3970748f59 Remove overflow indentation 2015-10-19 23:06:36 +02:00
Marcus Klaas
11756d2ef8 Refactor enum formatting 2015-10-19 21:28:05 +02:00
Marcus Klaas
7e0456b852 Format visibility for statics and consts 2015-10-19 20:08:03 +02:00
Marcus Klaas
3ce425c9ed Factor out common item indentation idiom 2015-10-18 22:59:39 +02:00
Marcus Klaas
1a7d39041e Format constants and static variables 2015-10-18 21:36:26 +02:00
Marcus Klaas
b039e3a8c3 Force semicolons after break/continue/return. Remove after blocks. 2015-10-15 19:55:42 +02:00
Nick Cameron
6600cd341a Format inner and outer attributes separately.
Actually just skips inner attributes, because its a pain to track them, and lets missed spans handle them.

Closes #413
2015-10-08 17:20:19 +13:00
Marcus Klaas de Vries
5eeae3944e Merge pull request #404 from marcusklaas/rewrite-list-fmt
List formatting refactoring
2015-10-06 22:29:52 +02:00
Marcus Klaas
199d40fa55 Increase default function call width limit 2015-10-06 22:27:11 +02:00
Marcus Klaas
84718b5b90 Format rustfmt's own indices 2015-10-02 11:48:52 +02:00
Nick Cameron
617eed353c Changes to rustfmt source 2015-09-26 18:29:48 +12:00
Nick Cameron
99d71a164a Changes to source formatting 2015-09-26 13:58:12 +12:00
Marcus Klaas
a7690cb1e5 Make rewrite_string return Option<String> 2015-09-25 13:01:20 +02:00
Marcus Klaas
71faa8984d Format foreign functions and statics 2015-09-21 20:02:45 +02:00
Marcus Klaas
f8e74bfa2c Place the closing brace of an inline mod on a new line 2015-09-20 14:22:12 +02:00
Pavel Sountsov
01bdcd0014 Remove unnecessary config parameter from format_missing_with_indent. 2015-09-19 10:44:28 -07:00
Pavel Sountsov
620650219e Use the block_indent inside visit_expr.
This seems to pass all the tests and greatly improves the formatting output
when using hard tabs.
2015-09-19 10:36:46 -07:00
Pavel Sountsov
03e1b27826 Add Indent::none(), remove make_indent. 2015-09-19 10:36:45 -07:00
Pavel Sountsov
d4108a3029 Initial implementation of hard tab indentation. 2015-09-19 10:36:45 -07:00
Marcus Klaas
e72d488281 Refactor test code
No longer use callbacks or thread::catch_panic; reduce stdout spew; guard against rustfmt breaking the column limit.
2015-09-18 22:34:46 +02:00
Marcus Klaas
f751356910 Format macro invocations 2015-09-16 20:26:14 +02:00
Marcus Klaas
a9814149c9 Align dots in chained expressions 2015-09-11 00:53:01 +02:00
Marcus Klaas
659c9b9037 Update indentation heuristics for single arg functions 2015-09-11 00:52:20 +02:00
Marcus Klaas
c680bb4030 Implement basic chain formatting 2015-09-11 00:52:16 +02:00
Marcus Klaas
d05a41c773 Add failure mode to write_list 2015-09-07 20:35:25 +02:00
Andre Bogus
d6c652e33c code improvements suggested by clippy 2015-09-04 23:39:33 +02:00
Nick Cameron
a5f8b37eeb Format match expressions properly when they appear on an overflowing line. 2015-09-02 14:29:47 +12:00
Marcus Klaas
85ddf35385 Rustup
Fix breakage caused by rust commit 2076cdd.
2015-09-01 20:28:38 +02:00
Gaëtan Cassiers
5e445697ce Implement Rewrite for [ast::Attribute] 2015-08-27 22:29:07 +02:00
Simon Bernier St-Pierre
6adb6a1d1a Fix build on nightly
https://github.com/rust-lang/rust/pull/27857
2015-08-25 17:37:48 -04:00
Marcus Klaas
120fd2426e Format assignment 2015-08-25 21:43:13 +02:00
Ivan Apachev
c7e6d0b54a Replace uses of x.len() == 0 by x.is_empty() #187 2015-08-25 01:07:48 +03:00
Marcus Klaas
c8fd23ca68 Refactor closure formatting routine 2015-08-20 23:05:41 +02:00
Nick Cameron
a43e2b5ae8 Formatting 2015-08-20 08:11:14 +12:00
Marcus Klaas
41bca58100 Format paths 2015-08-16 22:53:06 +02:00
Gaëtan Cassiers
0eab4bf430 Remove ChangeSet of FmtVisitor 2015-08-02 13:12:51 +02:00
Gaëtan Cassiers
0e10329dc7 Separate modules and files listing of reformatting
As suggested in #141
Closes #156
2015-08-02 13:07:27 +02:00
Marcus Klaas
0f640b06dd Properly format unsafe blocks 2015-08-02 12:40:02 +02:00
Marcus Klaas
54a96355dd Phase out token::get_ident in favour of ToString
token::get_ident was removed in rust commit 00a5e66f81
2015-07-31 13:10:19 +02:00
cassiersg
92b3f69934 Add a helper method to format imports 2015-07-25 19:00:38 +02:00
Gaëtan Cassiers
30b16bc474 Move 'use' to Rewrite
Implements Rewrite for ViewPath

Behavior change: always use max_width instead of ideal_width for use
list rewrite. I think it looks better, was also suggested by @nrc in
https://github.com/nrc/rustfmt/issues/82#issuecomment-105314265
2015-07-25 19:00:38 +02:00
Nick Cameron
8461e8a0a8 Merge pull request #147 from marcusklaas/even-more-expr
Format if expressions & loops
2015-07-25 09:51:59 +12:00
Marcus Klaas
3aa03dcc25 Use new module code from libsyntax 2015-07-24 19:25:01 +02:00
Marcus Klaas
2fa6220f57 Format all the loops! 2015-07-19 23:43:32 +02:00
Nick Cameron
c3375078e5 Merge pull request #137 from nrc/struct-lit-opt
Options for formatting struct literals
2015-07-17 06:57:01 +12:00
Nick Cameron
f2bcee9d87 Tidy up some overrunning lines 2015-07-16 14:23:48 +12:00
Nick Cameron
018fa85453 Reformat code to new struct lit style 2015-07-16 14:05:10 +12:00
Marcus Klaas
b473c2bd2a Format loops 2015-07-15 23:33:01 +02:00
Gaëtan Cassiers
990a123e1c Run rustfmt on the code 2015-07-03 11:13:28 +02:00
Gaëtan Cassiers
3de366d282 Format modules into separate files 2015-07-03 11:12:21 +02:00
Marcus Klaas
482f200b0b Update import list formatting
Include comments and sort items alphabetically.
2015-06-26 03:43:12 +02:00
Marcus Klaas
0ef5db9496 Format tuple-like structs 2015-06-23 16:54:42 +02:00
Marcus Klaas
d7b49fd76c Remove global mutable config to allow for concurrency 2015-06-23 13:26:04 +02:00
Nick Cameron
1488d5eadb Merge pull request #90 from marcusklaas/empty-imports
Remove empty list imports
2015-06-22 17:32:55 -07:00
Gaëtan Cassiers
b7ead806f4 Use FromIterator implementation for Option
Combined with try_opt!, this avoid an explicit for loop or another macro.
2015-06-23 02:15:46 +02:00
Gaëtan Cassiers
c012d311c4 A basic impl of Rewrite for ast::Expr 2015-06-23 02:15:46 +02:00
Marcus Klaas
27d6558964 Remove empty list imports 2015-06-02 23:55:16 +02:00
Marcus Klaas
90bc40a111 Implement basic enum formatting 2015-06-02 15:52:07 +02:00
Gaëtan Cassiers
113bdaa119 Fix #79 2015-05-25 13:22:10 +02:00
Nick Cameron
e7adf64155 Format structs 2015-05-25 17:07:55 +12:00
Nick Cameron
1a09a6d00a Use config file for constants 2015-05-23 17:53:53 +12:00
Marcus Klaas
4aa3518703 Format required methods on traits 2015-05-12 02:37:05 +02:00
Nick Cameron
e2a5d94e3f Merge pull request #68 from marcusklaas/import-breaks
Keep import lists on a single line when possible
2015-05-12 09:39:22 +12:00
Oliver Schneider
853b58901b typo 2015-05-11 15:05:12 +02:00
Marcus Klaas
c790d7d550 Keep import lists on a single line when possible 2015-05-04 22:22:31 +02:00
Marcus Klaas
58a14fbc79 Correctly indent use items and functions 2015-05-04 09:25:20 +02:00
Nick Cameron
0931b7c6df Merge pull request #45 from tbu-/pr_toowned
Change `to_string` to `to_owned` when it just creates a `String` from a `&str`
2015-04-30 21:10:54 +12:00
Tobias Bucher
5247d98d31 Change to_string to to_owned when it just creates a String from a &str
This means that it doesn't have to go through the formatting hierarchy and can
just immediately reserve enough memory.
2015-04-30 10:31:42 +02:00
Manish Goregaokar
9398aed82c Handle pub use (fixes #23) 2015-04-30 13:52:28 +05:30
Nick Cameron
f61ad35494 Preserve linebreaks in doc comments 2015-04-29 16:25:52 +12:00
Nick Cameron
16f9057975 Better handle trait items 2015-04-29 15:24:20 +12:00
Nick Cameron
2e485ea086 Better attribute handling 2015-04-29 15:03:15 +12:00
Nick Cameron
40be79304e Tweak rules around attributes for modules 2015-04-28 22:19:25 +12:00
Nick Cameron
a84287c6b0 Comments in function decls and annotations/doc comments 2015-04-28 20:56:01 +12:00
Nick Cameron
c00970f5e9 Indenting for modules
rustfmt now bootstraps!
2015-04-23 18:43:46 +12:00
Nick Cameron
bc7855d347 Idempotent tests and comments in function decls 2015-04-23 16:22:48 +12:00
Nick Cameron
4c869a1b9d Extract out more files 2015-04-21 21:01:19 +12:00