Commit graph

2318 commits

Author SHA1 Message Date
Tibo
5581be2616
Use failure for FormattingError 2018-04-26 12:18:30 +10:00
Tibo
efb8069cfc
Replace std::Error with failure for FormatDiff 2018-04-26 12:18:20 +10:00
Seiichi Uchida
ac8ae00625
Cargo update and clippy (#2643) 2018-04-25 07:21:23 +09:00
Roman Stoliar
5b5a72c840 keep auto trait 2018-04-20 17:31:31 +03:00
Nick Cameron
866900449a Make some more stuff private
0.6
2018-04-20 22:10:48 +12:00
Nick Cameron
ca610d35b3 Refactor to make a sensible public API
0.5 - lots of breaking changes

cc #2639
2018-04-20 21:52:02 +12:00
Nick Cameron
6a31741eaa Get exit codes right 2018-04-20 14:17:56 +12:00
Nick Cameron
5194984812 Add a verbose-diff option
And don't print end of line characters by default in diffs

cc #2536
2018-04-20 14:02:44 +12:00
Nick Cameron
7a886e8fe5 Refactoring around write mode in main 2018-04-20 13:42:27 +12:00
Nick Cameron
a73f14aa95 Trivial refactoring in bin 2018-04-20 13:24:45 +12:00
David Barsky
f9532ba8d7 Implemented rough draft of check write mode. (#2539)
* Add rough draft of `check` mode. Not unit tested.

* Added assert-cli; simple test case for `--write-mode=check`

* Lightly documented `check` WriteMode

* wrote clearer phrasing for config::options::WriteMode::Check

* Implemented default for WriteMode where default is Overwrite

* Simplified exit code handling

* updated README.md as per @nrc' comment

* collapsed exit-code handling

* Removed write_mode from Summary, introduced partial option parsing earlier

* Handle write-mode parsing in a slightly better way.
2018-04-20 11:14:11 +12:00
Shotaro Yamada
61d29eb70c Add spaces between consecutive .. ..= 2018-04-16 17:33:22 +09:00
Nick Cameron
1415a4dc23 Fix tests 2018-04-14 10:20:08 +12:00
Nick Cameron
01c1f99e39 Fallout from removing TupField 2018-04-14 10:15:39 +12:00
Nick Cameron
2cea3644fe
Merge pull request #2618 from topecongiro/issue-1174
Output xml header and footer only once
2018-04-12 16:56:00 +12:00
Seiichi Uchida
8b731db6ba Output xml header and footer only once 2018-04-12 13:45:12 +09:00
Nick Cameron
55dd8f1df0
Merge pull request #2603 from topecongiro/merge-nested-imports
Merge imports
2018-04-12 16:40:06 +12:00
Seiichi Uchida
e58e97783e Preserve trailing comma on macro call when using mixed layout 2018-04-12 09:54:00 +09:00
Nick Cameron
305c640553 Review changes 2018-04-11 10:50:19 +12:00
Nick Cameron
1c17dbbf74 rebasing 2018-04-11 10:46:49 +12:00
Nick Cameron
911395a451 Squash the various 'reorder imports' option into one
cc #2185
2018-04-11 10:46:49 +12:00
Seiichi Uchida
8820a59bd5 Resolve review comments 2018-04-10 12:36:57 +09:00
Seiichi Uchida
4a7e45ec28 Simplify UseTree::has_comment 2018-04-10 12:36:57 +09:00
Seiichi Uchida
1954513ace Merge imports with the same prefix into a single nested import 2018-04-10 12:36:57 +09:00
Seiichi Uchida
5dd203eabe Add merge_imports config option 2018-04-10 12:36:57 +09:00
Nick Cameron
518ece2272
Merge pull request #2612 from peterhuene/suppress-unstable-config-options
Suppress unstable config options by default.
2018-04-10 15:07:57 +12:00
Peter Huene
8208f8aa01
Suppress unstable config options by default.
This commit suppresses the output of unstable config options by default.

Users can specify the `--unstable-features` option to show the config options
that are unstable.

Fixes #2611.
2018-04-09 12:45:56 -07:00
Nick Cameron
e784712f09 Try to fix a build regression before it happens 2018-04-09 21:07:49 +12:00
Nick Cameron
f14671131e Make error_on_line_overflow false by default
And improve docs, the error message, etc.

I think false is the better default since such errors should only occur due to a bug in Rustfmt and therefore most users should not be notified of it happening (although to be clear, it might be a 'bug' which only occurs with pathological input and therefore we won't fix it). The error has proven to be confusing and annoying in the past.

Closes #1080
2018-04-09 16:47:55 +12:00
Nick Cameron
48e5bc1988 Reorder config options
cc #1974
2018-04-09 16:31:53 +12:00
Nick Cameron
7822d0c921 Fix test 2018-04-09 09:54:07 +12:00
csmoe
84d3659767 update rustc syntax 91.0.0 2018-04-08 22:22:11 +08:00
Seiichi Uchida
edcc7b69eb
Cargo update (#2602)
Update `rustc-ap-syntax` to 89.0.0 and fix up breaking changes.
2018-04-06 23:09:45 +09:00
Nick Cameron
b6645e345e
Merge pull request #2601 from topecongiro/fix-merge-mess
Fix up merge mess
2018-04-06 15:32:05 +12:00
Seiichi Uchida
04227a7d30 Fix up merge mess 2018-04-06 10:31:57 +09:00
Nick Cameron
0a480181e8
Merge pull request #2600 from i1skn/error_on_unformatted
Fix error_on_unformatted and skip_children override
2018-04-06 12:41:13 +12:00
Nick Cameron
4b2160e1b2
Merge pull request #2599 from topecongiro/issue-2596
Use multiple lines for imports list which exceeds max width
2018-04-06 11:12:53 +12:00
Nick Cameron
a3fba04141
Merge pull request #2593 from topecongiro/issue-2455
Add reorder_impl_items config option
2018-04-06 11:12:11 +12:00
Ivan Sorokin
3fe2233fd3 Fix error_on_unformatted and skip_children override
Currently, error_on_unformatted and skip_children options
specified in the config file are discarded.
This happens because CLI options have a higher priority,
but we coerce an absence of a `bool` option to `false`.
In this scenario, an absence of a `bool` option is indistinguishable
from explicetely set as `false`. We should coerce it to `None` instead,
so it does not override the one in the config file.
2018-04-05 23:13:17 +02:00
Nick Cameron
b7ba6f70b1
Merge pull request #2576 from topecongiro/merge-imports
Use normalized form to format use items
2018-04-05 17:39:22 +12:00
Nick Cameron
0156fe07ac
Merge pull request #2589 from topecongiro/issue-2588
Do not indent or unindent inside string literal
2018-04-05 17:36:15 +12:00
Nick Cameron
a318bc887f
Merge pull request #2580 from remram44/improve-where_single_line-help
Improve `where_single_line` help
2018-04-05 17:34:53 +12:00
Seiichi Uchida
97ec417e74 Add trailing comma when using mixed layout with block indent 2018-04-05 13:27:42 +09:00
Seiichi Uchida
636de8313d Put imports list on the next line if it exceeds max width 2018-04-05 13:24:18 +09:00
Seiichi Uchida
ec1907b2a4 Do not indent or unindent inside string literal
Closes #2588.
2018-04-05 12:52:43 +09:00
Seiichi Uchida
89070a2244 Implement LineClasses 2018-04-05 12:52:43 +09:00
Seiichi Uchida
fa80ddf876 Reorder impl items based on its kind
The ordering is defined as follows:

type < cosnt < macro < method

Items that are same kind will not be reordered: that is, the item
that an user has put first comes first.
2018-04-05 12:49:16 +09:00
Seiichi Uchida
94f5a05a6a Add reorder_impl_items config option 2018-04-05 12:49:16 +09:00
memoryleak47
d48cbedfe4 typo (#2598)
* typo

* more typos
2018-04-05 12:47:09 +09:00
Marthog
bc05621f9b Let --dump-default-config default to stdout #2579 (#2586) 2018-04-01 23:15:25 +09:00
Seiichi Uchida
dec307b2fa
Merge pull request #2584 from sinkuu/cleanup
Misc cleanups
2018-04-01 23:14:52 +09:00
Shotaro Yamada
e2d801f11e Do not turn spaces in the beginning of the file into a newline (#2583) 2018-04-01 23:09:53 +09:00
Shotaro Yamada
56e10aa6e9 Fix typo 2018-04-01 22:29:26 +09:00
Shotaro Yamada
3467b4dafe Use ListItem::has_comment 2018-04-01 22:29:26 +09:00
Shotaro Yamada
ba792a7fa2 Remove redudant parens 2018-04-01 22:29:26 +09:00
Shotaro Yamada
71448ff3c2 Return String instead of always returing Cow::Owned 2018-04-01 22:29:26 +09:00
Shotaro Yamada
39e85281f3 Remove stray comment
Its pointee was removed in 04a6d16c7b
2018-04-01 22:29:26 +09:00
Shotaro Yamada
a2325375ed Do not collect into a Vec by hand 2018-04-01 22:29:26 +09:00
Shotaro Yamada
89200f40ff Remove unnecessary [..]s 2018-04-01 22:29:26 +09:00
Shotaro Yamada
6b3811a358 Use Iterator methods 2018-04-01 22:29:26 +09:00
Shotaro Yamada
ed46a777c8 Use str::repeat 2018-04-01 22:29:26 +09:00
Remi Rampin
37ee9c20aa Improve where_single_line help 2018-03-31 18:51:41 -04:00
Seiichi Uchida
78e09bd05c Cargo fmt 2018-03-31 14:47:50 +09:00
Seiichi Uchida
f6c0a0f4ed Cargo fmt 2018-03-31 14:23:40 +09:00
Seiichi Uchida
01311c63ec Format normalized use item
This commit implements `Rewrite` trait on `UseTree`, which is a normalized
form of `ast::UseTree` for rustfmt.
2018-03-31 14:23:36 +09:00
Seiichi Uchida
2b682b8ed5 Do not include separator to post comment
This prevents the trailing `;` on use item to be treated as comment.
2018-03-31 13:19:55 +09:00
Seiichi Uchida
a8022f3862 Do not insert newline when item is empty
This change is necessary when we remove unused imports (`use std::{};`).
2018-03-31 13:18:53 +09:00
Seiichi Uchida
73e7235317
Cargo update (#2575)
Update `rustc-ap-syntax` to 82.0.0.
2018-03-30 17:52:09 +09:00
Seiichi Uchida
3de184fb0e
Merge pull request #2572 from codeworm96/remove_unreachable
Remove unreachable! from macros.rs
2018-03-29 09:16:38 +09:00
codeworm96
e68682f6db Remove unreachable! from macros.rs
replaced unreachable! with error handling using Option.

Closes #2558
2018-03-28 23:38:34 +08:00
Nick Cameron
72b715bad4
Merge pull request #2571 from topecongiro/issue-2569
Avoid panicking on macro call with a single comma
2018-03-28 17:02:49 +02:00
Nick Cameron
1644b174a7
Merge pull request #2557 from topecongiro/vertical-layout-complex-attrs
Use vertical layout for complex attributes
2018-03-28 17:01:16 +02:00
Nick Cameron
8dd08ddd92
Merge pull request #2562 from topecongiro/issue-2196
Combine simple heuristics for function calls and array
2018-03-28 16:49:25 +02:00
Seiichi Uchida
a49e00b4d7 Avoid panicking on macro call with a single comma
`parse_item` from libsyntax may return `None`, so we need to discard
the result in that case.
2018-03-28 18:14:51 +09:00
Seiichi Uchida
efd295a4e1 Follow indent style config when formatting attrs 2018-03-28 17:42:17 +09:00
Seiichi Uchida
0f55350c7d
Merge pull request #2563 from rleungx/allow-underscore
allow underscore in macro_rules!
2018-03-28 12:41:51 +09:00
rleungx
bf3bf8c235 allow underscore 2018-03-28 00:31:44 +08:00
Taylor Cramer
72d8c9143b Allow stabilization of match_default_bindings 2018-03-26 22:29:01 +02:00
Nick Cameron
53ecabad04
Merge pull request #2556 from topecongiro/issue-2554
Do not add the beginning vert to the match arm
2018-03-26 18:01:24 +13:00
Seiichi Uchida
48424ea765 Update tests and cargo fmt 2018-03-26 07:38:39 +09:00
Seiichi Uchida
98c6f7b731 Format array using overflow module
This commit applies heuristics used for function calls to array
and vice versa.
2018-03-26 07:36:44 +09:00
Seiichi Uchida
affa4ce1ec Factor out default_tactic and fix indentation
rustfmt fails to handle binary expressions with comments in-between.
2018-03-26 07:34:17 +09:00
Seiichi Uchida
cf6c67e1a6 Replace MacroStyle with ast::DelimToken 2018-03-26 07:32:48 +09:00
Seiichi Uchida
903de92dae Avoid cloning RewriteContext 2018-03-25 20:20:50 +09:00
topecongiro
c77708ff9a Use vertical layout for complex attributes 2018-03-25 15:17:41 +09:00
Seiichi Uchida
1e1d9d4afe Do not add the beginning vert to the match arm
Pass the span after the match's condition expression.
Closes #2554.
2018-03-23 19:59:38 +09:00
Nick Cameron
2fbdedbf2f
Merge pull request #2549 from topecongiro/macro-def-spaces-around-colon
Add config option to control spaces around colon in macro def
2018-03-23 10:51:47 +13:00
topecongiro
ccec777f92 Cargo fmt and update tests 2018-03-22 16:09:21 +09:00
topecongiro
6115dcdbdc Remove a space after a colon of metavariable def in macro def 2018-03-22 16:08:57 +09:00
topecongiro
b58a113370 Use UseSegment::Slf or UseSegment::Super when appropriate
Currently we `UseSegment::Ident` for all of the segments except the last.
E.g. `use super::foo::bar::self;` will be
`[Ident("super"), Ident("foo"), Ident("bar"), Self(None)]`.
in the current implementation. I think that this should be
`[Super(None), Ident("foo"), Ident("bar"), Self(None)]`.
instead.

I noticed this because some tests failed after updating
`rustc-ap-syntax` to 73.0.0.
2018-03-22 15:56:51 +09:00
topecongiro
846f4f21db Fix libsyntax updates
`ast::UseTreeKind::Simple` now takes `Option<ast::Ident>`
instead of `ast::Ident`.
2018-03-22 15:55:14 +09:00
topecongiro
51d5696977 Fix libsyntax update
Underscore is now one of keywords.
2018-03-22 15:53:43 +09:00
Alan Du
d402cd20a8 Close #2551 2018-03-22 00:57:22 -04:00
Alan Du
d8723aaa8c Fix build 2018-03-22 00:01:09 -04:00
Nick Cameron
ff9ab51617
Merge pull request #2550 from sinkuu/chars_count_index
Don't index a string with chars().count()/position()
2018-03-22 16:26:48 +13:00
Nick Cameron
0bc0241d2a
Merge pull request #2548 from topecongiro/match-mod
Do not collapse block around expr with condition on match arm
2018-03-22 15:40:36 +13:00
Shotaro Yamada
83c8d23cc2 Omit unnecessary UTF-8 decoding 2018-03-22 08:34:53 +09:00
Shotaro Yamada
e5572bbb66 Use take_while 2018-03-22 08:34:36 +09:00
Shotaro Yamada
4757321277 Don't index a string with chars().count() 2018-03-22 08:33:18 +09:00
Seiichi Uchida
5b9b7d5b9f Do not collapse block around expr with condition on match arm
Closes #2376.
2018-03-21 22:21:08 +09:00
Seiichi Uchida
88589f2ad8 Add matches module
`matches` module contains `rewrite_match` and related stuffs.
2018-03-21 22:21:08 +09:00
Nick Cameron
3a138a24a3 Return grouping extern crate to true by default 2018-03-20 09:54:00 +13:00
Nick Cameron
bf9f175336 reviewer comments and rebase fallout 2018-03-20 09:27:31 +13:00
Nick Cameron
0cf80dcce7 Better handle comments and newlines around erased imports 2018-03-20 09:27:31 +13:00
Nick Cameron
50c95a074a cargo fmt 2018-03-20 09:27:31 +13:00
Nick Cameron
4cfffbd0a8 Reimplement import reordering. 2018-03-20 09:27:31 +13:00
Nick Cameron
a76d9b529a format code and tests 2018-03-20 09:27:31 +13:00
Nick Cameron
164cf7d6c9 Reorder imports by default 2018-03-20 09:26:10 +13:00
Seiichi Uchida
adc257f4b3 Put a space before colon that appears after a meta variable
Closes #2534.
2018-03-19 08:27:53 +09:00
Seiichi Uchida
f8109f8e9c Put spaces around braces 2018-03-19 08:23:53 +09:00
Seiichi Uchida
96a83b57e5 Add some doc comments and factor out add_repeat and add_delimited 2018-03-19 08:23:53 +09:00
Seiichi Uchida
0fd174d5f1 Handle binary operators and lifetimes 2018-03-19 08:23:53 +09:00
Seiichi Uchida
3f7b59ca2b Break before meta variables when using multiple lines 2018-03-19 08:23:53 +09:00
Seiichi Uchida
95507e3a43 Remove has_prefix_space 2018-03-19 08:23:53 +09:00
Seiichi Uchida
ec71459c44 Format macro arguments with vertical layout 2018-03-19 08:23:53 +09:00
Seiichi Uchida
84ea306d32 Remove unit tests 2018-03-19 08:23:53 +09:00
Nick Cameron
56d2a08db0
Merge pull request #2541 from topecongiro/issue-2358
Skip name replacement in comments and strings
2018-03-19 08:55:35 +13:00
Seiichi Uchida
1a969cff7f Remove FIXME about duplicated code 2018-03-17 14:59:39 +09:00
Seiichi Uchida
d7188654ea Skip name replacement in comments and strings 2018-03-17 14:59:26 +09:00
Seiichi Uchida
ca6fc67e60 Fix print_version 2018-03-17 12:16:15 +09:00
topecongiro
a03b3b7d6f Cargo update
Remove `rustc-ap-rustc_errors` from dependencies since it
is re-exported from `rustc-ap-syntax`.
2018-03-16 08:52:36 +09:00
Nick Cameron
c416246494
Merge pull request #2509 from topecongiro/issue-2493
Overflow the last rhs of a binary expression
2018-03-16 07:30:30 +13:00
Seiichi Uchida
eda626cfc9 Call syntax::with_globals before using a parser 2018-03-15 18:55:52 +09:00
Matthew McAllister
c5168405b0 Format attributes on block expressions 2018-03-14 01:16:19 +09:00
Nick Cameron
a0e063a6e1
Merge pull request #2522 from topecongiro/ignore-config-option
Add ignore config option
2018-03-12 16:25:31 +13:00
topecongiro
3999d64f12 Simplify IgnoreList 2018-03-12 08:41:19 +09:00
Seiichi Uchida
182b46e0ed Simplify join_bounds() 2018-03-12 07:57:03 +09:00
Seiichi Uchida
ccd134ed75 Add a test for #2497
Closes #2497.
2018-03-12 07:54:12 +09:00
Seiichi Uchida
b077297179 Modify the placement of the opening brace of trait
Put the opening brace on the next line if

1. putting it one the current line exceeds max width.
2. trait bounds uses multiple lines.
2018-03-12 07:54:12 +09:00
Seiichi Uchida
f56039c7e5 Use rewrite_assign_rhs for rewriting bounds 2018-03-12 07:54:12 +09:00
Seiichi Uchida
8f7a90fbef Add rewrite_assign_rhs_with
It is like `rewrite_assign_rhs` but lets us force to put the rhs on the next
line if it uses multiple lines.

This lets us avoid duplicating logic for choosing whether to put stuff on the
same line or the next line.
2018-03-12 07:48:31 +09:00
Nick Cameron
f5ebcd922e
Merge pull request #2513 from rtsuk/master
Restore cargo fmt behavior in workspaces
2018-03-12 11:26:12 +13:00
Nick Cameron
bcaeab7a5e
Merge pull request #2527 from topecongiro/issue-2526
Check whether '\\'' is char literal or lifetime
2018-03-12 11:25:40 +13:00
Nick Cameron
af5d3cc87b
Merge pull request #2524 from topecongiro/issue-2523
Do not unindent code block in comments with unformattable macro
2018-03-12 11:21:09 +13:00
Nick Cameron
124f03b1fc
Merge pull request #2516 from topecongiro/issue-2510
Make rewrite_call_inner more generic
2018-03-12 11:18:14 +13:00
David Lukes
a41947cd7d Enable doctests
Doctests were disabled globally because up until #2456, they were just
formatting examples which were not supposed to compile. Now that there
is one runnable doctest, I disabled the other ones individually (by
adding the ignore directive).

I also added some empty lines around the code blocks to avoid the
following warning and instead ignore the code blocks cleanly:

WARNING: ... Code block is not currently run as a test, but will in
future versions of rustdoc. Please ensure this code block is a runnable
test, or use the `ignore` directive.

See rust-lang/rust#28712 for further details.
2018-03-10 09:57:01 +01:00
Seiichi Uchida
86a427fe32 Check whether '\\'' is char literal or lifetime 2018-03-10 01:19:38 +09:00
Rob Tsuk
ba10a4c48d Canonicalise the paths 2018-03-09 07:24:40 -07:00
Rob Tsuk
53dcb0d09d Restore cargo fmt behavior in workspaces
Previously, cargo fmt  invoked without parameters would
only format the crate in the current directory, even if
the crate was part of a workspace. This patch restores
that behavior.
2018-03-09 07:24:40 -07:00
topecongiro
2188b464b0 Format macro call with item arguments 2018-03-09 17:17:55 +09:00
topecongiro
eaab592cb8 Avoid unindenting code block in comment with unformattable macro
`format_code_block` formats the given `code_snippet` by enclosing it inside
`fn main` block. Previously we did not add indentation to the `code_snippet`
before formatting it. This works fine as long as we can format the given
`code_snippet`, but when the code block has unformattable macro, they gets
unindented. This commit fixes it by adding proper indentation before formatting
the `code_snippet`.

For example, when formatting the following code block,

```rust
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
```

previously we enclosed it like this:

```rust
fn main() {
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
}
```

with this PR, we will enclose it like this:

```rust
fn main() {
    some_macro!(pub fn foo() {
        println!("Don't unindent me!");
    });
}
```

Closes #2523.
2018-03-09 17:10:20 +09:00
Seiichi Uchida
6ba7c34433 Use Option<SeparatorTactic> over bool to control trailing comma 2018-03-09 14:07:43 +09:00
Seiichi Uchida
466caa77bb Make INDENT_BUFFER longer
Avoid panicking when indent whose width is 80 called `to_string()`.
2018-03-09 14:07:43 +09:00
Seiichi Uchida
2a99d9704f Use overflow::rewrite_with_angle_brackets to rewrite generics 2018-03-09 14:07:43 +09:00
Seiichi Uchida
ae629abc41 Add overflow module
This commit adds `overflow` module. This module provides two APIs.
`rewrite_with_parens` is basically the same as `rewrite_call_inner`.
`rewrite_with_angle_brackets` is used for rewriting generics and types.
2018-03-09 14:07:43 +09:00
Seiichi Uchida
8943c376bc Use RefCell for RewriteContext fields 2018-03-09 14:07:05 +09:00
Seiichi Uchida
84ad70c151 Add ignore config option
For example, with the following config file, rustfmt will ignore `src/types.rs`,
`src/foo/bar.rs` and every file under `examples/` directory.

```toml
[ignore]
files = [
    "src/types.rs",
    "src/foo/bar.rs",
]
directories = [
    "examples",
]
```
2018-03-09 13:37:52 +09:00
Nick Cameron
dc2f1429e7
Merge pull request #2521 from topecongiro/issue-2520
Fix bugs when rewriting doc comments with code block
2018-03-09 15:18:53 +13:00
Nick Cameron
58fb47a8ca
Merge pull request #2519 from topecongiro/nested-parens
Remove nested parens
2018-03-09 15:16:30 +13:00
Nick Cameron
5f99ebe628
Merge pull request #2518 from topecongiro/issue-2491
Disallow combining parens and brackets in impl
2018-03-09 15:15:21 +13:00
Nick Cameron
1780d68761 Catch panics in the parser before they crash rustfmt
Closes #753
2018-03-09 14:59:52 +13:00
Seiichi Uchida
484469899b Keep code block without correct backticks enclosing 2018-03-09 09:46:43 +09:00
Seiichi Uchida
67fa394e4e Restrict the width of doc comments with comment_width
See the diff in tests/target/enum.rs for an example.
2018-03-09 09:34:13 +09:00
Seiichi Uchida
9344d2ca83 Fix a bug in attr::take_while_with_pred
Closes #2520.
2018-03-09 09:29:08 +09:00
Seiichi Uchida
d45aa55bd6 Remove nested parens
And make sure that we do not remove comments within parens.
2018-03-08 20:25:18 +09:00
Seiichi Uchida
71ca21fc23 Disallow combining parens and brackets in impl 2018-03-08 19:08:38 +09:00
Seiichi Uchida
a6b574bfa7 Cargo update and cargo clippy 2018-03-08 18:10:23 +09:00
moe
a2f861730e fix adds a trailing comma to struct-like macro (#2490)
* fix adds a trailing comma to struct-like macro
2018-03-08 18:05:39 +09:00
Seiichi Uchida
822dd41ad9 Put lhs and rhs of binop on the same line if lhs is short 2018-03-08 17:21:30 +09:00
Nick Cameron
06d509c25c
Merge pull request #2512 from topecongiro/rustc-ap-syntax
Update rustc-ap-syntax
2018-03-08 17:13:05 +13:00
Seiichi Uchida
9889678f56 Replace Option<Vec<&'a ast::pat>> with Vec<&'a ast::Pat> 2018-03-08 12:56:28 +09:00
Nick Cameron
f0d179dd12
Merge pull request #2456 from dlukes/feat/check-license
Attempt at checking for license (#209)
2018-03-08 15:36:27 +13:00
Nick Cameron
e01753909f
Merge pull request #2508 from topecongiro/issue-2494
Only format code blocks in comments with rust syntax notation
2018-03-08 15:29:37 +13:00
Shotaro Yamada
b3fa50db73 Use nested_shape for indenting types of lazy_static 2018-03-07 10:51:28 +09:00
Seiichi Uchida
3f0b630845 Support parentheses in patterns 2018-03-06 20:07:09 +09:00
Seiichi Uchida
520f0d65ef Format multiple patterns in 'if let' and `while let'
Closes #2511.
2018-03-06 20:02:04 +09:00
Seiichi Uchida
d7495324bc Work around removal of beginning_vert field from ast::Arm
`ast::Arm` used to have `beginning_vert` field whose type is `Option<Span>`
and holds a span of the beginning `|` if available. This field is now removed.
This commit works around that.

Since we only need a `BytePos` of the `|`, the type of `beginning_vert` in
`ArmWrapper` is `Option<BytePos>`.
2018-03-06 19:56:49 +09:00
Seiichi Uchida
5416c4df76 Modify code around ast::Visibility
`ast::Visibility` is changed to `codemap::Spanned` whose node is
`ast::VisibilityKind`. This commit fixes it.

Closes #2398.
2018-03-06 19:47:28 +09:00
Seiichi Uchida
d316eba54d Add opt_span_before() to SpanUtils trait
With some refactorings to avoid duplicated code.
2018-03-06 19:46:03 +09:00
kngwyu
8ea79aa025 add offset_left(4) for 'dyn ' 2018-03-05 22:45:40 +09:00
David Lukes
01f652799d Make license doctest pass again 2018-03-05 13:39:30 +01:00
David Lukes
085cc90599 Load and compile template in proper function
Get rid of the unncessary closure.
2018-03-05 13:25:47 +01:00
David Lukes
1db84a3ec5 Wrap license-related errors in enum 2018-03-05 13:20:51 +01:00
David Lukes
533d185f49 Shorten var names to comply with line len reqs 2018-03-05 13:19:46 +01:00
David Lukes
b33451b4ed Fix indentation in create_config macro definition 2018-03-05 13:18:27 +01:00
David Lukes
bbd6d9cd55 Refactor parsing code into struct
This also splits the giant state machine match expression into separate
methods.
2018-03-05 13:18:27 +01:00
David Lukes
310c1146f2 Move license template parsing into submodule 2018-03-05 13:13:55 +01:00
David Lukes
e48d7f3ebb Account for possibly empty license_template_path
Don't attempt to load license_template if the path wasn't specified.
2018-03-05 13:13:55 +01:00
David Lukes
ead81205cc Simplify match → if let 2018-03-05 13:13:55 +01:00
David Lukes
ad76741bca Move license template parsing into config phase 2018-03-05 13:13:55 +01:00
David Lukes
d012d52b4d Parse template with state machine instead of regex
This allows occurrences of `{` and `}` within `{}` placeholders in the
template, and also for having literal `{` and `}` in the template by
means of escaping (`\{`).

Unbalanced, unescaped `}` at the toplevel is a syntax error which
currently triggers a panic; I'll add proper error handling as I move the
license template parsing code into the config parsing phase.
2018-03-05 13:11:21 +01:00
David Lukes
2eebe614c7 Attempt at checking for license (#209)
I'm not quite sure how best to handle loading the license template from
a path -- I mean obviously I know *how* to do it, but I'm not sure where
to fit it in the codebase :) So this first attempt puts the license
template directly into the config file.

These are my misgivings about the license template config option as a
path to a file (I'd love feedback if some of these are wrong or can be
easily circumvented!):

1. I thought the obvious choice for the type of `license_template` in
`create_config!` should be `PathBuf`, but `PathBuf` doesn't implement
`FromStr` (yet? see https://github.com/rust-lang/rust/issues/44431), so
it would have to be wrapped in a tuple struct, and I went down that road
for a little while but then it seemed like too much ceremony for too
little gain.

2. So a plain `String` then (which, mind you, also means the same
`doc_hint()`, i.e. `<string>`, not `<path>` or something like that). The
fact that it's a valid path will be checked once we try to read the
file.

3. But where in the code should the license template be read? The
obvious choice for me would be somewhere in `Config::from_toml()`, but
since `Config` is defined via the `create_config!` macro, that would
mean tight coupling between the macro invocation (which defines the
configuration option `license_template`) and its definition (which would
rely on the existence of that option to run the template loading code).

4. `license_template` could also be made a special option which is
hardwired into the macro. This gets rid of the tight coupling, but
special-casing one of the config options would make the code harder to
navigate.

5. Instead, the macro could maybe be rewritten to allow for config
options that load additional resources from files when the config is
being parsed, but that's beyond my skill level I'm afraid (and probably
overengineering the problem if it's only ever going to be used for this
one option).

6. Finally, the file can be loaded at some later point in time, e.g. in
`format_lines()`, right before `check_license()` is called. But to
face a potential *IO* error at so late a stage, when the source files
have already been parsed... I don't know, it doesn't feel right.

BTW I don't like that I'm actually parsing the license template as late
as inside `check_license()` either, but for much the same reasons, I
don't know where else to put it. If the `Config` were hand-rolled
instead of a macro, I'd just define a custom `license_template` option
and load and parse the template in the `Config`'s init. But the way
things are, I'm a bit at a loss.

However, if someone more familiar with the project would kindly provide
a few hints as to how the path approach can be done in a way that is as
clean as possible in the context of the codebase, I'll be more than
happy to implement it! :)
2018-03-05 13:11:21 +01:00
topecongiro
93d454aed7 Only format code blocks in comments with rust syntax notation 2018-03-05 19:30:08 +09:00
kngwyu
078fbb0819 support dyn keyword(2506) 2018-03-05 16:57:22 +09:00
Nick Cameron
5025a53b30
Merge pull request #2502 from topecongiro/fix-reorder-module
Fix reorder module
2018-03-05 11:20:48 +13:00
Bastien Orivel
64f6372f32 Bump winapi to 0.3 2018-03-02 15:20:26 +01:00
Seiichi Uchida
0bd77f2681 Do not reorder inline modules 2018-03-02 21:53:24 +09:00
Nick Cameron
4f522794ae Tidy up and pass tests 2018-03-02 15:07:13 +13:00
Nick Cameron
39301ae5f2 Go back to a non-workspace structure
Kinda reverts https://github.com/rust-lang-nursery/rustfmt/pull/2419
2018-03-02 14:58:23 +13:00
topecongiro
9c9b31c13b Create git-rustfmt crate 2018-02-07 22:49:56 +09:00
topecongiro
d28d7fee89 Create rustfmt-format-diff crate 2018-02-07 22:49:43 +09:00
topecongiro
d18cd1d11c Create rustfmt-bin crate 2018-02-07 22:49:26 +09:00
topecongiro
3920282deb Create cargo-fmt crate 2018-02-07 22:49:10 +09:00
topecongiro
66b25f1b4a Create rustfmt_config crate 2018-02-07 22:48:52 +09:00
topecongiro
4af2aa3a9e Create rustfmt_core crate 2018-02-07 22:48:05 +09:00
Nick Cameron
c9e250a1ab
Merge pull request #2417 from topecongiro/issue-2415
Avoid orphan in chain with punctuation
2018-02-06 21:23:14 +13:00
topecongiro
5e0c6f9716 Avoid orphan in chain with punctuation 2018-02-06 09:36:29 +09:00
topecongiro
7f949a5018 Explicitly disable colored output when it is not supported 2018-02-06 09:29:00 +09:00
Seiichi Uchida
d85e1db178
Merge pull request #2393 from RReverser/macro_rules
Format stable macro_rules
2018-02-05 09:56:26 +09:00
Nick Cameron
c4314df1ab
Merge pull request #2412 from topecongiro/issue-2399
Do not reorder items with '#[macro_use]'
2018-02-05 11:28:58 +13:00
Ingvar Stepanyan
8691c64e99 cargo run cargo-fmt
Reformat codebase with current version to pass self_tests (formats macros without repetitions).
2018-02-04 12:09:03 +00:00
Ingvar Stepanyan
d8c154f052 Extract branch rewrite function 2018-02-04 11:55:08 +00:00
Ingvar Stepanyan
571af9d4b1 Format 2018-02-04 11:54:03 +00:00
Ingvar Stepanyan
bc9185451d Move ; between macro branches to a separator 2018-02-04 11:54:03 +00:00
Ingvar Stepanyan
6377c52233 Fix comment handling in macros 2018-02-04 11:54:03 +00:00
Ingvar Stepanyan
70e7716262 Comments WIP 2018-02-04 11:54:03 +00:00
Ingvar Stepanyan
41c393c751 Keep delimiter as part of macro args list 2018-02-04 11:53:10 +00:00
Ingvar Stepanyan
9423cdba82 Omit newline for empty macro branches 2018-02-04 11:53:10 +00:00
Ingvar Stepanyan
5bd036fcac Optimise common => {{ macro pattern 2018-02-04 11:53:10 +00:00
Ingvar Stepanyan
1b9fd01343 Support compact macros 2.0 representation 2018-02-04 11:53:10 +00:00
Ingvar Stepanyan
9318b4d2cf Update some macro tests 2018-02-04 11:53:10 +00:00
Ingvar Stepanyan
5d973d2e8c Initial support for macros 1.1 2018-02-04 11:53:09 +00:00
Seiichi Uchida
f815858420 Use correct offset when unindenting code block
When using hard tabs, we should only remove '\t'.
2018-02-04 17:21:10 +09:00
Seiichi Uchida
3bb0a2a749 Do not reorder items with '#[macro_use]'
Reordering items with `#[macro_use]` could change the semantic of source code.
There could exist other attributes that requires special treatment.
2018-02-04 12:08:02 +09:00
Nick Cameron
346238f497
Merge pull request #2410 from topecongiro/skip-repeat-macro
Skip rewriting macro def with repeat
2018-02-04 14:33:03 +13:00
Seiichi Uchida
61b23a4293 Skip rewriting macro def with repeat 2018-02-04 08:52:50 +09:00
Nick Cameron
30a28a262c Make is_mod_decl more accommodating
Fixes #2403 (I think)
2018-02-02 15:16:29 +13:00
Nick Cameron
7c3a422742 Update libsyntax crates 2018-02-02 14:18:30 +13:00
Nick Cameron
b7f01769f9
Merge branch 'master' into init-shorthand 2018-02-01 15:20:01 +13:00
Nick Cameron
918e79bb5a
Merge pull request #2380 from topecongiro/reorder-mods
[RFC] Reorder modules alphabetically
2018-02-01 15:18:34 +13:00
csmoe
28bb16a5a0 add a support for immovable generators 2018-01-30 22:14:33 +08:00
Seiichi Uchida
c9c346a89f Add 'use_field_init_shorthand' config option 2018-01-29 22:15:20 +09:00
Seiichi Uchida
4c9ab8b405 Cargo fmt with modules reordering enabled 2018-01-29 22:00:07 +09:00
Seiichi Uchida
56c6d73d82 Reorder modules
Add `reorder_modules` config option.

Two things we must keep in mind when reordering modules:
1. We should not reorder modules with attributes, as doing so could
   potentially break the code (e.g. `#[macro_use]`).
2. We should not reorder inline modules e.g. `mod foo { /* .. */ }`.
   We should only reorder module declarations e.g. `mod foo;`.

Some open questions:
1. Should we bring modules with `pub` in front of those without `pub`
   so that they stand out from others?
2. Instead of keeping modules with attributes in the same place,
   can we bring them in front of others? Is this safe?
2018-01-29 21:59:15 +09:00
Seiichi Uchida
7d63490d85 Update to the latest libsyntax changes 2018-01-29 21:44:26 +09:00
Nick Cameron
4633786848
Merge pull request #2396 from topecongiro/issue-2389
Put attributes and enum variants on different lines
2018-01-29 10:36:26 +11:00
Seiichi Uchida
c60d865b98 Put attributes and enum variants on different lines 2018-01-26 16:20:00 +09:00
Seiichi Uchida
dfc67a5df7 Cargo clippy 2018-01-26 14:53:28 +09:00
Seiichi Uchida
f925c581fe
Merge pull request #2386 from acmcarther/master
Make rustfmt-bin's CARGO_PKG_VERSION envvar optional
2018-01-26 12:35:52 +09:00
Alex McArther
6d294e6bcb Make rustfmt-bin's CARGO_PKG_VERSION envvar optional 2018-01-23 07:55:50 -08:00
Seiichi Uchida
154bf8e1af Cargo fmt 2018-01-22 13:05:18 +09:00
Seiichi Uchida
fa6892eb63 Use field initialization shorthand if possible
Also this PR fixes a bug that attributes on a shorthand field get removed.
2018-01-22 13:04:20 +09:00
David Alber
69f27673df Extending spaces_around_ranges to ranges in match arm patterns 2018-01-21 16:50:17 -08:00
K.J. Valencik
1fb172f989 LineOverflow: Count tabs as tab_spaces when measuring line length for overflow 2018-01-19 12:18:25 -05:00
Seiichi Uchida
298f29a57d Do not panic when special macros have less args than expected 2018-01-18 00:50:16 +09:00
Chris Stinson
4c4e079613 Fixing binop_separator="Back" for ranges
Hardcoded Separator::Place=Front in call to rewrite_pair for range
caused binop_separator="Back" to be hendled incorrectly

Fixed rewrite_pair call and the example in Configuration.md showing
the faulty behaviour
2018-01-16 17:50:20 +13:00
Seiichi Uchida
fa782303a6 0.3.5 2018-01-15 21:34:41 +09:00
Nick Cameron
74a957e80f
Merge pull request #2357 from topecongiro/issue-2342
Put attributes and struct fields on different line by default
2018-01-12 17:32:55 +13:00
Nick Cameron
a7d1d1da0e
Merge pull request #2355 from topecongiro/hide-parse-error-format-snippet
Hide parse error in format_snippet()
2018-01-12 17:31:43 +13:00
Nick Cameron
b356fc06f7
Merge pull request #2352 from topecongiro/issue-2337
Break after colon if static item does not fit in a single line
2018-01-12 17:31:12 +13:00
Nick Cameron
09e44b22f2
Merge pull request #2351 from topecongiro/issue-2256
Use correct BytePos when recovering comments on removed import
2018-01-12 17:30:27 +13:00
Nick Cameron
be0000380b
Merge pull request #2350 from topecongiro/issue-2324
Issue 2324
2018-01-12 17:27:45 +13:00
Seiichi Uchida
41b14b640a
Merge pull request #2353 from davidalber/merge-print-diff
Consolidating the logic for printing output
2018-01-12 08:26:42 +09:00
David Alber
9f5f9d2250 Consolidating the logic for printing output 2018-01-11 08:02:57 -08:00
Pascal Seitz
2e82ad8c36 case insensitive FIXME and TODO 2018-01-11 11:04:28 +01:00
Seiichi Uchida
2420d346c5 Put attributes and struct fields on different line 2018-01-11 16:57:12 +09:00
Seiichi Uchida
279acda4c4 Remove same_line_attributes config option 2018-01-11 16:52:28 +09:00
Seiichi Uchida
cf4ab38f67 Hide parse error in format_snippet() 2018-01-11 15:19:23 +09:00
Nick Cameron
1ced6d1037 Minor refactoring in macros.rs 2018-01-11 17:40:05 +13:00
Seiichi Uchida
eaab51db2e Break after colon if static item does not fit in a single line 2018-01-10 23:23:42 +09:00