Commit Graph

1854 Commits

Author SHA1 Message Date
Caleb Cartwright
1ac2ac0db6 Merge remote-tracking branch 'upstream/master' into subtree-sync-2022-06-07 2022-06-07 22:06:28 -05:00
Caleb Cartwright
79515f17ed feat: remove license_template_path config option 2022-05-30 08:56:09 -05:00
Caleb Cartwright
825561deb8 feat: remove report_fixme option 2022-05-30 08:56:09 -05:00
Caleb Cartwright
4c8db85939 feat: remove report_todo option 2022-05-30 08:56:09 -05:00
Jacob Pratt
241a6f6930 Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
ydah
86940d2652 Fix typo
This PR is fixes typo "avaiable" to "available".
2022-05-20 10:39:10 +09:00
David Lattimore
95837832f4 import_granularity: Don't normalize imports with comments 2022-05-18 21:08:30 -05:00
Yacin Tmimi
b08b2daeb6 Add test for issue 3937
Closes 3937

It's unclear which change fixed the `format_code_in_doc_comments=true`
issue brought up in this issue, however I'm unable to reproduce the
error on the current master.

The added test cases should serve to prevent a regression.
2022-05-17 17:17:07 -05:00
Pascal Seitz
c65ba14d69 Fixes #5260
Fixes #5260 by checking if it is part of a type '::'
2022-05-08 13:22:35 -05:00
Yacin Tmimi
3cc1f5ed5b Add tests for issue 4573
It's unclear which PR resolved this issue, however the behavior of
adding inline comments to the next line can't be reproduced.

These test cases should serve to prevent a regression.
2022-05-08 12:55:43 -05:00
cuishuang
c03e1842f6 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-07 11:10:59 -05:00
hkalbasi
a37d3ab0e1 Memoize format_expr 2022-04-17 09:32:43 -05:00
Tom Milligan
acdab00ecc [review] check interaction with import grouping 2022-04-17 09:28:48 -05:00
Paul Gey
ba0351a146 Preserve attributes for imports_granularity=Item
Fixes #5030
2022-04-17 09:28:48 -05:00
Tom Milligan
4f3f87fb9a group_imports: test and document non-consecutive imports 2022-04-11 17:46:33 -05:00
Tharun Rajendran
1dcdfb276d
fix(rustfmt): fix struct field formatting with doc comments present (#5217)
* fix(rustfmt): fix struct field formatting with doc comments present

Fixes #5215

* fix review feedbacks

* add unit test without doc comment

* move tests to a seperate file

* add additional test cases

* reintroduce a newline at the of test/souce/structs.rs
2022-04-01 19:00:53 -05:00
Caleb Cartwright
8211d64c71 Merge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree 2022-03-29 23:17:30 -05:00
David Tolnay
5ff7b632a9 Preserve semicolon after macro call inside foreign mod 2022-03-29 22:20:11 -05:00
David Tolnay
8e94761a94 Add test of macro calls inside extern block 2022-03-29 22:20:11 -05:00
Caleb Cartwright
e0c7b7d5d3 tests: ignore cargo fmt test for rust-lang/rust runs 2022-03-28 21:33:45 -05:00
Yacin Tmimi
8984438a6f Honor #[rustfmt::skip::attributes(derive)] attribute
Fixes 5270

Previously, rustfmt only checked the `merge_derives` configuration value
to determine if it should merge_derives. This lead to derives being
merged even when annotated with the `rustfmt::skip` attribute.

Now, rustfmt also checks if derives are explicitly being skipped in the
current context via the `rustfmt::skip` attribute.
2022-03-21 16:56:34 -05:00
123vivekr
0dba01aee1 Add short_item_threshold config option
Allow custom short item threshold values via config
2022-03-21 16:56:09 -05:00
Yacin Tmimi
e41329ce87 Search for struct body span after any generic arguments
Fixes 5273

Previously, rustfmt searched for the start of a struct body after the
opening `{`. In most cases this works just fine, but const values can
also be defined between `{ }`, which lead to issues when rewriting the
struct body.

Now, rustfmt will search for the `{` after the generic argument list to
guarantee that the `{` it finds is the start of the struct body.
2022-03-20 21:39:12 -05:00
Tom Milligan
b4de150dbc fix: imports_granularity module with path containing self 2022-03-12 10:47:46 -06:00
Yacin Tmimi
18c0369688 Improve mod resolution error for mods with multiple candidate files
Fixes 5167

When ``a.rs`` and ``a/mod.rs`` are both present we would emit an error
message telling the user that the module couldn't be found. However,
this behavior is misleading because we're dealing with an ambiguous
module path, not a "file not found" error.

Is the file ``a.rs`` or is it ``a/mod.rs``? Rustfmt can't decide, and
the user needs to resolve this ambiguity themselves.

Now, the error message displayed to the user is in line with what they
would see if they went to compile their code with these conflicting
module names.
2022-03-08 21:51:23 -06:00
cassaundra
58de4142c5 Add test for issue #4791 2022-03-06 11:23:50 -06:00
cassaundra
ab9f2a8ac7 Add more tests for struct_field_align_threshold and trailing_comma 2022-03-06 11:23:50 -06:00
cassaundra
ee130515e3 Fix missing struct field separators under certain conditions
When struct_field_align_threshold is non-zero and trailing_comma is set to
"Never," struct field separators are omitted between field groups. This issue is
resolved by forcing separators between groups.

Fixes #4791.

A test is included with a minimal reproducible example.
2022-03-06 11:23:50 -06:00
Yacin Tmimi
272fb42f06 Prevent wrapping markdown headers in doc comments
Fixes 5238

A markdown header is defined by a string that starts with `#`.

Previously, rustfmt would wrap long markdown headers when
`wrap_comments=true`. This lead to issues when rendering these headers
in HTML using rustdoc.

Now, rustfmt leaves markdown headers alone when wrapping comments.
2022-02-28 23:25:49 -06:00
Yacin Tmimi
12048e444f fallback to dir_path when relative external mod resolution fails
We only want to fall back if two conditions are met:

1) Initial module resolution is performed relative to some nested
   directory.
