Commit Graph

1963 Commits

Author SHA1 Message Date
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
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
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