Commit graph

1042 commits

Author SHA1 Message Date
Stéphane Campinas
9467033a8e
fix the logic for retaining a comment before the arrow in a match 2018-11-07 15:00:33 +01:00
Kevin Stenerson
cd8bb50aea Trim the indentation on macros which heuristically appear to use block-style indentation (#3178) 2018-11-07 17:49:53 +09:00
Kevin Stenerson
25b828d35f Add config option to more aggressively allow overflow 2018-11-05 21:12:40 -07:00
Nick Cameron
16d5f507b6
Merge pull request #3172 from scampi/issue3153
trim the start of a line when wrapping an item in preparation for formatting
2018-11-06 10:23:30 +13:00
Stéphane Campinas
5a2ebdddcc
trim the start of a line when wrapping an item in preparation for formatting 2018-11-05 20:22:06 +01:00
Rémy Rakic
83d1d9aa14 normalize_doc_attributes: remove leading whitespace from the doc comment opener
Remove possible whitespace from the `CommentStyle::opener()` so that the literal itself has control over the comment's leading spaces.

This is most useful for tools, such as bindgen, to allow for example: machine-readable comments with precise syntax rules, or idempotently round-tripping between the proc-macro API and rustfmt.
2018-11-05 18:24:36 +01:00
Stéphane Campinas
7132fe03a0
fix alignment of a struct's fields with the visual style
- rewrite_with_alignment was called from the expr module with the wrong
  shape that missed the extra offset needed for the visual style
- rewrite_with_alignment was indenting the given shape although that
  should have been the caller's responsability
2018-11-04 23:41:21 +01:00
Stéphane Campinas
2d718a3fc2
The method trim_left_preserve_layout didn't handle tabs properly.
This is fixed by taking the method macros::indent_macro_snippet which
essentially does the same: it indents a paragraph while preserving the
layout.
2018-10-30 20:24:03 +01:00
Emilio Cobos Álvarez
4a82252f03
missed-spans: Fix bogus check.
I don't really know what it's trying to do, but forgetting about everything
you've seen before when you see whitespace followed by a semicolon doesn't look
right to me, and absolutely no tests were hitting that.

This check was introduced in 5ecdd072d6, however
it was wrong even at that point, and now rustfmt still passes that test,
regardless of macro name.

Fixes #3154.
2018-10-30 03:21:28 +01:00
Seiichi Uchida
131f11a6e5 Add a test for #3139 2018-10-27 11:22:18 +09:00
Seiichi Uchida
2d0487164f Add a test for #3137 2018-10-26 16:36:01 +09:00
Nick Cameron
825207dd2e
Merge pull request #3126 from topecongiro/issue-3117
Use correct width when formatting type on local statement
2018-10-23 10:35:32 +13:00
Seiichi Uchida
cf44c079c1 Add a test for #3117 2018-10-22 22:20:48 +09:00
Matthias Krüger
b25f974c0d fix a few typos found via codespell. 2018-10-19 12:28:00 +02:00
Nick Cameron
e633f2b3f5
Merge pull request #3109 from scampi/issue-3038
force a newline after the `if` condition if there is a different indentation level
2018-10-18 19:56:17 +13:00
Seiichi Uchida
8c4e92a14e
Catch parser panic in format_snippet (#3103) 2018-10-17 14:21:04 +09:00
Stéphane Campinas
30c06da781
force a newline after the if condition if there is a different
indentation level
2018-10-15 23:24:35 +02:00
Nick Cameron
5f02be6294
Merge pull request #3102 from nrc/arm-guard-newline
Only put `{` on a newline in a match arm where necessary
2018-10-16 09:06:15 +13:00
Nick Cameron
bc4414e53c
Merge pull request #3101 from nrc/pair-newline
Simplify multi-lining binop exprs
2018-10-16 09:01:40 +13:00
Daniele D'Orazio
075aa909cd try to fix comment bad wrapping (#3099) 2018-10-15 11:18:37 +09:00
Nick Cameron
e2be62c7a5 Add test (issue 3005) 2018-10-15 14:09:31 +13:00
Nick Cameron
7be173eb8c add test 2018-10-15 12:09:53 +13:00
Nick Cameron
a6ef302236
Merge pull request #3100 from topecongiro/issue-3092
Fix poor formatting of empty trait with generic bounds
2018-10-15 08:07:59 +12:00
Nick Cameron
2f8c1fea72
Merge pull request #3093 from scampi/issue2633
do not vertically align list items in case the tactic is Horizontal
2018-10-15 07:57:39 +12:00
Nick Cameron
945fb504b1
Merge pull request #3091 from topecongiro/issue-3060
Do not add parens around lifetimes
2018-10-15 07:40:34 +12:00
Seiichi Uchida
476992a15d Add a test for #3092 2018-10-14 21:47:50 +09:00
Otavio Salvador
ef59b34cd7 Avoid control flow expressions conditions to go multi line
Extends the multi line condition to over other control flow
expressions, it now covers: `if`, `if let`, `for`, `loop`, `while`,
`while let` and `match`.

Refs: #3029

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2018-10-13 14:12:43 -03:00
Stéphane Campinas
8f7a0470b0
handle lines prefixed with a # inside code blocks 2018-10-13 09:57:43 +02:00
Otavio Salvador
8feeddf1f8 Only combine match if its condition expression fits in a single line
This improves the formatting and reading of code avoiding the
condition expression to be rewrite, if it goes multi line.

Fixes: #3029.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2018-10-12 20:12:45 -03:00
Seiichi Uchida
6b33043e06 Add a test for #3060 2018-10-13 00:42:22 +09:00
Nick Cameron
8b709c0019 Add attr_fn_like_width to the width heuristics
It is a bit larger than than `fn_call_width` which we used previously, so fewer attributes get reformatted.

Closes #2929
2018-10-12 15:20:42 +13:00
Seiichi Uchida
b2de574848 Add format_doc_comments 2018-10-11 23:34:36 +09:00
Nick Cameron
4895699e88
Merge pull request #3083 from scampi/itemized_blocks
Handle itemized blocks in comments
2018-10-10 10:38:54 +12:00
Stéphane Campinas
375c87820f
rewrite_string: detect when a url is being split and place the new line
after it
2018-10-09 21:47:32 +02:00
Stéphane Campinas
c0b7222e2d
handle itemized items inside comments 2018-10-09 00:44:59 +02:00
Seiichi Uchida
a925bdf092 Add a test for #3031 and update test
No combining for an item-like macro argument.
2018-10-08 13:50:00 +09:00
Nick Cameron
1b2e72726f
Merge pull request #3078 from YaLTeR/fix-closure-indentation
Fix inconsistent overflow behavior in Visual style
2018-10-08 14:38:49 +13:00
Nick Cameron
832a912f79
Merge pull request #3077 from YaLTeR/fix-extra-commas
Get rid of extra commas in Visual struct literal formatting
2018-10-08 14:37:48 +13:00
Nick Cameron
4dc5557625
Merge pull request #3070 from topecongiro/issue-3030
Format a paren expr with double slash comment
2018-10-08 13:05:36 +13:00
Ivan Molodetskikh
6dc9b96651
Add a test for #3049 2018-10-06 16:32:27 +03:00
Ivan Molodetskikh
cfe20fe585
Add a test for #3066 2018-10-06 10:59:47 +03:00
Seiichi Uchida
efe24bd7e7 Add a test for #3030 2018-10-01 00:06:37 +09:00
Seiichi Uchida
4a15875f07 Add a test for #3003
and run cargo fmt.
2018-09-30 23:28:03 +09:00
Nick Cameron
3dc6eed601
Merge pull request #2816 from moxian/enum-discrim
Add option to vertically align enum discriminants.
2018-09-28 21:48:57 +12:00
Stéphane Campinas
2bcc3a9302 do not format a code block in documentation if it is annotated with ignore or text (#3058) 2018-09-28 11:06:29 +09:00
moxian
65ae0b9a09 Change enum align semantics to care about absolute length, rather than difference.
If we're only aligning enum discriminants that are "not too far apart
(length-wise)", then this works really well for enums with
consistently-long or consistently-short idents, but not for the mixed
ones.
However, consistently-long idents is somewhate of an uncommon case and
overlong idents may be allowed to be formatted suboptimally if that
makes mixed-length idents work better (and it does in this case).
2018-09-26 18:47:17 +00:00
moxian
cc22869fb4 Add option to vertically align enum discriminants. 2018-09-26 14:35:38 +00:00
Nick Cameron
ac6871f376
Merge pull request #3048 from emilio/merged-comments
lists: Detect block comment by starting from the end.
2018-09-24 14:22:01 +12:00
Emilio Cobos Álvarez
66c15e46ba
lists: Detect block comment by starting from the end.
The issue with the current code is that comments are collapsed, so comments like
the one from the test end up in a string like:

```
"// this is a single line comment\n/* block = */"
```

I chose to fix it by detecting whether we're in a block comment starting from
the end instead, and tested a single-line comment ended in `*/` just for sanity,
ensuring line breaks are not removed in that case, which would break the
formatting.

The right fix eventually is probably to lex the comments properly, but this does
the work for now, I guess :)

Fixes #3025
2018-09-22 12:16:38 +02:00
Stéphane Campinas
5fdb6db136
Prevent right-shifting of block comments with bare lines.
Lines that didn't start with a comment sigil were returned unchanged in
comment::rewrite_comment. Then these unchanged lines were indented in
MacroBranch::rewrite.
2018-09-22 00:09:11 +02:00
Seiichi Uchida
ec32c961d3 Add a test for #3040 2018-09-21 00:57:46 +09:00
Seiichi Uchida
8021b29405 Add a test for #3006 2018-09-19 22:33:25 +09:00
Nick Cameron
829dbfabe9
Merge pull request #3028 from scampi/issue2973
Fix indent computation of a macro with braces.
2018-09-19 11:31:28 +12:00
Nick Cameron
1739041f03
Merge pull request #3002 from lqd/normalize-doc-attributes
normalize_doc_attributes option: convert doc attributes to comments
2018-09-19 11:05:27 +12:00
Nick Cameron
2267c2cddc
Merge pull request #3001 from scampi/issue2977
propagate errors about failing to rewrite a macro
2018-09-19 10:43:21 +12:00
Seiichi Uchida
661bea71c1
Merge pull request #3013 from YaLTeR/fix-issue-2985
Fix wrong shape for last chain items for indent_style = "Visual"
2018-09-18 20:21:21 +09:00
Nick Cameron
01c14a2058
Merge pull request #3012 from YaLTeR/fix-issue-2496
Fix match arm block flattening
2018-09-18 21:12:12 +12:00
Stéphane Campinas
c3edf6d3a1
Fix indent computation of a macro with braces.
The leading whitespace of a multine string was taken into account when
computing the `min_prefix_space_width`, even if that line couldn't be
trimmed. The consequence is it was always shifting the macro's content
to the right.
2018-09-18 00:01:51 +02:00
Rémy Rakic
0c73b9414b add test ensuring only doc = "" attributes are normalized to comments
The other shapes of doc attributes shouldn't be normalized or modified.
2018-09-13 02:40:24 +02:00
Rémy Rakic
cbc58410d9 add tests interleaving doc attrib comments and regular comments 2018-09-13 02:27:09 +02:00
Rémy Rakic
171e656f64 add non-regression test to existing attributes
when `normalize_doc_attributes` is on, they shouldn't be affected
2018-09-13 01:10:57 +02:00
Rémy Rakic
4af0888648 add non-regression test to existing doc attributes
when `normalize_doc_attributes` is off, they shouldn't be normalized to a doc comment
2018-09-13 01:06:02 +02:00
Rémy Rakic
43f813867c add test with multiple levels of indents 2018-09-13 01:02:11 +02:00
Nick Cameron
e39bd35ae1
Merge pull request #3010 from topecongiro/issue-3009
Refactor the corner case of handling long function
2018-09-12 13:55:41 +12:00
Ivan Molodetskikh
2f03a31e1a
Add a visual fn type alias test 2018-09-11 12:34:21 +03:00
Ivan Molodetskikh
abcdc0fadd
Add a test for #2985 2018-09-11 11:09:31 +03:00
Ivan Molodetskikh
f116baeed7
Add a test for match flattening 2018-09-11 08:54:43 +03:00
Ivan Molodetskikh
bc03234e25
Add a test for #2496 2018-09-11 08:54:43 +03:00
Seiichi Uchida
9674e12a5c Add a test for #3009 2018-09-11 13:30:36 +09:00
Nick Cameron
77824a24ef
Merge pull request #2988 from YaLTeR/fix-issue-2922
Use correct indent in rewrite_bare_fn with Visual style
2018-09-11 15:50:13 +12:00
lqd
4b7130dfa1 normalize_doc_attributes option: convert doc attributes to comments
Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
2018-09-07 21:58:35 +02:00
Stéphane Campinas
6f318e3cef
propagate errors about failing to rewrite a macro 2018-09-07 14:48:52 +02:00
Nick Cameron
f655671e12
Merge pull request #2983 from topecongiro/issue-2642
Handle raw string literals in CharClasses
2018-09-04 19:11:49 +12:00
Nick Cameron
a67208f212
Merge pull request #2986 from topecongiro/issue-2907
Handle chain w/ try operators with spaces
2018-09-03 13:10:50 +12:00
Ivan Molodetskikh
430f848c75
Add a test for #2922 2018-08-31 16:25:01 +03:00
Ivan Molodetskikh
098a5391f0
Add a test for #2930 2018-08-31 15:25:08 +03:00
Seiichi Uchida
1b8f0ff1b6 Add a test for #2907 2018-08-31 18:10:47 +09:00
Ryan Leckey
eec74360dc Accept 2015 and 2018 instead of Edition2015 and Edition2018 for edition option 2018-08-31 00:04:23 -07:00
topecongiro
67480422b9 Handle raw string literal without any sharps 2018-08-31 10:49:39 +09:00
topecongiro
c903119d8d Add a test for #2642 2018-08-31 10:37:22 +09:00
Seiichi Uchida
d8301050a5 Add a test for #2956 2018-08-30 23:38:40 +09:00
crw5996
d832525809 Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into fix-use-bug 2018-08-27 23:04:55 -04:00
crw5996
20075306f7 Fixed Issues brought up in PR 2018-08-27 22:59:44 -04:00
crw5996
3585706fa2 Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into fix-optional-arg-condensing 2018-08-27 13:44:56 -04:00
Seiichi Uchida
e1069403ca Add a test for #2969 2018-08-27 16:12:11 +09:00
Nick Cameron
97d29ff2e1
Merge pull request #2942 from crw5996/fix-ellipsis-bug
Fix Issue with ellipsis matching in pattern.rs
2018-08-27 09:44:28 +12:00
Zach Lute
ca19c9a35a Fix build with rust nightly by updating try block syntax. (#2965) 2018-08-26 13:02:24 +09:00
Maximilian Roos
10512a59d0 Impl only use (#2951) 2018-08-24 14:39:05 +09:00
chris
4e748a269e Fixed ellipsis bug where rustfmt was creating code that could not be parsed 2018-08-24 00:58:21 -04:00
cad97
04d804c365 Rename CodeMap/FileMap to SourceMap/SourceFile
#2946
2018-08-23 17:10:46 -04:00
Nick Cameron
8573df602a
Merge pull request #2925 from scampi/issue539
discard trailing blank comments
2018-08-23 10:13:56 +12:00
Seiichi Uchida
dfe4eef8fc Remove an invalid attribute from a test
This has become a parser error.
2018-08-19 00:26:56 +09:00
Stéphane Campinas
f23e6aaaf9
fix the identification of a block comment.
Block comments like below were not properly supported:

    /*
       something here but it doesn't start with a star
     */

because of the line that didn't start with a star.
2018-08-16 19:55:15 +02:00
Seiichi Uchida
71dc033fca Add a test for #2919 2018-08-16 07:49:50 +09:00
Seiichi Uchida
996dbbf960 Add a test for slice patterns 2018-08-12 23:55:34 +09:00
Nick Cameron
66d3924aa8
Merge pull request #2899 from topecongiro/chain-with-comments
Format chains with comment
2018-08-07 15:07:23 +12:00
Nick Cameron
e4d560b914
Merge pull request #2897 from topecongiro/issue-2896
Ignore comment in wrap_str
2018-08-06 19:36:03 +12:00
Seiichi Uchida
7bccc4473c Add a test for chains with comment 2018-08-05 21:04:06 +09:00
Seiichi Uchida
c19569c5d3 Add a test for #2896 2018-08-05 10:50:24 +09:00
Seiichi Uchida
cf13534150 Add a test for #2884 2018-08-04 09:59:19 +09:00