2) Module resolution fails because of a ModError::FileNotFound error.

When these conditions are met we can try to fallback to searching for
the module's file relative to the dir_path instead of the nested
relative directory.

Fixes 5198

As demonstrated by 5198, it's possible that a directory name conflicts
with a rust file name. For example, src/lib/ and src/lib.rs.

If src/lib.rs references an external module like ``mod foo;``, then
module resolution will try to resolve ``foo`` to src/lib/foo.rs or
src/lib/foo/mod.rs. Module resolution would fail with a file not
found error if the ``foo`` module were defined at src/foo.rs.

When encountering these kinds of module resolution issues we now fall
back to the current directory and attempt to resolve the module again.

Given the current example, this means that if we can't find the module
``foo`` at src/lib/foo.rs or src/lib/foo/mod.rs, we'll attempt
to resolve the module to src/foo.rs.
2022-02-28 23:13:11 -06:00
Caleb Cartwright
281bf03e64 fix: formatting in new test 2022-02-15 21:24:39 -06:00
Cameron Steffen
d5aabccfeb Format code 2022-02-15 19:44:53 -06:00
Yacin Tmimi
1e78a2b258 Leverage itemized blocks to support formatting markdown block quotes
Fixes 5157

Doc comments support markdown, but rustfmt didn't previously assign any
semantic value to leading '> ' in comments. This lead to poor formatting
when using ``wrap_comments=true``.

