Commit Graph

402 Commits

Author SHA1 Message Date
topecongiro
821d04b2a4 Do not report errors on skipped items or statements 2017-12-08 17:46:43 +09:00
topecongiro
5e6bb3edb0 Keep track of line number in visitor 2017-12-08 16:59:04 +09:00
Seiichi Uchida
3ebe054362 Replace into() on &str with to_owned() 2017-12-08 13:07:42 +09:00
Seiichi Uchida
c776443981 Remove unused lifetime 2017-12-08 13:07:28 +09:00
Seiichi Uchida
d6d8d86e94 Replace &Rc<String> with &str 2017-12-07 17:32:19 +09:00
Seiichi Uchida
c0eb8c3212 Add FmtVisitor::from_context() 2017-12-07 13:57:54 +09:00
Seiichi Uchida
1d9a10e00e Use explicit lifetime to get rid of unsafe code
at least this is why we use Rust
2017-12-07 13:57:54 +09:00
Seiichi Uchida
7c4a84751f Convert '&str' into 'String' whenever necessary 2017-12-07 13:57:52 +09:00
Seiichi Uchida
69a15b2eee Update FmtVisitor::from_codemap() 2017-12-06 22:51:52 +09:00
Seiichi Uchida
0928762562 Use SnippetProvider in FmtVisitor and RewriteContext 2017-12-06 22:49:49 +09:00
Seiichi Uchida
98860ab890 Add SnippetProvider 2017-12-06 22:48:48 +09:00
Seiichi Uchida
228578b9c7 Add count_newlines() utility function 2017-12-05 15:17:40 +09:00
Seiichi Uchida
483f71c8b1
Merge pull request #2218 from pietroalbini/fix-ast-for-use_nested_groups
Fix broken build after use_nested_groups lands on nightly
2017-12-02 16:34:16 +09:00
Pietro Albini
9d8cfbcd93
Fix imports formatting broken after AST change 2017-12-01 00:18:00 +01:00
topecongiro
22c9025027 Format source codes 2017-11-30 18:00:49 +09:00
Seiichi Uchida
f99b775de7 Rename is_dummy to has_braces 2017-11-30 06:40:29 +09:00
Seiichi Uchida
b5e4c99ca7 Use an explicit flag to decide on whether to add brace compensation 2017-11-30 06:12:32 +09:00
topecongiro
8b53d7806c Cargo fmt 2017-11-29 17:37:51 +09:00
topecongiro
35466adbfe Generalize ListItems to allow a separator other than comma 2017-11-16 17:43:36 +09:00
topecongiro
f8074b340d Combine fn_brace_style and item_brace_style 2017-11-14 10:47:02 +09:00
topecongiro
05798572bb Remove empty lines at the beginning of the file 2017-11-10 17:09:31 +09:00
topecongiro
6ce42823cb Add opt_snippet() and opt_span_after() 2017-11-10 17:08:57 +09:00
Seiichi Uchida
e079cb81ef Remove 'Option<_>' from return type of 'take_while_with_pred()' 2017-11-09 11:33:35 +09:00
topecongiro
fd10925a08 Implement soft wrapping on doc comments 2017-11-08 18:24:03 +09:00
topecongiro
082c001843 Add visit_static() 2017-11-06 13:52:25 +09:00
topecongiro
3b2b7f67ee Add StructParts to reduce the number of args 2017-11-06 13:52:25 +09:00
topecongiro
318f9c89e0 Add StaticParts to reduce the number of args in rewrite_static() 2017-11-06 13:52:25 +09:00
topecongiro
a3f286a0dc Remove an unused arg from visit_fn() 2017-11-06 13:52:25 +09:00
topecongiro
c7a788084b Simplify let-if pattern 2017-11-06 13:52:25 +09:00
topecongiro
314c97387d Squash redundant match arms 2017-11-06 13:52:25 +09:00
Pascal Hertleif
536526685d Fix compile on 2017-11-04 nightly
Breakage came from https://github.com/rust-lang/rust/pull/45247/
2017-11-05 12:26:06 +01:00
topecongiro
b17de6228f Cargo fmt 2017-11-02 21:45:00 +09:00
Martin Lindhe
f930a16b8d fix some typos 2017-11-01 07:33:55 +01:00
Nick Cameron
e2a5c78e4b
Merge pull request #2043 from sunjay/lift_generics
Lifted generics to account for changes in rust-lang/rust#44766
2017-10-28 18:14:13 +13:00
Nick Cameron
73b079d3f6 Merge pull request #2079 from SingingTree/issue-1979-errors-go-to-stdout
Use stderr for various errors and warnings.
2017-10-27 01:02:44 +05:30
Bryce Van Dyk
adac9fb43c Use stderr for various errors and warnings.
Adjusts several error and warning report cases to output using eprintln!
instead of println! so that messages are sent to stderr.
2017-10-25 22:18:19 +13:00
Matthew McAllister
1853d02ea9 Handle #![rustfmt_skip] in block statements 2017-10-20 02:37:52 -07:00
Sunjay Varma
3f11c4b93a Updated rustfmt to account for changes from rust-lang/rust#44766 2017-10-17 15:37:07 -04:00
Nick Cameron
802df67c2f Merge pull request #2035 from topecongiro/deprecate-try_opt!
Replace `try_opt!` macro with a `?` operator
2017-10-05 20:45:52 +08:00
topecongiro
fe69dde96b Replace 'try_opt!' macro with a '?' operator 2017-10-05 20:50:19 +09:00
Nick Cameron
81f0e9c94e Merge pull request #2032 from topecongiro/trailing-whitespaces-in-macro-def
Remove trailing whitespaces in macro def
2017-10-05 19:34:12 +08:00
Nick Cameron
2abe119d88 Merge pull request #2017 from topecongiro/issue-1987
Format strings in attributes when `format_strings = true`
2017-10-05 17:27:17 +08:00
topecongiro
106625bc5c Remove trailing whitespaces in macro def 2017-10-05 16:17:59 +09:00
topecongiro
74402bbdef Move logic for doc comments to ast::Attribute::rewrite() 2017-10-01 20:24:53 +09:00
topecongiro
48ff9df8a4 Add rewrite_literal() 2017-10-01 19:29:23 +09:00
topecongiro
2e6825cc8c Use FnSig in rewrite_fn() and rewrite_fn_base() 2017-09-29 12:49:39 +09:00
Seiichi Uchida
32fa51a6a9 Move Spanned to spanned.rs from lib.rs 2017-09-19 10:04:35 +09:00
Seiichi Uchida
df7d2be562 Move Indent and Shape to shape.rs from lib.rs 2017-09-19 10:04:35 +09:00
Nick Cameron
d906ea23c7 Merge pull request #1968 from topecongiro/issue-1967
Reorder use items inside blocks
2017-09-18 12:59:25 +12:00
Nick Cameron
cccb7f681e Merge pull request #1966 from topecongiro/string-to-cow
Refactoring: use Cow and etc.
2017-09-18 12:45:25 +12:00
Seiichi Uchida
178a339fc3 Reorder use items inside blocks 2017-09-15 22:31:52 +09:00
topecongiro
0b5d524486 Remove unnecessary references 2017-09-15 17:09:30 +09:00
topecongiro
f51261e93e Cargo fmt 2017-09-15 12:10:58 +09:00
Nick Cameron
a1fd68da46 Merge pull request #1948 from topecongiro/issue-1137
Use write_list() to format imports
2017-09-07 17:35:14 +12:00
topecongiro
903d815228 Clean up 2017-09-06 19:30:51 +09:00
topecongiro
4dbda06629 Use push_rewrite() to remove duplicates 2017-09-06 19:24:23 +09:00
topecongiro
4bd0373757 No cloning 2017-09-06 19:24:14 +09:00
topecongiro
662ee46e67 Use write_list() to format imports 2017-09-06 18:47:50 +09:00
topecongiro
af404b998c Factor out rewrite_extern_crate() 2017-09-06 18:44:33 +09:00
Seiichi Uchida
2fb5affb5f Remove duplicates inside visit_stmt() 2017-09-05 16:50:55 +09:00
topecongiro
47062c8f0a Format long derive 2017-09-03 08:14:00 +09:00
topecongiro
737186b890 Use rewrite() instead of format_expr 2017-09-03 08:09:37 +09:00
Seiichi Uchida
4b79055a15 Apply refactoring from cargo clippy 2017-08-31 12:49:12 +09:00
Nick Cameron
39a91ba292 Fixup warnings and test formatting 2017-08-31 14:20:47 +12:00
Vadim Petrochenkov
6e5c6f5ba3 Use getters to access Span fields 2017-08-31 14:14:13 +12:00
topecongiro
979d131c5d Format and preserve attributes on ast::Stmt 2017-08-30 19:27:36 +09:00
topecongiro
e31a48b4d9 Refactoring: remove duplicates 2017-08-30 19:26:45 +09:00
topecongiro
1015dd8860 Use String::with_capacity() instead of String::new() 2017-08-28 00:24:10 +09:00
topecongiro
eb828ed9ff Preserve blank line between doc comment and attribute 2017-08-28 00:17:38 +09:00
topecongiro
1f9e7c25c9 Implement Rewrite trait for ast::ForeignItem 2017-08-25 08:19:51 +09:00
topecongiro
669a139956 Only merge consecutive derives 2017-08-24 23:48:18 +09:00
topecongiro
5dafcc24e4 Add merge_derives config option 2017-08-24 22:29:56 +09:00
Nick Cameron
d7b5e7de54 Merge pull request #1906 from topecongiro/remove_count_missing_closing_parens
Remove count_missing_closing_parens()
2017-08-21 10:12:30 +12:00
topecongiro
3d1b6fe1c6 Remove count_missing_closing_parens() 2017-08-20 23:23:13 +09:00
Seiichi Uchida
63ac49638b Support match_pattern_separator_break_point config option 2017-08-18 23:19:47 +09:00
topecongiro
528200009a Do not panic against files with invalid attributes 2017-08-16 00:11:20 +09:00
sinkuu
f9ee060eae Use utils::inner_attributes 2017-08-12 18:28:28 +09:00
sinkuu
955b25625d Use attribute span 2017-08-12 18:28:28 +09:00
sinkuu
b433e63d2a Remove unnecessary blank lines at the start and the end of a block 2017-08-11 17:44:16 +09:00
Nick Cameron
62689ef568 Merge pull request #1861 from topecongiro/refactor-chain
Remove unnecessary rewriting
2017-08-10 09:03:45 +12:00
topecongiro
be38606c77 Add leave_last field to ListItems 2017-08-09 16:37:21 +09:00
Seiichi Uchida
f9239dd630 Format source codes and update tests 2017-08-09 16:36:41 +09:00
topecongiro
7bf9aa25be Add reorder_extern_crates and reorder_extern_crates_in_group config options 2017-08-09 00:16:18 +09:00
Caleb Jones
fa242a5cd6 Fix #1858 - "Don't erase a use with attributes attached"
This prevents code like

    #[cfg(unix)]
    pub use self::unix::{};

