Commit Graph

1941 Commits

Author SHA1 Message Date
Caleb Cartwright
c2515dfa41 tests: fix let chain tests 2023-10-22 13:30:25 -05:00
Caleb Cartwright
f35f25287f Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-10-22 2023-10-22 12:45:06 -05:00
Oli Scherer
4b5ef37e21 Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
Oli Scherer
0f739816c9 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Yacin Tmimi
547577fa5d implement sinlge line let-chain rules
for now, let-chains can only be formatted on a single line if the chain
consits of 2 expressions where the first is an identifier proceeded by
any number of unary operators and the second is a let-expr.
2023-10-10 20:13:50 -05:00
Cameron Steffen
457dc79a35 Add support for ExprKind::Let 2023-10-10 20:13:50 -05:00
Caleb Cartwright
2707103154 fix: adjust span derivation for const generics 2023-10-08 19:55:04 -04:00
GambitingMan
a1fabbf386
Bugfix/comment duplication (#5913)
* Fix #5871

* Only idempotence test is necessary

* Update src/expr.rs

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2023-09-20 14:29:02 -05:00
pan93412
18737ddc72
Prefer light_rewrite_comment if it is not a doccomment (#5536)
Fixes 5533, 5568, 5907

Prevent `format_code_in_doc_comments=true` from affecting how non-doc comments are formatted.


---------

Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
2023-09-11 14:15:59 -04:00
Linda_pp
262feb3337
Fix checking if newline is needed before else in let-else statement
Fixes 5901

Take leading attributes and comments into consideration when determining if we need to wrap the `else` keyword onto the next line.
2023-09-08 21:05:07 -04:00
Robert Sammelson
b6367235eb Improve tests for #5852 2023-08-30 23:55:13 -04:00
Robert Sammelson
1340fc412a Fix issues with formatting imports with comments 2023-08-30 23:55:13 -04:00
xxchan
f89cd3c1f3
Don't treat lines starting with . or ) as ordered markdown lists (#5839)
Fixes 5835

Ordered markdown lists start with 0-9 digits followed by a `.` or a `)`.
Now, rustfmt ensure that the `.` or `)` is only preceded by numeric
characters before deciding that it's reached an `ItemizedBlock`
2023-08-29 08:46:44 -04:00
Frank King
cef3117302 Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field
definitions.

Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-08-24 11:17:54 +08:00
tdanniels
e480739e56
Prevent ICE when formatting item-only vec!{} (#5879)
* Prevent ICE when formatting item-only `vec!{}`

Fixes 5735

Attempting to format invocations of macros which are considered "forced
bracket macros" (currently only `vec!`), but are invoked with braces
instead of brackets, and contain only items in their token trees,
currently triggers an ICE in rustfmt. This is because the function that
handles formatting macro invocations containing only items,
`rewrite_macro_with_items`, assumes that the forced delimiter style of
the macro being formatted is the same as the delimiter style in the
macro's source text when attempting to locate the span after the macro's
opening delimiter. This leads to the construction of an invalid span,
triggering the ICE.

The fix here is to pass the old delimiter style to
`rewrite_macro_with_items` as well, so that it can successfully locate
the span.
2023-08-17 15:21:53 -04:00
Kevin Ji
a57d57b16a Remove newlines in where clauses for v2
Fixes #5655.
2023-08-16 12:34:21 -04:00
fee1-dead
4b01e62943
refactor ABI formatting (#5845)
fixes 5701

Whenever we see an `extern "Rust"` on a function, we don't strip it from the function.

If there's any future desire to have rustfmt remove an explicit "Rust" ABI, as it historically did prior to this change, then we can consider updating the rustfmt config surface to support that scenario
2023-08-14 08:19:23 -04:00
Yuri Astrakhan
b069aac44d
Inline format arguments for easier reading (#5881)
* Inline format arguments for easier reading

Code becomes shorter and often easier to read when format args are inlined.  Note that I skipped the mixed cases to make it more straightforward (could be done separatelly).

Also, there are two FIXME comments - for some reasons inlining makes format string exceed 100 char line width and crash.

```
cargo clippy --workspace --allow-dirty --fix --benches --tests --bins -- -A clippy::all -W clippy::uninlined_format_args
```

* address feedback
2023-08-13 14:14:31 -05:00
Yacin Tmimi
e86c2ba545 Don't flatten blocks that have labels 2023-08-13 14:03:58 -05:00
Yacin Tmimi
0d4c1431f5 Improve formatting of empty macro_rules! definitions
Fixes 5882
2023-08-13 13:04:33 -05:00
Catherine
a72613be50 Add parenthesis around closure method call 2023-08-01 04:36:16 -04:00
Yacin Tmimi
cdfa2f86b7 Handle dyn* syntax when rewriting ast::TyKind::TraitObject
Resolves 5542

Prior to rust-lang/rust#101212 the `ast::TraitObjectSyntax` enum only
had two variants `Dyn` and `None`. The PR that introduced the `dyn*`
syntax added a new variant `DynStar`, but did not update the formatting
rules to account for the new variant.

Now the new `DynStar` variant is properly handled and is no longer
removed by rustfmt.
2023-07-27 19:52:26 -05:00
Michael Goulet
2db13f448c Support non-lifetime binders 2023-07-19 22:18:51 -05:00
tdanniels
b944a32e5c
Prevent ICE when formatting an empty-ish macro arm (#5833)
Fixes 5730

Previously rustfmt was attempting to slice a string with an invalid
range (`start > end`), leading to the ICE.

When formatting a macro transcriber snippet consisting of a lone
semicolon, the snippet was being formatted into the empty string,
leading the enclosing `fn main() {\n}` added by `format_code_block` to
be formatted into `fn main() {}`. However, rustfmt was assuming that the
enclosing function string's length had been left unchanged. This was
leading to an invalid range being constructed when attempting to trim
off the enclosing function.

The fix is to just clamp the range's start to be less than or equal
to the range's end, since if `end < start` there's nothing to iterate
over anyway.
2023-07-18 20:48:57 -05:00
Caleb Cartwright
f2bad9c7af fix: handle skip_macro_invocations from config file 2023-07-05 17:46:03 -04:00
Cosmic Horror
3c3cf6192d Add failing test 2023-07-03 12:06:25 -05:00
Deadbeef
bb87a1b717 Rewrite float literals ending in dots with parens in method calls 2023-07-03 12:03:12 -05:00
Caleb Cartwright
78331eefaf Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt 2023-07-01 02:49:12 -05:00
Yacin Tmimi
1de65a2711 wrap else to next line if let-else pattern is multi-lined
This rule wasn't explicity stated in the style guide so it was missed,
but luckily we caught it during testing.
2023-07-01 01:06:35 -05:00
Yacin Tmimi
fe8b72d98e implement single_line_let_else_max_width
This allows users to configure the maximum length of a single line
`let-else` statements. `let-else` statements that otherwise meet the
requirements to be formatted on a single line will have their divergent
`else` block formatted over multiple lines if they exceed this length.

**Note**: `single_line_let_else_max_widt` will be introduced as a stable
configuration option.
2023-07-01 01:06:35 -05:00
Yacin Tmimi
9386b32f5a wrap else { for long, single-lined initializer expressions
This helps to prevent max width errors.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
e4a9892b7a Add additional test cases
These test cases try to cover various edge cases. For example, comments
around the else keyword and long, unbreakable, single-line initializer
expressions, and long patterns.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
00fef2d51d Implement wrapping rules to force else on a newline in let-else 2023-06-20 08:26:11 -05:00
Yacin Tmimi
9316df0ca2 Initial pass at implementing let-else 2023-06-20 08:26:11 -05:00
Yacin Tmimi
75870c55b9 Extract logic for rewriting else keyword into function
The function properly handles recovering comments before and after the
`else` keyword, and properly handles how to write the else when users
configure `control_brace_style`.
2023-06-20 08:26:11 -05:00
Caleb Cartwright
ed3e96e3d1 Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync 2023-06-19 23:13:56 -05:00
Caleb Cartwright
312a86b46b Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-06-19 2023-06-19 20:56:20 -05:00
Lukasz Anforowicz
f4201ef2cb Handling of numbered markdown lists.
Fixes issue #5416
2023-06-19 20:50:01 -05:00
Yacin Tmimi
2c30fa5a82 Adjust enum variant spans to exclude any explicit discriminant
Fixes 5686

For reference, explicit discriminants were proposed in [RFC-2363].

`ast::Variant` spans extend to include explicit discriminants when they
are present.

Now we'll adjust the span of enum variants to exclude any explicit
discriminant.

[RFC-2363]: https://rust-lang.github.io/rfcs/2363-arbitrary-enum-discriminant.html
2023-06-19 10:12:19 -05:00
Yacin Tmimi
ac2ebd3a78 Prevent ICE when calling parse_attribute without an attribute
Fixes 5729

`parse_attribute` will panic if the first token is not a `#`. To prevent
this we return early instead of trying to parse an invalid attribute.
2023-06-19 09:58:12 -05:00
Deadbeef
5f9de6bfc9 Recover comments between attrs and generic param
Fixes #5320.
2023-06-11 19:34:36 -05:00
Michael Goulet
8ed5d5de3d Rustfmt support for negative bounds, test 2023-05-02 22:36:25 +00:00
yukang
9d20134a78 remove rustfmt testcase for type ascription 2023-05-01 16:15:17 +08:00
yukang
a74d2d7440 fix tests 2023-05-01 16:15:17 +08:00
Yacin Tmimi
475396a03c Prevent ICE when calling parse_attribute in parse_cfg_if_inner
Fixes 5728

Previously we were ignoring the diagnostic error, which lead to the ICE.
Now we properly cancel the error.
2023-04-01 13:21:12 -05:00
clubby789
a5ba6e025f Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
Caleb Cartwright
34f9ca28f2 fix: use correct span for struct generics 2023-02-16 00:03:36 -05:00
Rajiv Sharma
5391847ea5 Fix #5488 - prevent shorthand init for tuple struct
Closes #5488

Fix for #5488. Before applying shorthand initialization for structs,
check if identifier is a literal (e.g. tuple struct). If yes, then do
not apply short hand initialization.

Added test case to validate the changes for the fix.
2023-02-01 21:33:19 -06:00
Thaqib
e2996a807b
Lists doc comments fix4041 (#5560)
* add + start of an itemized line

* add test

* fix format

* fix tests

* update doc comment
2023-02-01 21:26:12 -06:00
Wim Looman
3f36c997bf Test that with all comment wrapping disabled table comments are not wrapped 2023-01-29 16:47:06 -06:00