Only change multiline comments of the form
```rust
/*
* Text
*/
```
while not affecting comments of the form
```rust
/*
Text
*/
```
when normalize_comments is off. In the first case,
we have a known character we can align against, while
we don't have one in the second case.
Before, we have converted the second form into the first,
but this is against the spirit of normalize_comments being
turned off.
Fixes#956
* Split impl at 'for' if a line break is needed
* Fix formatting
* Improve comments
* Skip second try if there is no 'for'
* Restore intentional trailing whitespace
* Change test source to be incorrectly formatted
* Restore more missing trailing whitespace
* Remove too much whitespace...
Really should learn how to use git revert.
* Change required to prevent a trailing space at the end of a separate module being propagated
* Detect the start of the output file rather than the start of the input file when deciding whether to output preceding snippets - this stops unnecessary whitespace and blank lines from being inserted when spans and statements are output in an order other than that from the input file.
* Add code to prevent space from being added with the prefix snippet if a) the snippet is entirely horizontal whitespace, or b) the snippet contains whitespace followed by a newline. This prevents trailing spaces at the end of a line from being added.
* Tests for this issue
* Tidy up `match` statements
* Add test with blank lines between `use` statements
* Fix issue-1049
* Add testcase suggested by pepyakin
* Fix last commit
* Handle special case
* Remove debugging println
* Fix grammar in comment
* Change word in comment
* Add test for long func without ret type
* Add one more test
* Add config options for combinations of lines and items
* Reordering of import lines implemented.
* Changed nested matches to tuple pattern matching
* Added ordering of path list items to the ordering of use declarations
* Move `format_imports` and `format_import` methods to `imports.rs`
* Add comment to explain how `use` declarations are split off while walking through a module
* Change `ImportReordering` config option to separate boolean options
This will help in debugging issues as rustfmt gets more users.
If the working tree is clean, output looks like
$ target/debug/rustfmt -V
0.5.0 (9f5ed3b)
If the working tree is dirty, output looks like
$ target/debug/rustfmt -V
0.5.0 (9f5ed3b worktree dirty)
If git is unavailable, output looks like
$ target/debug/rustfmt -V
0.5.0 (git commit unavailable)
To avoid rebuilds on changing tests, the build script will only rerun if
files under src/ are changed. This means the actual git status may show
changed files and this would not show up in the version. This should not
be an issue as files not in src/ should not affect the build output.
This commit adds a very rough implementation of handling the specified
line ranges in `config.file_lines_map` for statements. It reformats a
statement if its span is fully contained in the set of lines specified
for the file.
The implementation here is intended as a proof of concept, and
demonstration that the machinery added in the preceding commits is
functional. A final implementation would likely hook in via the
`Rewrite` trait.
Refs #434
* Handle pub(restricted)
This commit properly handles pub(restricted) as introduced in RFC 1422
[0]. The syntax support was added in #971, but they were not correctly
formatted.
[0] https://github.com/rust-lang/rfcs/blob/master/text/1422-pub-restricted.mdFixes#970
* Drop #[inline] attribute on format_visibility
* Make newly non-failing functions return String
The change to `format_visibiilty` means that `format_header` and
`format_unit_struct` can no longer fail. Their return type is updated to
reflect that.
The old behaviour stored everything in memory until we were finished. Now we write as soon as we can.
This gives better behaviour when formatting large programs, since there is some progress indication. It also opens the door to optimising memory use by not storing everything in memory unless it is required (which it still might be). That is left as future work though.
* Handle attributes (including doc comments) on inline modules
Closes#22Closes#684
* Tweak the rules for changing indentation in comments (to do it less often).
* Fix closures again
Closes#934
Oh god, the rules for parsing closures are even more messed up than I thought - whether or not there is an inner block or depends not only on if there are braces, but also if there is a return type for the closure (!) and if there are statements in the block.
* Fix overflow
We will no longer break in the middle of words, only at whitespace or punctuation.
This means we sometimes over-run, but that seems better than some of the bad splits we see.
Closes#369
* change layout so that test group `foo` has source files in
`test/foo/source` and target files in `test/foo/target`.
* use significant comments to specify write mode instead of threading
Option<WriteMode>
If set, arguments will be kept on one line if they fit. Currently only
applies when `fn_args_layout` is set to `Block`.
This commit also fixes a bug where newlines were inserted inbetween
argument brackets when there were no arguments and `fn_args_layout` was
set to `Block`.
Removed unneeded comment
Commented line wrapping conditions
Removed prefix param on `rewrite_associated_type`
Merged `rewrite_associated_static` into `rewrite_static`
Added extra tests
This commit tidies up handling of `write_mode` by setting it in the
config at the start, and removing the `write_mode` parameter threaded
throughout the formatting process.
`Result::expect()` was added in Rust 1.4. Using it tidies up the code,
and also helps by printing error details, eg, printing syntax error
details if a regex fails to compile. It adds a colon followed by the
`Debug` output from any error, making the periods in messages
unnecessary.
Fix up the checkstyle test so they pass. There is still an issue with
the content, but I think that is caused by a problem with how diffs are
being calculated presently.
Also from @marcusklaas:
Refactor code output functions
Specifically, `write_all_files` no longer returns a HashMap. It would sometimes
contain items, and sometimes be empty. When "fixed" newlines are required, this
must now be done with a separate call. The tests use this strategy and should now pass!
When the reformatted code doesn't contain the same quantity of comments
as the original code, use the original code instead of the reformatted
code.
This is done for all expressions and `let` statements.
This should be used at the finest grained level possible, to avoid that
a small disappearing comment prevents a big chunk of code to be
reformatted.
Kind of fixes (avoid disappearing comments, but prevents a good
formatting is such case) #285#225#563#743