from becoming

    #[cfg(unix)]

which would cause the attribute to be attached to the next item.
2017-08-06 19:53:57 -04:00
topecongiro
60fb11e5dd Do not take inner attributes into account for span 2017-08-05 15:21:46 +09:00
Emilio Cobos Álvarez
27a3bdb394
visitor: Only reorder imports if at least one of them is in file-lines. 2017-07-31 09:14:58 +01:00
Seiichi Uchida
47456aaa43 Merge pull request #1819 from brainlessdeveloper/fix-extern-crate-whitespace
Remove whitespace between words in extern declarations
2017-07-31 16:21:48 +09:00
Fausto Núñez Alberro
3377ba4dd7 Remove whitespace between extern crate declaration 2017-07-29 12:03:57 +02:00
topecongiro
5aff5beb2a More fine-grained file-lines 2017-07-29 16:11:36 +09:00
Nick Cameron
1f991d00e0 Merge pull request #1822 from topecongiro/issue-1172
Remove newlines between list elements for expressions
2017-07-27 11:15:53 +12:00
Seiichi Uchida
261865ecc9 Remove newlines between list elements for expressions 2017-07-26 22:43:36 +09:00
topecongiro
e523f053a3 Format source codes and update tests 2017-07-26 16:30:58 +09:00
Seiichi Uchida
8b970fcc9f Format inner attributes wherever possible 2017-07-25 00:55:55 +09:00
Seiichi Uchida
adce954560 Support inner attributes 2017-07-25 00:55:29 +09:00
Nick Cameron
b559a0f2f2 Merge pull request #1808 from topecongiro/issue-831
Allow block-like rhs expression to stay on the same line with lhs
2017-07-22 16:29:36 +12:00
topecongiro
0b38ac40d7 Support rustfmt_skip on statements 2017-07-22 11:18:47 +09:00
topecongiro
68c6fe70fd Format source codes and update tests 2017-07-21 17:57:31 +09:00
topecongiro
1e00a28332 Apply item_brace_style to mod 2017-07-21 13:55:15 +09:00
Seiichi Uchida
a8b0a6e4c5 Format source codes and update tests 2017-07-20 00:42:00 +09:00
Seiichi Uchida
faf45b3a80 Remove old heuristics from legacy style 2017-07-20 00:42:00 +09:00
Seiichi Uchida
b78b6e8b09 Format source codes and update tests 2017-07-20 00:42:00 +09:00
topecongiro
6fd291981e Sort imports in alphabetical and consistent order 2017-07-13 18:42:14 +09:00
Seiichi Uchida
51641f167e Do not count the number of parens inside str or comment 2017-07-12 17:17:41 +09:00
topecongiro
2fb66cd1d3 Add trailing_semicolon config option
trailing_semicolon controls whether to add a trailing semicolon after break,
continue and return.
2017-07-12 14:16:06 +09:00
topecongiro
e3310a6a18 Format source codes 2017-07-11 21:53:10 +09:00
Seiichi Uchida
bc90a12b8d Format union 2017-07-10 17:26:55 +09:00
Seiichi Uchida
bc63d69c3f Format source codes 2017-07-10 02:24:59 +09:00
topecongiro
fb1225a8af Use format_expr wherever single-lined block is not allowed 2017-06-20 22:35:16 +09:00
topecongiro
91bd1fdc86 Format source codes 2017-06-18 14:29:17 +09:00
topecongiro
54233acc8e Format source codes 2017-06-17 16:56:54 +09:00
topecongiro
e31f5eceac Use correct span for Infer type inside closure header 2017-06-17 15:35:29 +09:00
topecongiro
b048fe6b35 Format source codes 2017-06-17 15:26:59 +09:00
topecongiro
f60a810730 Preserve comments inside attributes 2017-06-17 05:44:54 +09:00
topecongiro
208ff15954 Format source codes 2017-06-16 08:49:49 +09:00
topecongiro
b8f11a4e3c Format source codes 2017-06-14 20:39:07 +09:00
topecongiro
e2d51aeb41 Use correct span for MetaItem 2017-06-14 00:09:05 +09:00
topecongiro
384d985df9 Do not rely on format_missing for rewriting attributes 2017-06-14 00:08:31 +09:00
Nick Cameron
1f512948a0 Reformat source code using new defaults 2017-06-13 14:41:49 +12:00
topecongiro
647fd4ff77 Leave GlobalAsm and MacroDef without formatting 2017-06-06 07:32:06 +02:00
est31
727963afe4 Update syntex_syntax
Bases on commit to switch to libsyntax by @nrc
2017-06-06 07:31:47 +02:00
Nick Cameron
8ac9245df4 Merge pull request #1634 from topecongiro/impl-rewrite-attribute
Implement Rewrite trait for syntax::ast::Attribute
2017-06-06 17:11:10 +12:00
topecongiro
7be703a637 Implement Rewrite trait for syntax::ast::Attribute 2017-06-06 13:55:34 +09:00
Nick Cameron
130aa70e3a Merge pull request #1621 from topecongiro/combining
Combine more expressions
2017-06-06 14:52:48 +12:00
Nick Cameron
14a1ea8193 Merge pull request #1629 from topecongiro/issue-982
Use recover_comment_removed in rewrite_static
2017-06-05 11:37:21 +12:00
topecongiro
b49269ad39 Forbid method chain to get combined if it uses multi line.
If the method chain goes multi line before the last element, disallow combining
the method chain.
2017-06-04 19:37:24 +09:00
topecongiro
d54634bd7c Use recover_comment_removed in rewrite_static 2017-06-04 18:44:08 +09:00
topecongiro
aadd3e11f4 Unindent comment on top of else 2017-06-02 11:58:58 +09:00
Seiichi Uchida
789abf063d Use block indent style when visual indent failed 2017-06-01 12:08:20 +09:00
Nick Cameron
2dc4298b71 Merge pull request #1593 from topecongiro/issue-1439
Allow comments after where clause
2017-05-27 13:34:50 +12:00
topecongiro
dab14b4485 Allow comments after where clause 2017-05-27 02:07:58 +09:00
topecongiro
fcffe854b8 Allow default associated types 2017-05-26 17:17:12 +09:00
topecongiro
77a2e9858b Format source codes 2017-05-23 11:37:33 +09:00
Michael Killough
bce1f309b7 Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into config 2017-05-19 16:10:27 +07:00
Flier Lu
1077a100a1 reorder imports in group 2017-05-18 13:26:34 +08:00
Michael Killough
c0bdbfa531 Switch to accessing config items via method.
Preparation for #865, which proposes adding a flag which outputs which
config options are used during formatting.