Now, rustfmt treats block quotes as itemized blocks, which greatly
improves how block quotes are formatted when ``wrap_comments=true``.
2022-02-11 17:31:06 -06:00
Tharun Rajendran
b05b313800
chore(rustfmt): remove executable path from usage string (#5216)
* chore(rustfmt): remove executable path from usage string

* add unit test for usage string

* rename test and check usage text in a single assert
2022-02-10 22:35:45 -06:00
Gabriel Smith
ace7241087 Fix incorrect string indentation in macro defs with format_strings 2022-02-10 21:02:59 -06:00
Frank King
5df8c8f7e5
Fix doc of generic items formmating error (#5124)
* Fix doc of generic items formmating error

* Remove tracked `attrs_end_with_doc_comment` flag in `RewriteContext`

* Fix duplicated doc comments of const generic params

* Fix `<ast::GenericParam as Spanned>::span()`

* Remove duplicated source file of `doc-of-generic-item.rs`
2022-02-06 20:57:39 -06:00
Stéphane Campinas
fd6e11cc57 Add tests for the One and Crate variants 2022-02-03 18:56:53 -06:00
Stéphane Campinas
b2c7a52ea8 Fix import_granularity option when the use tree has an alias 2022-02-03 18:56:53 -06:00
Yacin Tmimi
606894eb0b Retain trailing separator when extracting the last inline post comment
Fixes 5042

Previously, trailing commas were removed from the last inline comment.
This lead to rustfmt refusing to format code snippets because
the original comment did not match the rewritten comment.

Now, when rustfmt extracts the last inline comment it leaves trailing
separators alone. Rustfmt does not need to remove these separators
because they are commented out.
2022-02-03 18:52:58 -06:00
Stéphane Campinas
368a9b7cef
Handle non-ascii character at boundary (#5089)
* Handle non-ascii character at boundary

* Replace substraction underflow check with early termination
2022-02-01 19:06:14 -06:00
Yacin Tmimi
8b0b213cdd Prevent adding trailing whitespace when rewriting ast::Param
Fixes 5125

Previously, a newline was always added, even if the parameter name was
not preceded by any param attrs.

Now a newline is only added if there were param attrs.
2022-01-29 12:20:34 -06:00
Szymon Gibała
b4a4bf0bf8
Fix formatting of comments in empty structs (#5171)
* Fix formatting of comments in empty structs

* Add tests

* Add single line tests

* Fix block comments

* Revert changes of test source files
2022-01-28 22:55:47 -06:00
Seiichi Uchida
34d374ee5d Use <stdin> when emitting stdin as filename (#4298)
# Conflicts:
#	src/config/file_lines.rs
#	src/rustfmt/main.rs
#	src/test/mod.rs
2022-01-02 10:06:06 -06:00
Tim
894a3c0e77 Fix newlines in JSON output (#4262)
* Fix newlines in JSON output

This changes the JSON output to be more consistent about where newlines are included. Previously it only included them between lines in a multiline diff. That meant single line changes were treated a bit weirdly. This changes it to append a newline to every line.

When feeding the results into `arc lint` this behaves correctly. I have only done limited testing though, in particular there's a possibility it might not work with files with `\r\n` endings (though that would have been the case before too).

Fixes #4259

* Update tests
# Conflicts:
#	tests/writemode/target/output.json
2022-01-02 10:06:06 -06:00
Caleb Cartwright
776baf93f8 refactor: update json emitter to better handle errors (#3953) 2022-01-02 10:06:06 -06:00
Chris Emerson
93b7de5b01 Make --check work when running from stdin. (#3896)
# Conflicts:
#	src/bin/main.rs
2022-01-02 10:06:06 -06:00
Yacin Tmimi
737e6f7046 Improve out of line module resolution
Fixes 5119

When the directory structure was laid out as follows:

```
dir
 |---mod_a
 |    |---sub_mod_1.rs
 |    |---sub_mod_2.rs
 |---mod_a.rs
```

And ``mod_a.rs`` contains the following content:

```rust
mod mod_a {
    mod sub_mod_1;
    mod sub_mod_2;
}
```

rustfmt previously tried to find ``sub_mod_1.rs`` and ``sub_mod_2.rs``
in ``./mod_a/mod_a/``. This directory does not exist and this caused
rustfmt to fail with the error message:

    Error writing files: failed to resolve mod

Now, both ``sub_mod_1.rs`` and ``sub_mod_2.rs`` are resolved correctly
and found at ``mod_a/sub_mod_1.rs`` and ``mod_a/sub_mod_2.rs``.
2022-01-01 10:27:49 -06:00
Caleb Cartwright
6db6bafc61 Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree 2021-12-29 20:49:39 -06:00
David Lattimore
4a053f206f Do not flatten match arm block with leading attributes
This is a backport of #4124.

Fixes #4109
2021-12-29 17:43:58 -06:00
Yacin Tmimi
76eb077fb2 Retain qualified path when rewriting struct literals
Fixes 5151

Details about the qualified path are now passed along so that rustfmt
can include them when formatting struct literals.
2021-12-23 23:04:26 -06:00