Commit Graph

1978 Commits

Author SHA1 Message Date
Yacin Tmimi
76cd550c54 Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2024-06-13 2024-06-12 22:37:39 -04:00
Rémy Rakic
783a411f67 Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco"
This reverts commit 57dad1d75e, reversing
changes made to 36316df9fe.
2024-06-06 20:39:54 +00:00
WeiTheShinobi
bf7bb56524 Prevent rustfmt from removing inner attributes in inline const blocks
Fixes 6158
2024-05-31 20:40:07 -06:00
Febriananda Wida Pramudita
23c11f3a08 rename file and remove unecessary file and add testcase 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
6540304790 add test and simplify code 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
3854ce9aca add test and simplify code 2024-04-26 07:21:32 -06:00
Oli Scherer
20e40d5efe Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Dominik Stolz
966dd60251 Disallow ambiguous attributes on expressions 2024-04-18 20:42:19 +02:00
hanghuge
728939191e chore: fix some typos
Signed-off-by: hanghuge <cmoman@outlook.com>
2024-04-07 15:20:42 -05:00
Yacin Tmimi
a848e28ff2 Revert "Initial work on formatting headers"
This reverts commit dd301b0c04.
2024-04-07 13:54:23 -05:00
Jules Bertholet
31a4eae7ea Add rustfmt test for mut ref mut 2024-03-27 16:38:56 -04:00
Tanishq Rajesh Jain
202fa22cee
Fix: ICE when formatting builtins
Replace `unreachable!` with `None`. Now rustfmt won't
panic when it comes across a `builtin # offset_of` or any other builtin
2024-03-17 13:32:41 -04:00
Deadbeef
dd301b0c04 Initial work on formatting headers 2024-03-12 21:36:52 -06:00
ding-young
9580747a76
Fix failure with => in comment after match => (#6092)
* Find arrow with find_last_uncommented
* Add version gate for arrow finding fix
2024-03-11 22:26:28 -04:00
Ross Smyth
1709dd59bd Add basic rustfmt implementation & test 2024-03-06 00:51:45 -05:00
David Wood
124808b582 errors: share SilentEmitter between rustc and rustfmt
Signed-off-by: David Wood <david@davidtw.co>
2024-03-05 10:14:36 +00:00
MarcusGrass
73c81495cd
Ensure space after binary exprs that ends with . before range expr
Removing the space would lead to compilation errors.
2024-03-04 22:19:57 -05:00
Nicholas Nethercote
90af751966 Move emit_stashed_diagnostic call in rustfmt.
This call was added to `parse_crate_mod` in #121487, to fix a case where
a stashed diagnostic wasn't emitted. But there is another path where a
stashed diagnostic might fail to be emitted if there's a parse error, if
the `build` call in `parse_crate_inner` fails before `parse_crate_mod`
is reached.

So this commit moves the `emit_stashed_diagnostic` call outwards, from
`parse_crate_mod` to `format_project`, just after the
`Parser::parse_crate` call. This should be far out enough to catch any
parsing errors.

Fixes #121517.
2024-02-26 10:45:45 +11:00
cui fliter
21f353a637
Spelling fixes(#6088)
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-02-23 09:57:24 -05:00
Nicholas Nethercote
ce71137b96 Explicitly call emit_stashed_diagnostics.
Commit 72b172b in #121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes #121450.
2024-02-23 16:09:51 +11:00
Jules Bertholet
5805040d28
Search span using *unnormalized* ident (#6073)
Fixes 6069

Calling `item.ident.as_str()` returns an NFC normalized ident, which
might not be what's written in the source code. To avoid panics when
calling `snippet_provider.span_after` use the ident from the source.
2024-02-14 14:40:55 -05:00
Guillaume Gomez
e504c64a41 Rollup merge of #121035 - compiler-errors:rustfmt-asyncness, r=calebcartwright
Format `async` trait bounds in rustfmt

r? `@ytmimi` or `@calebcartwright`

This PR opts to do formatting in the rust-lang/rust tree because otherwise we'd have to wait until a full sync, and rustfmt is currently totally removing the `async` keyword.

cc https://github.com/rust-lang/rustfmt/issues/6070
2024-02-14 15:41:27 +01:00
Michael Goulet
bed388348b Format async bounds in rustfmt 2024-02-13 16:05:41 +00:00
Frank King
16250ea7ba Add rustfmt test from #117942 2024-02-12 12:47:30 +08:00
David Bar-On
7bedb9fb8c
wrap macro line with width off by one char beyond max width (#5582)
Fix issue 3805
2024-01-28 19:07:30 -05:00
Michael Goulet
b92320c39b Check that a token can begin a nonterminal kind before parsing it as a macro arg in rustfmt 2024-01-22 01:49:33 +00:00
IVIURRAY
bf967319e2
Add config option generated_marker_line_search_limit (#5993)
`generated_marker_line_search_limit` allows users to configure how many
lines rustfmt should search for an `@generated` marker comment when
`format_generated_files=false`

---------

Co-authored-by: Jordan Eldredge <jordan@jordaneldredge.com>
2024-01-20 11:14:50 -05:00
IVIURRAY
6356fca675
Prevent enum variant attributes from wrapping one character early
Fixes 5801 when using `version=Two`

Previously, doc comments would wrap one character less than the
`comment_width` when using `wrap_comments=true`, and fn-like attributes
would wrap one character before the `attr_fn_like_width`.

Now, when using `version=Two` enum variant attributes won't wrap early
2024-01-08 10:06:25 -05:00
Sam Tay
d86fc1bf64
Make trace! formatting consistent with other log macros (#5989)
Fixes 5987

rustfmt already special cases the formatting for the `debug!`, `info!`,
`warn!`, and `error!`, macros from the `log` crate. However, this
speical case handling did not apply to the `trace!` macro.

Now when using `Version=Two` rustfmt will also special case the
formatting for the `trace!` macro.
2023-12-23 22:39:01 -05:00
Yacin Tmimi
227e361187 Merge remote-tracking branch 'upstream/master' into subtree_push_2023_12_12 2023-12-12 11:45:27 -05:00
Eric Huss
b9ad02421a Remove edition umbrella features. 2023-12-10 13:03:28 -08:00
GambitingMan
8d2c4157e6 Fixes comma added to comment in where-clause 2023-11-01 20:21:05 -05:00
GambitingMan
041f113159
Fixed error caused by combination of match_arm_blocks and control_brace_style
Fixes 5912

When `control_brace_style = "AlwaysNextLine"`, the code seems to always assume that `body_prefix` is `{`. This is however not the case when `match_arm_blocks = false`. This causes `block_sep` to introduce extra white space that causes the error.

The fix was to check if `body_prefix` is empty before matching on `ControlBraceStyle::AlwaysNextLine`.
2023-10-23 20:27:26 -04:00
Caleb Cartwright
04bd7201a9 Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-sync 2023-10-22 20:21:44 -05:00
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
7a20da333b Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
Oli Scherer
4b5ef37e21 Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
Oli Scherer
1b9dd4b4ad s/generator/coroutine/ 2023-10-20 21:14:01 +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
af6a6a3c2c 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