This PR should not make any difference to functionality. A lot of this
was search-and-replace.

Some areas worthy of review/discussion:

 - The method for each config item returns a clone of the underlying
   value. We can't simply return an immutable reference, as lots of
   places in the code expect to be able to pass the returned value as
   `bool` (not `&bool). It would be nice if the `bool` items could
   return a copy, but the more complex types a borrowed reference... but
   unfortunately, I couldn't get the macro to do this.
 - A few places (mostly tests and `src/bin/rustfmt.rs`) were overriding
   config items by modifying the fields of the `Config` struct directly.
   They now use the existing `override_value()` method, which has been
   modified to return a `Result` for use by `src/bin/rustfmt.rs`. This
   benefits of this are that the complex `file_lines` and `write_mode`
   strings are now parsed in one place (`Config.override_value`) instead
   of multiple. The disadvantages are that it moves the compile-time
   checks for config names to become run-time checks.
2017-05-16 15:47:09 +07:00
Seiichi Uchida
762db5138e Format source codes 2017-05-15 22:55:45 +09:00
Seiichi Uchida
7ec78711f2 Prevent rewriting closure block to expr inside macro 2017-05-13 18:32:25 +09:00
topecongiro
d062d79fb5 Use block indent when visual indent failed 2017-05-08 08:07:18 +09:00
topecongiro
4a28be486e Refactor Shape 2017-05-08 07:24:32 +09:00
topecongiro
e923df4146 Add indented and with_max_width 2017-05-08 07:24:12 +09:00
Nick Cameron
8579c1db0e Merge pull request #1495 from topecongiro/poor-formatting/closure
Fix weird indentation inside closures
2017-05-04 17:15:58 +12:00
Sheng Hau
51815effbe Format macros in trait item position 2017-05-04 00:10:03 +08:00
topecongiro
58d957be3f Check format failures explicitly in visit_block 2017-05-04 00:21:51 +09:00
Jonathan Behrens
b6f1b516d9 Format any statement whose span intersects file_lines 2017-03-29 01:33:14 -04:00
Nick Cameron
5305bc8436 test fallout 2017-03-28 11:25:59 +13:00
Nick Cameron
5fb1140688 fallout - source reformatting 2017-03-28 11:14:47 +13:00
Nick Cameron
e4efa22983 Source formatting fallout 2017-03-28 10:58:41 +13:00
C4K3
ab832fa4bb config: Rename ideal_width -> comment_width (#1370)
Since the config option only affects comment widths, and the previous
name has led to some confusion (see #1321, #1152).
2017-03-13 09:07:33 +13:00
David Wickes
094c8898e1 Fix for #1255
Default annotation incorrectly removed on associated types

Fixed by adding a specific function to perform formatting on `ImplItems`.
2017-02-26 22:28:21 +00:00
Nick Cameron
d9d2423764 Tweak chain rules 2017-02-23 13:15:48 +13:00