Commit Graph

3531 Commits

Author SHA1 Message Date
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
Jack Huey
1212c9477c Change syntax for TyAlias where clauses 2022-03-05 13:13:45 -05:00
Felix S. Klock II
ce301d92f1 Placate tidy in submodule. 2022-03-04 17:05:30 -05:00
Felix S. Klock II
651f46376a Adjusted diagnostic output so that if there is no use in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.
2022-03-03 18:58:37 -05:00
Felix S. Klock II
74876ef4e9 Associate multiple with a crate too. 2022-03-03 18:45:25 -05:00
Felix S. Klock II
4edb757826 refactor: prepare to associate multiple spans with a module. 2022-03-03 14:38:50 -05: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
Mark Rousskov
de1ac375f0 Enable rustc_pass_by_value for Span 2022-02-25 08:00:53 -05:00
Caleb Cartwright
89ca3f3a10 fix: unused test imports on non-nightly, prevent regression 2022-02-23 22:51:32 -06:00
Eduard-Mihai Burtescu
5723946081 rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00
Eduard-Mihai Burtescu
7592663e85 rustc_errors: add downgrade_to_delayed_bug to Diagnostic itself. 2022-02-23 03:46:51 +00:00
Cameron Steffen
c63d42e804 Use cargo-fmt in self_tests 2022-02-15 19:44:53 -06:00
Travis Finkenauer
6c476127ae
Add context to get_toml_path() error (#5207)
* rustfmt: print full error chain

* Add context to get_toml_path() error

Instead of an error like:

```
Permission denied (os error 13)
```

Gives error like:

```
Failed to get metadata for config file "/root/.rustfmt.toml": Permission denied (os error 13)
```
2022-02-15 17:25:44 -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
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
Eduard-Mihai Burtescu
3572c542c2 rustc_errors: only box the diagnostic field in DiagnosticBuilder. 2022-01-24 11:23:14 +00:00
Caleb Cartwright
9e1973f1d9 chore: bump toolchain, update test 2022-01-23 11:18:17 -06:00
Caleb Cartwright
9b454a5990 Merge remote-tracking branch 'upstream/master' into subtree-sync-2022-01-23 2022-01-23 11:07:20 -06:00
kadmin
7913f130d3 Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00
kadmin
cf86d53202 Add term
Instead of having a separate enum variant for types and consts have one but have either a const
or type.
2022-01-17 17:20:57 +00:00
kadmin
f5ce84e4f2 add eq constraints on associated constants 2022-01-17 17:20:57 +00:00
bors
8ae2312e34 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
Caleb Cartwright
bfbf42cecb fix(rustfmt): resolve generated file formatting issue 2022-01-14 18:18:37 -06:00
Tomasz Miąsko
04670a1404 Remove LLVM-style inline assembly from rustfmt 2022-01-12 21:43:35 +01:00
Lamb
6e6300207f Compute most of Public/Exported access level in rustc_resolve
Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
2022-01-09 21:33:14 +00:00
Matthias Krüger
5056f4cfb3 some minor clippy fixes 2022-01-05 17:53:27 -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
34263cd6bd Fix --check -l with stdin. (#3910)
* Fix some possible panics when using `--check` with stdin.

One case which doesn't work is when there are only line ending fixes;
with stdin rustfmt is unable to detect the difference as it stores
the input with Unix line endings.

* Add test for `rustfmt --check -l` with stdin.
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
Caleb Cartwright
f935f0cf89 feat: support parsing asm! args 2021-12-28 20:25:17 -06:00
Caleb Cartwright
e8afb62c71 chore: reduce some vis. for updated unreachable_pub lint 2021-12-27 18:16:04 -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
David Tolnay
0b2fd9b132 Fix static async closure qualifier order 2021-12-23 23:03:49 -06:00
Caleb Cartwright
7b8303d479 chore: cleanup unused imports 2021-12-21 10:55:39 -06:00
Caleb Cartwright
97c3e48834 refactor: encapsulate cfg_if parsing within parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright
62987562e2 refactor: extract final rustc_parse touchpoint from macros.rs 2021-12-21 10:55:39 -06:00
Caleb Cartwright
c8cf454173 refactor: move lazy_static parsing to parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright
9ce5470a8c refactor: move macro arg parsing to parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright
40b73d8fee refactor: rename syntux mod to parse 2021-12-21 10:55:39 -06:00
Caleb Cartwright
8bf82aeb83 Merge remote-tracking branch 'upstream/master' into subtree-sync-2021-12-19 2021-12-19 15:22:45 -06:00
Nicholas Nethercote
122e1c3802 Remove unnecessary sigils around Ident::as_str() calls. 2021-12-15 17:32:42 +11:00
Nicholas Nethercote
3bb5f81d8d Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote
b4afb38f2f Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Yacin Tmimi
57ac92bf16 Prevent duplicate comma when formatting struct pattern with ".."
Fixes 5066

When a struct pattern that contained a ".." was formatted, it was
assumed that a trailing comma should always be added if the struct
fields weren't formatted vertically.

Now, a trailing comma is only added if not already included in the
reformatted struct fields.
2021-12-14 13:28:25 -06:00
Matthias Krüger
740fb57f5d clippy fixes 2021-12-13 20:36:12 -06:00
Yacin Tmimi
f40b1d9f1a Backport: Do not touch module with #![rustfmt::skip] (4297)
Although the implementation is slightly different than the original PR,
the general idea is the same. After collecting all modules we want to
exclude formatting those that contain the #![rustfmt::skip] attribute.
2021-12-07 18:45:00 -06:00
Caleb Cartwright
0167c5303f Merge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rustfmt-subtree 2021-12-02 21:35:30 -06:00
Caleb Cartwright
e305322557 Merge remote-tracking branch 'upstream/master' into subtree-sync-2021-12-02 2021-12-02 21:02:14 -06:00
Yacin Tmimi
ec46ffd981 Determine when new comment lines are needed for itemized blocks
Fixes 5088

Previously, rustfmt would add a new comment line anytime it reformatted
an itemized block within a comment when ``wrap_comments=true``. This
would lead to rustfmt adding empty comments with trailing whitespace.

Now, new comment lines are only added if the original comment spanned
multiple lines, if the comment needs to be wrapped, or if the comment
originally started with an empty comment line.
2021-12-01 18:31:10 -06:00
Yacin Tmimi
1f28683ffa Update nightly only test with #[nightly_only_test] attribute 2021-11-29 14:02:02 -06:00
Caleb Cartwright
0fc846f979 refactor: maintain more AST info when formatting a RHS 2021-11-28 23:25:06 -06:00
Yacin Tmimi
a21f1b6c2a Conditionally compile tests based on CFG_RELEASE_CHANNEL env var
Adds the ``nightly_only_test`` and ``stable_only_test`` attribute macros
that prevent or allow certain tests to compile on nightly and stable
respectively. This is achieved through conditionally outputting the
tests TokenStream.

If CFG_RELEASE_CHANNEL is not set, it's assumed that we're running in a
nightly environment.

To mark a test as nightly only:

    #[nightly_only_test]
    #[test]
    fn only_run_on_nightly() {
        ...
    }

To mark a test a stable only:

    #[stable_only_test]
    #[test]
    fn only_run_on_stable() {
        ...
    }
2021-11-27 17:36:18 -06:00
Esteban Kuber
f99469d7c4 Change how the fn params span is calculated
Use the available Generics span field to avoid issues with `T: Fn()` bounds.

This is necessary to land #85346.
2021-11-24 20:02:16 +00:00
Dom
4389a4ce49 fix: do not wrap reference-style doc links
Prevents wrap_comments from incorrectly wrapping reference-style doc
links.
2021-11-23 16:17:52 -06:00
mujpao
196e676504 Preserve normalized comments after last list item 2021-11-19 19:18:17 -06:00
Caleb Cartwright
2c442ccf25 fix: correct some type alias issues 2021-11-18 13:43:37 -06:00
Caleb Cartwright
eee8f0419d refactor: cleanup duplicative Impl handling code 2021-11-17 13:57:25 -06:00
Caleb Cartwright
f99e3582bd Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync 2021-11-07 20:37:34 -06:00
Caleb Cartwright
4621915d25 Merge remote-tracking branch 'upstream/master' into rustup-2021-11-s1 2021-11-07 14:44:33 -06:00
Caleb Cartwright
e4472d3b07 refactor: dedupe associated item visitation 2021-11-07 08:12:58 -06:00
Vadim Petrochenkov
bf3c52f355 ast: Fix naming conventions in AST structures
TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
2021-11-07 21:38:17 +08:00
Caleb Cartwright
19c5c74951 refactor: dedupe & simplify ty alias formatting 2021-11-06 16:06:21 -05:00
mujpao
4d50e7c760 Put empty trait braces on same line if possible 2021-11-05 20:40:49 -05:00
Caleb Cartwright
a5f85058ac fix: handle external mods imported via external->inline load hierarchy 2021-11-04 18:35:38 -05:00
r00ster
bd86077c58 Remove grave accent that shouldn't be there 2021-11-02 21:28:24 -05:00
Peter Hall
c1eab154c9 Use a custom env var for log settings intead of default RUST_LOG
# Conflicts:
#	src/rustfmt/main.rs
2021-10-31 21:43:29 -05:00
Yacin Tmimi
5ce82e1513 Prevent trailing whitespace in where clause bound predicate
resolves 5012
resolves 4850

This behavior was noticed when using the ``trailing_comma = "Never"``
configuration option (5012).

This behavior was also noticed when using default configurations (4850).

rustfmt would add a trailing space to where clause bounds that had an
empty right hand side.

Now no trailing space is added to the end of these where clause bounds.
2021-10-30 23:07:34 -05:00
Caleb Cartwright
ed5a0250d3 refactor: minor parser cleanup 2021-10-30 11:00:19 -05:00
Yacin Tmimi
bc46af9742 Retain trailing comments in module when using rustfmt::skip attribute
Resolves 5033

Trailing comments at the end of the root Module were removed because the
module span did not extend until the end of the file.

The root Module's span now encompasses the entire file, which ensures
that no comments are lost when using ``#![rustfmt::skip]``
2021-10-28 21:44:39 -05:00
Matthias Krüger
0b8ffac029 fix a bunch of the other clippy warnings that look interesting 2021-10-27 20:41:57 -05:00
Matthias Krüger
c493ee4828 fix clippy::needless_borrow 2021-10-27 20:41:57 -05:00
Caleb Cartwright
757da8c617 Merge remote-tracking branch 'upstream/master' into another-subtree-sync 2021-10-24 13:45:19 -05:00
Martinez
599b2fd9c4
Add One option to group_imports (#4966)
* Add Together option to group_imports

* Rename option to One

* Rename files from Together to One
2021-10-23 11:01:48 -05:00
Caleb Cartwright
051e2b40c9 fix doc issue in rustfmt 2021-10-21 17:22:54 -05:00
Caleb Cartwright
2b41b6d022 Merge commit 'efa8f5521d3813cc897ba29ea0ef98c7aef66bb6' into rustfmt-subtree 2021-10-20 00:11:59 -05:00
Caleb Cartwright
923126348d
Merge branch 'master' into 1.4.38-subtree 2021-10-19 23:01:25 -05:00
Yacin Tmimi
1ae5c35f8d Replace match expression with match! macro
This is a follow up to 5f4811ed7b

The matches! macro expresses the condition more succinctly and avoids
the extra level of indentation introduced with the match arm body.
2021-10-18 21:32:52 -05:00
Yacin Tmimi
5f4811ed7b Handle DefinitiveListTactic::SpecialMacro when writing pre-comments
Resolves 4615

Previously only Vertical and Mixed enum variants of DefinitiveListTactic
were considered when rewriting pre-comments for inner items in
lists::write_list.

Because we failed to considering the SpecialMacro variant we ended up in
a scenario where a ListItem with a pre_comment and a pre_comment_style
of ListItemCommentStyle::DifferentLine was written on the same line as the
list item itself.

Now we apply the same pre-comment formatting to SpecialMacro, Vertical,
and Mixed variants of DefinitiveListTactic.
2021-10-17 16:27:05 -05:00
Caleb Cartwright
c9c1932be3 feat: stabilize disable_all_formatting 2021-10-13 21:58:13 -05:00
Yacin Tmimi
f2fb3c9659 Update connector search in ControlFlow::rewrite_pat_expr for for loops
Resolves 5009

For loops represented by a ControlFlow object use " in" as their connector.
rustfmt searches for the first uncommented occurrence of the word "in" within the
current span and adjusts it's starting point to look for comments right after that.
visually this looks like this:

    rustfmt starts looking for comments here
            |
            V
    for x in /* ... */ 0..1 {}

This works well in most cases, however when the pattern also contains
the word "in", this leads to issues.

    rustfmt starts looking for comments here
          |
          V
    for in_here in /* ... */ 0..1 {}
        -------
        pattern

In order to correctly identify the connector, the new approach first
updates the span to start after the pattern and then searches for the
first uncommented occurrence of "in".
2021-10-13 19:36:37 -05:00
Yacin Tmimi
f7c4a44149 Adjust non-empty tuple struct span to start before fields
Resolves 5011

Tuple structs with visibility modifiers and comments before the first
field were incorrectly formatted. Comments would duplicate part of the
visibility modifier and struct name.

When trying to parse the tuple fields the ``items::Context`` searches
for the opening '(', but because the visibility modifier introduces
another '(' -- for example ``pub(crate)`` -- the parsing gets messed up.

Now the span is adjusted to start after the struct identifier, or after
any generics. Adjusting the span in this way ensures that the
``items::Contex`` will correctly find the tuple fields.
2021-10-12 20:08:07 -05:00
Yacin Tmimi
d41805704d Prevent structs with ".." from being rewritten with alignment
rustfmt should only support rewriting a struct in an expression
 position with alignment (non-default behavior) when there is no rest
 (with or without a base) and all of the fields are non-shorthand.
2021-10-12 19:37:48 -05:00
Emilio Cobos Álvarez
8b58cce673 Stabilize match_block_trailing_comma. (#4145)
Servo has used this since forever, and it'd be useful to be able to use
rustfmt stable there so that we can use the same rustfmt version in
both Firefox and Servo.

Feel free to close this if there's any reason it shouldn't be done.
2021-10-11 17:16:10 -05:00
Yacin Tmimi
40f4993c67 Update derive attibute span to start after opening '('
Fixes 4984

When parsing derive attributes we're only concerned about the traits
and comments listed between the opening and closing parentheses.

Derive attribute spans currently start at the '#'.

    Span starts here
    |
    v
    #[derive(...)]

After this update the derive spans start after the opening '('.

    Span starts here
             |
             V
    #[derive(...)]
2021-10-05 22:29:23 -05:00
Patrick Walton
f0f449d6ed Wrap long array and slice patterns.
Closes #4530.
2021-10-04 20:41:17 -05:00
Yacin Tmimi
a5138b34d5 Prevent removal of qualified path for tuple struct inside macro
fixes 5005

This was very similar to 4964 and the fix was to extract and pass along
the qself of the ``PatKind::TupleStruct``
2021-09-27 17:49:10 -05:00
Caleb Cartwright
4b9d637f58 refactor: simplify local dep lookups 2021-09-23 21:12:57 -05:00
Caleb Cartwright
7f6229b9aa tests: restructure and extend cargo-fmt tests 2021-09-23 21:12:57 -05:00
Ulyssa
dd445aba08 Trailing comma on match block goes missing when guard is on its own line 2021-09-20 20:05:52 -05:00
Caleb Cartwright
7aa69e5bc8 refactor: use iter workaround for contains() gap 2021-09-16 22:01:50 -05:00
Caleb Cartwright
17cb2b147e feat: add --check flag to cargo fmt (#3890) 2021-09-16 22:01:50 -05:00
Manish Goregaokar
52e1a529f2 Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Revert anon union parsing

Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code.

Fix #88583.
2021-09-15 14:56:58 -07:00
Arjen Laarhoven
9d65b7dcd1 feat: upper- or lowercase hexadecimal literals 2021-09-14 21:22:26 -05:00
Seiichi Uchida
d4ffd1efa4 Support @generated marker to skip code formatting
This is a copy of #4296 with these changes:
* file is not reopened again to find if the file is generated
* first five lines are scanned for `@generated` marker instead of one
* no attempt is made to only search for marker in comments

`@generated` marker is used by certain tools to understand that the
file is generated, so it should be treated differently than a file
written by a human:
* linters should not be invoked on these files,
* diffs in these files are less important,
* and these files should not be reformatted.

This PR proposes builtin support for `@generated` marker.

I have not found a standard for a generated file marker, but:
* Facebook [uses `@generated` marker](https://tinyurl.com/fb-generated)
* Phabricator tool which was spawned from Facebook internal tool
  [also understands `@generated` marker](https://git.io/JnVHa)
* Cargo inserts `@generated` marker into [generated Cargo.lock files](https://git.io/JnVHP)

My personal story is that rust-protobuf project which I maintain
was broken twice because of incompatibilities/bugs in rustfmt marker
handling: [one](https://github.com/stepancheg/rust-protobuf/issues/493),
[two](https://github.com/stepancheg/rust-protobuf/issues/551).
(Also, rust-protobuf started generating `@generated` marker
[6 years ago](https://git.io/JnV5h)).

While rustfmt AST markers are useful to apply to a certain AST
elements, disable whole-file-at-once all-tools-at-once text level
marker might be easier to use and more reliable for generated code.
2021-09-14 21:22:26 -05:00
Laurențiu Nicola
67a59f6ee3 opts: rephrase wording for --all and -p 2021-09-13 18:57:31 -05:00
bors
8743472386 Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
Encode spans relative to the enclosing item

The aim of this PR is to avoid recomputing queries when code is moved without modification.

MCP at https://github.com/rust-lang/compiler-team/issues/443

This is achieved by :
1. storing the HIR owner LocalDefId information inside the span;
2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache;
3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation.

Since all client code uses `Span`, step 3 ensures that all manipulations
of span byte positions actually create the dependency edge between
the caller and the `source_span(LocalDefId)`.
This query return the actual absolute span of the parent item.
As a consequence, any source code motion that changes the absolute byte position of a node will either:
- modify the distance to the parent's beginning, so change the relative span's hash;
- dirty `source_span`, and trigger the incremental recomputation of all code that
  depends on the span's absolute byte position.

With this scheme, I believe the dependency tracking to be accurate.

For the moment, the spans are marked during lowering.
I'd rather do this during def-collection,
but the AST MutVisitor is not practical enough just yet.
The only difference is that we attach macro-expanded spans
to their expansion point instead of the macro itself.
2021-09-11 23:35:28 +00:00
Camille GILLOT
127ec9a8c9 Keep a parent LocalDefId in SpanData. 2021-09-10 20:17:33 +02:00
Fabian Wolff
e014277b07 Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
Felix S. Klock II
d647ebfb4a Revert "Allow formatting Anonymous{Struct, Union} declarations"
This reverts commit 64acb7d921.
2021-09-09 09:14:16 -04:00
Nipunn Koorapati
b10ab51fed rustfmt doc code blocks with multiple comma-separated attributes
Added test covering this. Chose to treat the code block
as rust if and only if all of the comma-separated attributes
are rust-valid. Chose to allow/preserve whitespace around commas

Fixes #3158
2021-09-08 23:27:51 -05:00
Caleb Cartwright
a80688329c fix: handle param doc comments for macro scenarios 2021-09-08 19:27:31 -05:00
Caleb Cartwright
57548aa096 fix: resolve idempotency issue in extern body elements 2021-09-07 20:22:09 -05:00
Stéphane Campinas
c2f0e99d85 try to write the parameter on a new line in case the attribute/parameter together are over max_width 2021-09-06 18:14:13 -05:00
Caleb Cartwright
a59cac29f4 fix: use correct spans for params with attrs 2021-09-06 18:14:13 -05:00
Caleb Cartwright
59063e8b40 fix: newline width calc in combine w/ comments (#4123) 2021-09-06 17:02:20 -05:00
bors
6271dedd8d Auto merge of #88493 - chenyukang:fix-duplicated-diagnostic, r=estebank
Fix #88256 remove duplicated diagnostics

Fix #88256
2021-09-06 00:14:41 +00:00
yukang
1674eea8ad Fix #88256, remove duplicated diagnostic 2021-09-04 19:26:25 +08:00
Esteban Kuber
48b8e4577a Detect bare blocks with type ascription that were meant to be a struct literal
Address part of #34255.

Potential improvement: silence the other knock down errors in
`issue-34255-1.rs`.
2021-09-03 14:43:04 +00:00
Yusuke Tanaka
ca9b050bbf Implement One option for imports_granularity (#4669)
This option merges all imports into a single `use` statement as long as
they have the same visibility.
2021-08-31 18:33:06 -05:00
Cameron Steffen
a603756cc5 Temporary fix rustfmt for let-else 2021-08-30 20:18:41 -05:00
Deadbeef
076916fe94 Introduce ~const
- [x] Removed `?const` and change uses of `?const`
 - [x] Added `~const` to the AST. It is gated behind const_trait_impl.
 - [x] Validate `~const` in ast_validation.
 - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
 `ConstIfConst` allowing future extensions)
 - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
 - [ ] Optional steps (*for this PR, obviously*)
      - [ ] Fix #88155
      - [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
Ashvin Arsakularatne
e81c393663 fix: remove wrong reformatting of qualified paths in struct patterns 2021-08-25 21:18:41 -05:00
David Tolnay
fd6b025e8a Preserve visibility on trait items inside trait and impl 2021-08-22 12:06:18 -05:00
Frank Steffahn
9bc0dbeb64 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Frank Steffahn
25ebc35f97 Fix more “a”/“an” typos 2021-08-22 16:35:29 +02:00
bors
e1dac88cfe Auto merge of #87119 - jyn514:rustfmt-doc-private, r=Mark-Simulacrum
Document private items for rustfmt

This is possible now that https://github.com/rust-lang/rust/pull/73936 has been merged.
2021-08-17 04:18:55 +00:00
Joshua Nelson
7769ed0484 Document private items for rustfmt
This is possible now that rustdoc allows passing
`--document-private-items` more than once.
2021-08-16 01:46:56 +00:00
Caio
64bf8dfa33 Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Caleb Cartwright
5d8eb8d79c fix: don't drop drop generic args on assoc ty constraints 2021-08-08 13:58:10 -05:00
Caleb Cartwright
fefb5427a2 fix: handle GAT types in impls with self bounds 2021-08-06 22:03:40 -05:00
klensy
8c52aae10a Bump deps
* dirs-sys v0.3.4 -> v0.3.6 to drop a lot of deps
regex v1.3.1 -> v1.4.3 drops thread_local 0.3.6
bytecount v0.6.0 -> v0.6.2 replaces packed_simd with packed_simd_2
ignore v0.4.11 -> v0.4.17 drop crossbeam-channel v0.4.0

* itertools 8.0 -> 9.0
bump `ignore` version in Cargo.toml

* cargo_metadata 0.8 -> 0.12

* env_logger 0.6 -> 0.8
2021-07-27 19:50:11 -05:00
Ellen
0b21ea2161 Unyeet const param defaults 2021-07-27 19:50:11 -05:00
Outvi V
e7fa07036f fix: make --edition 2021 visible in --help 2021-07-27 19:50:11 -05:00
Caleb Cartwright
e4b8714c09 Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-rustfmt 2021-07-25 22:57:19 -05:00
Caleb Cartwright
d42be80bf7 chore: disable clippy::matches_like_macro lint 2021-07-25 22:53:32 -05:00
Matthias Krüger
4c2959fb12 fix a bunch of clippy warnings
clippy::bind_instead_of_map
clippy::branches_sharing_code
clippy::collapsible_match
clippy::inconsistent_struct_constructor
clippy::int_plus_one
clippy::iter_count
clippy::iter_nth_zero
clippy::manual_range_contains
clippy::match_like_matches_macro
clippy::needless::collect
clippy::needless_question_mark
clippy::needless_return
clippy::op_ref
clippy::option_as_ref_deref
clippy::ptr_arg
clippy::redundant_clone
clippy::redundant_closure
clippy::redundant_static_lifetimes
clippy::search_is_some
clippy::#single_char_add_str
clippy::single_char_pattern
clippy::single_component_path_imports
clippy::single_match
clippy::skip_while_next
clippy::unnecessary_lazy_evaluations
clippy::unnecessary_unwrap
clippy::useless_conversion
clippy::useless_format
2021-07-25 22:53:32 -05:00
Caleb Cartwright
b305d62e5b fix: correct arm leading pipe check (#4880)
In the event a pattern starts with a leading pipe
the pattern span will contain, and begin with, the pipe.

This updates the process to see if a match arm contains
a leading pipe by leveraging this recent(ish) change to
the patterns in the AST, and avoids an indexing bug that
occurs when a pattern starts with a non-ascii char in the
old implementation.
2021-07-25 22:53:32 -05:00
Michael Murphy
486e774fbf Adjusting help message (#4865)
On stable, running with `--help|-h` shows information about `file-lines`
which is a nightly-only option. This commit removes all mention of
`file-lines` from the help message on stable.

There is room for improvement here; perhaps a new struct called, e.g.,
`StableOptions` could be added to complement the existing
`GetOptsOptions` struct. `StableOptions` could have a field for each
field in `GetOptsOptions`, with each field's value being a `bool` that
specifies whether or not the option exists on stable. Or is this adding
too much complexity?
2021-07-25 22:53:32 -05:00
Casey Rodarmor
1ca3798d2c Improve pasta copyability of merge_imports deprecation message
Add double quotes around `Crate` so that it can be copied directly into a `Cargo.toml` file
2021-07-25 22:53:32 -05:00
Ruby Lazuli
75765f656e Allow --edition 2021 to be passed to rustfmt
This was added to Configurations.md in #4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
2021-07-25 22:53:32 -05:00
Camille GILLOT
277feac1f9 Use LocalExpnId where possible. 2021-07-17 19:41:02 +02:00
Guillaume Gomez
abf449ffa6 Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
Joshua Nelson
33acc960f7 Document rustfmt on nightly-rustc
The recursion_limit attribute avoids the following error:

```
error[E0275]: overflow evaluating the requirement `std::ptr::Unique<rustc_ast::Pat>: std::marker::Send`
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`rustfmt_nightly`)
```
2021-07-01 19:39:47 -04:00
Yuki Okushi
0b8a26f507 Rollup merge of #86424 - calebcartwright:rustfmt-mod-resolution, r=Mark-Simulacrum
rustfmt: load nested out-of-line mods correctly

This should address https://github.com/rust-lang/rustfmt/issues/4874

r? `@Mark-Simulacrum`

Decided to make the change directly in tree here for expediency/to minimize any potential backporting issues, and because there's some subtree sync items I need to get resolved before pulling from r-l/rustfmt
2021-06-22 00:00:41 +09:00
Caleb Cartwright
2608f2c63b fix(rustfmt): load nested out-of-line mods correctly 2021-06-17 22:35:19 -05:00
Yuki Okushi
1e2258ffa9 Use AttrVec for Arm, FieldDef, and Variant 2021-06-17 08:04:54 +09:00
Ryan Levick
58c63cf8de Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
jedel1043
e243be6ada Allow formatting Anonymous{Struct, Union} declarations 2021-05-16 22:13:38 -05:00
Andy Wang
ef31361766 Rename RealFileName::Named to LocalPath 2021-05-12 22:12:43 -05:00
Andy Wang
e4b5621b0e Only deal with LocalPath in conversion 2021-05-12 22:12:43 -05:00
Andy Wang
8526acee21 Rename span_to_string to span_to_diagnostic_string 2021-05-12 22:12:43 -05:00
Caleb Cartwright
f87414729f fix: backport changes for latest rustc api comaptibility 2021-05-02 10:37:43 -05:00
Yuki Okushi
ddb224a173
Upgrade annotate-snippets to 0.8 (#4762) 2021-04-22 08:33:36 -05:00
ChinYing-Li
dac2423f3f Recognize when a block comment has been ended inside a string literal (#4312) 2021-04-21 21:30:42 -05:00
Caleb Cartwright
78b0728887 refactor: remove panics on misconfigured widths 2021-04-21 21:27:50 -05:00
Caleb Cartwright
a168d92f9a tests: augment heuristics tests 2021-04-21 21:27:50 -05:00
Caleb Cartwright
1bcc1f8df5 refactor: apply heuristic config changes in lib 2021-04-21 21:27:50 -05:00
Caleb Cartwright
ea1611c06e feat(config): expose all width heurstic options 2021-04-21 21:27:50 -05:00
Joshua Nelson
943b97c3ae Fix errors when parallel_compiler is enabled 2021-04-21 21:17:36 -05:00
Joshua Nelson
61ee1089f0 Use rustc_private instead of crates.io dependencies
- Update rust-toolchain to also install `rustc-dev` component
2021-04-21 21:17:36 -05:00
Caleb Cartwright
c32f2ec015 chore: fmt and cleanup 2021-04-02 23:21:06 -05:00
Caleb Cartwright
4948911608 deps: apply rustc-ap-* v712 changes 2021-04-02 23:21:06 -05:00
Caleb Cartwright
4c617e8fb3 deps: apply rustc module loading changes 2021-04-02 23:21:06 -05:00
Caleb Cartwright
a1dc57ace1 chore: apply AST HasAttrs->AstLike changes 2021-04-02 23:21:06 -05:00
Caleb Cartwright
612e8d5b9b refactor: apply rustc mod parsing changes 2021-04-02 23:21:06 -05:00
Caleb Cartwright
2c6339571b chore: apply pattern parsing changes 2021-04-02 23:21:06 -05:00
Caleb Cartwright
cbd83b8083 chore: add span creation util function 2021-04-02 23:21:06 -05:00
Yuki Okushi
ca4e9f47b9 Fix a legacy_derive_helpers warning 2021-03-18 23:34:32 -05:00
Joshua Nelson
c3a5111106 Fix some clippy warnings
This commit can be replicated with
`cargo clippy --fix -Z unstable-options && cargo +nightly-2021-02-10 fmt`.
2021-02-18 20:20:29 -06:00
David Bar-On
432e09e89f Add the use of rewrite_assign_rhs_with_comments to 1.x 2021-02-17 20:47:20 -06:00
David Bar-On
4b0ed96f2e Fix for issue 4603 about extra macro body indentation (third version) 2021-02-17 20:19:27 -06:00
Joshua Nelson
6170948820 Fix warnings
- Fix nightly warning about `format!`
- Remove unused functions and fields
2021-02-17 20:14:46 -06:00
Caleb Cartwright
9ed75111e2 deps: apply rustc-ap v705 changes to itemkind variants 2021-02-07 12:46:43 -06:00
Caleb Cartwright
58ac85b58e deps: bump rustc-ap crates to v701.0.0 2021-02-03 21:05:15 -06:00
Caleb Cartwright
b8f318c303 fix: don't insert trailing comma on struct lit rest in mac def 2021-01-28 22:01:50 -06:00
Caleb Cartwright
c13d2452c0 chore: backport some empty block check fixes 2021-01-27 20:58:42 -06:00
Caleb Cartwright
bd4dc36c4e refactor: cleanup block check for statements 2021-01-27 20:58:42 -06:00
vallentin
3e61326716 Fixed semicolon getting moved into comment (fixes #4646) 2021-01-27 20:58:42 -06:00
Michael Morgan
384ba68d64 Add imports_granularity="Item".
This option splits all imports into their own `use` statement.
2021-01-27 20:58:42 -06:00
Sean Klein
5e14f760c5 fix: Avoid incorrect global 'cfg_if' Symbol interning
Fixes #4656
2021-01-27 19:26:58 -06:00
Ayaz Hafiz
f8deed3a3a Include const generic type bounds in their spans
Closes #4310
2021-01-27 18:50:03 -06:00
Seiichi Uchida
c0fede355c Use the span after generics and where clause (#4208) 2021-01-27 18:50:03 -06:00
hafiz
269584634a Include constness in impl blocks (#4215)
Closes #4084
2021-01-27 18:50:03 -06:00
Geoffry Song
0d60a616ab Disable deprecated_option_merge_imports tests on non-nightly 2021-01-17 11:48:47 -06:00
Geoffry Song
71863753bd Rename merge_imports to imports_granularity and add a Module option.
This renames the existing `true`/`false` options to `Crate`/`Never`, then adds a
new `Module` option which causes imports to be grouped together by their
originating module.
2021-01-17 11:48:47 -06:00
Caleb Cartwright
c4d551cdf5 refactor: remove unneeded clone 2021-01-16 11:17:23 -06:00
Caleb Cartwright
b30cb24286 fix: indentation issue on generic bounds 2021-01-16 11:17:23 -06:00
Caleb Cartwright
3571c5d6f7 fix: maintain redundant semis on items in statement pos 2021-01-09 12:11:52 -06:00
Mara Bos
5bb17a0d36 Account for new ast::GenericParamKind::Const::default in rust_ast. 2021-01-09 12:11:52 -06:00
Mara Bos
4644418556 Fixes for new rustc changes. 2021-01-09 12:11:52 -06:00
Mara Bos
398d2f96c3 Add support for edition 2021. 2021-01-09 12:11:52 -06:00
Seiichi Uchida
0d022d08d8 Format error and typeof types (#4416)
* Add a test for #4357

* Format error and typeof types
2020-12-20 12:05:05 -06:00
Stéphane Campinas
c536d80dc1 Fix rewrite of closures with a return type
If the closure's body fits in a line, the block is removed but it is
necessary if the closure has a return type.
2020-12-20 12:05:05 -06:00
Caleb Cartwright
4cfb9ef8f4 fix: don't strip nonexistent comma in derive 2020-12-20 12:05:05 -06:00
David Tolnay
96ee060529 Preserve polarity on negative non-trait impl 2020-11-30 23:24:36 -06:00
WhizSid
7d9ee7558e Comment between typebounds (#4474)
* Test cases and get spans

* Fixed type bounds

* Fixed issue of test cases

* Fixed first test case issue

* Removed unwanted whitespaces

* Removed tmp files
2020-11-29 13:26:58 -06:00
Caleb Cartwright
823c4f820a fix: backport some imports for cherry-picked commit 2020-11-29 13:26:58 -06:00
WhizSid
b7c38c9d50 Fixed comment dropped between & and type issue (#4482)
* Fixed comment dropped between & and type issue

* Reduced nesting levels and avoided duplications

* Removed extra allocations
2020-11-29 13:26:58 -06:00
WhizSid
6455e9de0e Fixed 'Comment removed between type name and =' issue (#4448)
* Fixed Comment removed between type name and = issue

* Fixed where clause issue and pass the full span

* has_where condition inline

* Fixed indentation error on where clause

* Removed tmp file
2020-11-29 13:26:58 -06:00
Caleb Cartwright
ea712f1a2c fix: apply rustc-ap updates to backported commit 2020-11-29 13:26:58 -06:00
hafiz
5e7fb45533 Pick up comments between visibility modifier and item name (#4239)
* Pick up comments between visibility modifier and item name

I don't think this hurts to fix. #2781, which surfaced this issue, has
a number of comments relating to similar but slightly different issues
(i.e. dropped comments in other places). I can mark #2781 as closed and
then will open new issues for the comments that are not already resolved
or tracked.

Closes #2781

* fixup! Pick up comments between visibility modifier and item name

* fixup! Pick up comments between visibility modifier and item name
2020-11-29 13:26:58 -06:00
Caleb Cartwright
fb7e604538 tests: backport an additional test case 2020-11-29 13:26:58 -06:00
Adam H. Leventhal
3df383aa3c fixes #4115, #4029, #3898 2020-11-29 13:26:58 -06:00
hafiz
c77c6a405d Compare code block line indentation with config whitespace (#4166)
Previously the indetation of a line was compared with the configured
number of spaces per tab, which could cause lines that were formatted
with hard tabs not to be recognized as indented ("\t".len() < "    ".len()).

Closes #4152
2020-11-29 13:26:58 -06:00
Ayaz Hafiz
3bf67c175d Don't drop blocks on foreign functions
A code like

```rust
extern "C" {
    fn f() {
        fn g() {}
    }
}
```

is incorrect and does not compile. Today rustfmt formats this in a way
that is correct:

```rust
extern "C" {
    fn f();
}
```

But this loses information, and doesn't have to be done because we know
the content of the block if it is present. During development I don't
think rustfmt should drop the block in this context.

Closes #4313
2020-11-28 21:59:30 -06:00
Ayaz Hafiz
5ffccbb627 Properly format function signature in extern blocks
Closes #4288

And we get to drop a method, which I think is a win :)
2020-11-28 21:59:30 -06:00
Caleb Cartwright
48d30a4f71 chore: run rustfmt against source 2020-11-28 17:41:21 -06:00
Caleb Cartwright
4d9fa00fd5 feat: support underscore expressions 2020-11-28 17:41:21 -06:00
Caleb Cartwright
5c0673c371 refactor: update cfg_if attr parsing 2020-11-28 17:41:21 -06:00
Caleb Cartwright
4f32ce8434 feat: support struct/slice destructuring 2020-11-28 17:41:21 -06:00
Caleb Cartwright
5b216029b5 deps: minor rustc_ast changes for v691 2020-11-28 17:41:21 -06:00
Caleb Cartwright
581da523db deps: bump rustc-ap to v687 2020-11-28 17:41:21 -06:00
meiomorphism
003786228d fix: don't force a newline after an empty where clause
Fixes #4547.
2020-11-25 21:32:46 -06:00
Matt
073cc3891f Option to create groups for std, external crates, and other imports
Backport of 17d90ca.
2020-11-18 21:37:42 -06:00
Caleb Cartwright
89f38304a7 fix: don't drop leading comments in extern 2020-11-16 15:48:20 -06:00
WhizSid
faf97a67d6 Fixed 'Incorrect comment indent inside if/else' issue. (#4459)
* Added test cases

* Fixed if condition comment issue

* Fixed extern C issue

* Removed previous test case

* Removed tmp file

* honor the authors intent

* Changed the file name to its original name

* Removed extra whitespace
2020-11-14 11:50:28 -06:00
Ayaz Hafiz
ce13ff15c3 Correctly create artificial span for formatting closure body
This commit partially reverts #3934, opting to create a span that covers
the entire body of a closure when formatting a closure body with a
block-formatting strategy, rather than having the block-formatting code
determine if the visitor pointer should be rewound. The problem with
rewinding the visitor pointer is it may be incorrect for other (i.e.
non-artificial) AST nodes, as in the case of #4382.

Closes #4382
2020-11-14 11:50:28 -06:00
Caleb Cartwright
a613c57521 feat: don't insert semi in macro_rules arm body 2020-11-11 18:26:13 -06:00
Caleb Cartwright
ae6b40e2f9 fix: remove ignored depr attribute which now errors 2020-11-05 20:45:11 -06:00
Caleb Cartwright
1139e6e5cc fix: remove comment from cherry-pick that v1.x doesn't handle 2020-11-05 20:45:11 -06:00
Aaron Hill
46ab14437e Don't flatten a block containing a single macro call
We no longer flatten a block that looks like this:

```rust
match val {
    pat => { macro_call!() }
}
```

Currently, rust ignores trailing semicolons in macro expansion in
expression position (see https://github.com/rust-lang/rust/issues/33953)

If this is changed, flattening a block with a macro call may break the
user's code - the trailing semicolon will no longer parse if the macro
call occurs immediately on the right-hand side of the match arm
(e.g. `pat => macro_call!()`)
2020-11-05 20:45:11 -06:00
Caleb Cartwright
15854e5fd3 feat: v2 support for nested tuples w/o spaces 2020-11-02 18:31:51 -06:00
Caleb Cartwright
98975e1a64 tests: adjust some cherry-picekd tests 2020-11-02 18:31:51 -06:00
Caleb Cartwright
2b6226ce49 fix: resolve some parser related bugs 2020-11-02 18:31:51 -06:00
Caleb Cartwright
86a41bc80b tests: add test for panic on new_parser_from_file 2020-11-02 18:31:51 -06:00
Caleb Cartwright
9faba4539b fix(parser): better unclosed delims handling 2020-11-02 18:31:51 -06:00
Caleb Cartwright
e131797b62 deps: bump rustc-ap to v686 2020-11-02 18:31:51 -06:00
Michael Müller
fa9d97499e
Fix overriding license header bug (#4488)
* Override header to None when path len = 0

* Add regression test

* Ensure nightly
2020-10-24 11:14:52 -05:00
hafiz
6a7824787e Preserve comments in empty statements (#4180)
* Preserve comments in empty statements

Closes #4018

* fixup! Preserve comments in empty statements
2020-10-24 11:13:00 -05:00
Ayaz Hafiz
e70343a5f5 Correctly indent skipped-over code
Closes #4398
2020-10-24 11:13:00 -05:00
Caleb Cartwright
31cef56779 feat: add initial support for ConstBlock expressions 2020-10-24 11:13:00 -05:00
Caleb Cartwright
c89638ae55 deps: update macro parsing 2020-10-24 11:13:00 -05:00
David Tolnay
14d53f75c9 Use rustfmt given by RUSTFMT env var (#4419) 2020-10-04 16:58:34 -05:00
Ayaz Hafiz
2a8ff209f6 fixup! Preserve and format type aliases in extern blocks 2020-10-01 19:12:22 -05:00
Ayaz Hafiz
92ab76cfa7 fixup! Preserve and format type aliases in extern blocks 2020-10-01 19:12:22 -05:00
Ayaz Hafiz
a9b0b057eb fixup! Preserve and format type aliases in extern blocks 2020-10-01 19:12:22 -05:00
Ayaz Hafiz
a15800a327 Preserve and format type aliases in extern blocks
Previously, non-trivial type aliases in extern blocks were dropped by
rustfmt because only the type alias name would be passed to a rewritter.
This commit fixes that by passing all type information (generics,
bounds, and assignments) to a type alias rewritter, and consolidates
`rewrite_type_alias` and `rewrite_associated_type` as one function.
2020-10-01 19:12:22 -05:00
Caleb Cartwright
d6a220b70a feat: support config. of leading match arm pipe 2020-09-24 09:43:31 -05:00
David Tolnay
8635a5ca44 deps: bump rustc-ap to v679 2020-09-23 00:45:18 -05:00
Caleb Cartwright
9ba373f822 deps: bump rustc-ap to v678 2020-09-23 00:45:18 -05:00
Caleb Cartwright
62dc7c5c6b fix: inner attribute formatting 2020-09-04 19:01:18 -05:00
mahkoh
89b7f5f382 Fix module resolution in inner modules with paths (#4194) 2020-09-04 19:01:18 -05:00
Caleb Cartwright
aa11c27490 chore: run rustfmt 2020-09-04 19:01:18 -05:00
Caleb Cartwright
637ddfb6da deps: bump rustc-ap to v673 2020-09-04 19:01:18 -05:00
Caleb Cartwright
e4617e0e61 deps: bump rustc-ap to v672 2020-09-04 19:01:18 -05:00
Caleb Cartwright
a17803127f fix: inverted span on attrs within closure 2020-08-09 14:32:34 -05:00
Caleb Cartwright
bf359c6ebc chore: backport 8157a3f0afe978d3e953420577f8344db7e905bf 2020-07-15 09:19:21 -05:00
Caleb Cartwright
391cd3e324 deps: bump rustc-ap to v669 2020-07-14 21:36:24 -05:00
Caleb Cartwright
b243075d75 deps: bump rustc-ap-* to v668 2020-07-09 23:15:08 -05:00
Caleb Cartwright
da18032ba4 deps: bump rustc-ap* to v666 2020-06-27 13:15:54 -05:00
Seiichi Uchida
a36e7c7981 Use correct span for match arms with the leading pipe and attributes (#3975) 2020-06-27 12:55:15 -05:00
Caleb Cartwright
796d6eafa4 fix: backport fix for #4079 2020-06-11 23:29:51 -05:00
Caleb Cartwright
5db7152962 fix: backport fix for #4020 2020-06-11 23:17:38 -05:00
Caleb Cartwright
ce1a3efff0 fix: backport fix for submod parser errors 2020-06-11 21:49:40 -05:00
Caleb Cartwright
dead3a807d fix: backport mod resolution error handling 2020-06-11 21:11:18 -05:00
David Tolnay
bc9a0b2974 Switch to std::error::Error for errors (#3948) 2020-06-11 20:23:24 -05:00
Caleb Cartwright
b28fd5f91c deps: apply upstream rustc-* changes 2020-06-11 13:22:37 -05:00
topecongiro
08776ef3b4
Support module-level rustfmt::skip in sub-modules 2020-06-08 10:42:43 +09:00
Seiichi Uchida
577ef8136f
Update rustc-ap-* crates to 659.0.0 for rustfmt-1.4.15 (#4184) 2020-05-19 17:31:28 +09:00
Caleb Cartwright
c1267303bc
fix: formatting arbitrary extern abi (#4089) 2020-03-31 15:30:26 +09:00
Caleb Cartwright
00e199c974
backport new syntax to rustfmt 1.x (#4105)
* feat: support raw reference operator

* feat: support const opt-out syntax

* feat: support half open range syntax
2020-03-31 15:28:01 +09:00
Caleb Cartwright
9714a140c9 refactor: use ast::attr:HasAttrs 2020-03-30 13:11:00 -05:00
Caleb Cartwright
ac2d5b85a5 deps: bump rustc-ap* to v651 2020-03-30 12:02:39 -05:00
Caleb Cartwright
b173b42354 refactor: rename libsyntax --> rustc_ast 2020-03-27 22:29:12 -05:00
Caleb Cartwright
c1a66e1e22 fix: unreachable err on Fn with None block 2020-03-27 22:13:46 -05:00
Caleb Cartwright
537d746e08 fix: use correct ForeignItem span 2020-03-27 22:00:00 -05:00
Caleb Cartwright
bea7209d0a chore: fix src formatting 2020-03-27 21:53:40 -05:00
Caleb Cartwright
9b0ed57af6 refactor: parse & mod resolver for rustc-ap v650 2020-03-27 21:33:34 -05:00
Caleb Cartwright
bd5dff4012 refactor: backport syntux mod 2020-03-26 21:25:34 -05:00
Caleb Cartwright
9699c96cf1 deps: bump to rustc v647 2020-03-26 17:20:24 -05:00
Caleb Cartwright
7a76ec062d deps: bump to rustc v644 2020-03-26 15:26:58 -05:00
Caleb Cartwright
760bb29feb chore: fix compile warnings 2020-02-08 22:54:37 -06:00
Caleb Cartwright
e72f307f15 fix: backport parse bug fix
Backport the fix for the parser bug where the messages from
fatal/non-recoverable parser errors were being silently eaten by
rustfmt.
2020-02-08 22:47:48 -06:00
Caleb Cartwright
c60416ed21 deps: update rustc-ap to v642.0.0 2020-02-08 22:21:37 -06:00
Seiichi Uchida
731f15551b
Do not add block around async closure (#3946) 2019-12-03 08:47:25 +09:00
Chris Emerson
99f9f576d4 Return an error if --check or --emit json are used with stdin. (#3875) 2019-10-25 15:05:24 +09:00
Seiichi Uchida
69cf48344b
fix handling of nested comments in patterns and ControlFlows (#3869) 2019-10-25 15:04:33 +09:00
rChaser53
233497aceb fix Unparsable code when formmating (#3883) 2019-10-24 22:16:56 +09:00
Rui
69c7dbcd50 Try to solve issue3456. (#3556) 2019-10-19 18:19:47 +09:00
Caleb Cartwright
3a073f177c fix: handling of newline_style conflicts (#3850) 2019-10-19 17:15:13 +09:00
Stéphane Campinas
5327c3633f handle field attributes when aligning a struct's fields (#3513) 2019-10-19 16:56:32 +09:00
Caleb Cartwright
a5d16df9a4 feat: use offline by default with cargo fmt (#3830) 2019-10-19 16:35:33 +09:00
Caleb Cartwright
fd6e960648 fix: comments between lhs and rhs 2019-10-17 20:13:11 -05:00
Caleb Cartwright
28be77915f fix: nested comments in control flow condition pat 2019-10-17 19:58:08 -05:00
Stéphane Campinas
a15e97f1e9 do not indent impl generics (#3856) 2019-10-11 18:19:44 +09:00
Caleb Cartwright
8210cc1c13 fix: handle lhs unary in range expression (#3855) 2019-10-11 18:15:04 +09:00
rChaser53
396a2af181 fix to swallow attribute on brace expression (#3848) 2019-10-10 10:35:34 +09:00
Caleb Cartwright
207a58f365 fix panic on closure with empty block expr (#3846) 2019-10-08 11:00:31 +09:00
Caleb Cartwright
6dcbc5d78e fix: handle block comments with trailing line comments (#3842) 2019-10-08 10:12:21 +09:00
Stéphane Campinas
8073244420 improve detection of URL inside a string that is being rewritten. (#3809) 2019-10-07 16:43:50 +09:00
Stéphane Campinas
160c3aafc5 handle hard tabs when formatting trailing comments (#3836) 2019-10-07 16:40:27 +09:00
Caleb Cartwright
ba4bf03d84 don't fail on recoverable parser errors in ignored files (#3782) 2019-10-07 10:24:08 +09:00
Caleb Cartwright
ed697c9347 fix: support raw prefix identifiers in statics 2019-10-05 12:34:48 -05:00
Seiichi Uchida
383306e5fe
Update rustc-ap-* crates to 606.0.0 (#3835) 2019-10-05 23:40:24 +09:00
Stéphane Campinas
fb01dc857c do not force comments to be indented with a comment trailing a line of code (#3833) 2019-10-05 00:22:01 +09:00
rChaser53
7926851bb0 stop to strip 'impl' from impl trait type alias (#3816) 2019-10-04 11:25:16 +09:00
Matthew Pomes
e28ae8b4a3 Init Logger for unit tests (#3829)
Add `init_log()` function which attempts to init logger, and
ignores failure. The function is called at the beginning of
every test, and will fail if the logger is already initialized.
The logger must be initialized in every test, becuase cargo runs
the tests in parallel, with no garentees about the order and time
each starts.
2019-10-04 11:24:33 +09:00
Stéphane Campinas
dbd8936391 fix rust code in comment with a line containing only a hash sign (#3818) 2019-10-02 23:58:25 +09:00
Caleb Cartwright
f4bc494153 add --offline mode fallback to cargo fmt (#3813) 2019-10-02 23:56:20 +09:00
Caleb Cartwright
7c9c0d1a39 fix: merge_imports handling of ::{self} 2019-09-26 20:02:41 -05:00
Caleb Cartwright
9c2b375ba9 refactor to use param naming where appropriate (#3803) 2019-09-24 09:25:19 +09:00
Caleb Cartwright
3bb266180e fix: handling of empty str for license template path (#3804) 2019-09-24 09:24:05 +09:00
Caleb Cartwright
6b0a447150 feat: support parameter attributes (#3793) 2019-09-20 16:11:52 +09:00
rChaser53
4449250539 fix the error with long string in raw string (#3800) 2019-09-18 22:39:27 +09:00
Shotaro Yamada
ca78653d61 Use Cell instead of RefCell (#3798) 2019-09-18 22:37:08 +09:00
rChaser53
789a097a71 fix internal error when using rustfmt::skip with newline on stmt (#3785) 2019-09-15 23:45:46 +09:00
Caleb Cartwright
dfe87fe946 fix: async expression indentation (#3789) 2019-09-11 09:55:18 +09:00
Seiichi Uchida
ceca01465a
Update deps (#3788) 2019-09-08 23:33:21 +09:00
Seiichi Uchida
5baba86fe5
Update rustc-ap-* crates to 581.0.0 (#3783) 2019-09-06 22:41:03 +09:00
rChaser53
1ded995ee7 fix 'left behind trailing whitespace' (#3761) 2019-09-05 19:38:00 +09:00
Seiichi Uchida
783948fcbb
Fix handling of match arm's rewrite (#3775) 2019-09-05 11:15:46 +09:00
CreepySkeleton
e81ec20af0 Add --config command line option (#3767) 2019-09-05 11:15:19 +09:00
Valentine Valyaeff
15a28f79b8 Another fix for merge_imports (#3769) 2019-09-04 23:02:10 +09:00
Andrey
950b288d6f do not remove discriminant value if exists (#3771) (#3772) 2019-09-04 23:01:04 +09:00
rChaser53
2bf67b6e5c fix TrailingWhitespace when using line breaks in macros arguments (#3768) 2019-09-04 23:00:26 +09:00
Caleb Cartwright
ad5d9fba9b fix formatting mods inside cfg_if macro (#3763) 2019-09-02 18:36:51 +09:00
Seiichi Uchida
deb329a6bb
Forbid adding or removing a block from match arms inside macro calls (#3756) 2019-08-28 20:50:41 +09:00
rChaser53
a09ca681de fix the bug removing attrs (#3760) 2019-08-28 20:50:02 +09:00
Valentine Valyaeff
ef00f74ce3 Merge imports fix (#3753) 2019-08-27 11:23:55 +09:00
Caleb Cartwright
c26c0e5abf feat: add support for --message-format option (#3752) 2019-08-27 09:27:32 +09:00
Caleb Cartwright
9792ff0529 Fix line numbers in checkstyle output (#3694) 2019-08-19 11:11:35 +09:00
Caleb Cartwright
62432fe31b add new flag to list names of misformatted files (#3747) 2019-08-19 11:04:40 +09:00
Seiichi Uchida
73847d3986
Take the inner macro_use attr into acocunt while reordering (#3749) 2019-08-19 10:56:32 +09:00
Seiichi Uchida
1643d726ef
Use correct indent when formatting complex fn type (#3731) 2019-08-16 11:15:28 +09:00
Caleb Cartwright
dfd27663dc add json emit mode (#3735) 2019-08-16 11:14:53 +09:00
Caleb Cartwright
541d9a8659 tests: fix failing default config unit test (#3743) 2019-08-14 08:02:30 +09:00
Seiichi Uchida
4871d6467a
Use the correct BytePos for the opening brace position (#3742) 2019-08-13 23:21:55 +09:00
Caleb Cartwright
ac150d016b fix: remove trailing space with empty dyn macro arg (#3737) 2019-08-11 12:49:14 +09:00
topecongiro
0462008de8
Release 1.4.4 2019-08-06 11:14:12 +09:00
Seiichi Uchida
c0cb5eb535
Fix broken tuple pattern (#3729) 2019-08-06 11:09:45 +09:00
Caleb Cartwright
afc8fbd701 fix: issue with --all when workspace member also exists in dep tree (#3726) 2019-08-06 00:33:59 +09:00
topecongiro
3adfb08afe
Release 1.4.3 2019-08-03 00:01:59 +09:00
Igor Matuszewski
62a32e7b83 Fix most recenty nightly breakage due to removed await! support (#3722) 2019-08-02 23:54:39 +09:00
rChaser53
3b7a518144 fix underscore in slice patterns are removed (#3719) 2019-07-31 23:55:58 +09:00
topecongiro
aeb3496f31
Release v1.4.2 2019-07-31 11:10:49 +09:00
topecongiro
9e960e7d6a Release v1.4.1 2019-07-30 14:39:07 +09:00
rChaser53
fe05e88831 fix to build with rustc 1.38.0-nightly (4560cb830 2019-07-28) (#3712) 2019-07-30 14:32:38 +09:00
topecongiro
365461349d
Release 1.4.0 2019-07-29 05:58:18 +09:00
Seiichi Uchida
983a92c872
Update rustc-ap-* crates to 541.0.0 (#3707) 2019-07-29 05:52:45 +09:00
Seiichi Uchida
b004329782
Simplify code around visit_fn (#3698) 2019-07-21 13:26:41 +09:00
Seiichi Uchida
c0e616bc1d
Implement closing-block procedure without relying on missed_span module (#3691) 2019-07-17 23:07:12 +09:00
Michele d'Amico
76e2ba25bd #3665: Implemented (#3689) 2019-07-17 09:40:33 +09:00
Seiichi Uchida
66c27c9161
Add #[ignore] to test that runs external process (#3690) 2019-07-16 19:36:23 +09:00
topecongiro
65931cd09d
Release 1.3.3 2019-07-15 22:47:10 +09:00
Seiichi Uchida
89940e541f
Fix bugs related to file-lines (#3684) 2019-07-15 22:41:56 +09:00
Stéphane Campinas
6487422b3e fix print-config minimal option (#3687) 2019-07-15 20:58:54 +09:00
calebcartwright
6f67f07752 refactor: simplify manifest_path option checks 2019-07-14 09:56:07 -05:00