Commit Graph

73 Commits

Author SHA1 Message Date
Febriananda Wida Pramudita
76ab3c19d8 refactor if into match 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
1f806d979a Update src/matches.rs
Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
2024-04-26 07:21:32 -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
3854ce9aca add test and simplify code 2024-04-26 07:21:32 -06:00
Febriananda Wida Pramudita
22a4306a7e fix the logic 2024-04-26 07:21:32 -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
Josh Soref
cedb7b5058
Spelling (#5753)
various spelling fixes
---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2024-01-25 18:55:23 -05:00
Yacin Tmimi
6cc513f5e5 Merge remote-tracking branch 'origin/master' into subtree_sync_with_1.77.0_nightly_2023_12_27 2023-12-28 16:50:17 -05:00
Eric Holk
0315daafee Plumb awaitness of for loops 2023-12-19 12:26:20 -08:00
Yacin Tmimi
227e361187 Merge remote-tracking branch 'upstream/master' into subtree_push_2023_12_12 2023-12-12 11:45:27 -05:00
Nadrieril
a445ba8a9d Parse a pattern with no arm 2023-12-03 12:25:46 +01: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
f35f25287f Merge remote-tracking branch 'upstream/master' into subtree-sync-2023-10-22 2023-10-22 12:45:06 -05: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
d8aeabaee1 include block label length when calculating pat_shape of a match arm
Previously we alwasy assumed the match arm pattern would have
`shape.width` - 5 characters of space to work with.

Now if we're formatting a block expression with a label we'll take the
label into account.
2023-08-13 14:03:58 -05:00
Nilstrieb
aca22c73fd Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Nilstrieb
e83a7cadd2 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
clubby789
4e658cc01e Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
Caleb Cartwright
6db6bafc61 Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree 2021-12-29 20:49:39 -06:00
Caleb Cartwright
f99e3582bd Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync 2021-11-07 20:37:34 -06:00
Caleb Cartwright
2b41b6d022 Merge commit 'efa8f5521d3813cc897ba29ea0ef98c7aef66bb6' into rustfmt-subtree 2021-10-20 00:11:59 -05:00
Caleb Cartwright
e4b8714c09 Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-rustfmt 2021-07-25 22:57:19 -05:00
Caleb Cartwright
2c6339571b chore: apply pattern parsing changes 2021-04-02 23:21:06 -05: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
d6a220b70a feat: support config. of leading match arm pipe 2020-09-24 09:43:31 -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
b173b42354 refactor: rename libsyntax --> rustc_ast 2020-03-27 22:29:12 -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
c60416ed21 deps: update rustc-ap to v642.0.0 2020-02-08 22:21:37 -06:00
Seiichi Uchida
383306e5fe
Update rustc-ap-* crates to 606.0.0 (#3835) 2019-10-05 23:40:24 +09:00
Seiichi Uchida
ceca01465a
Update deps (#3788) 2019-09-08 23:33:21 +09:00
Seiichi Uchida
783948fcbb
Fix handling of match arm's rewrite (#3775) 2019-09-05 11:15:46 +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
Seiichi Uchida
983a92c872
Update rustc-ap-* crates to 541.0.0 (#3707) 2019-07-29 05:52:45 +09:00
Stéphane Campinas
84c2356590 handle unicode chars in closures (#3632)
The `NotUnicode` branch was unecessarily put on a new line, although it
was within max width:

```diff
 fn baz() {
     let our_error_b = result_b_from_func.or_else(|e| match e {
         NotPresent => Err(e).chain_err(|| "env var wasn't provided"),
-        NotUnicode(_) => Err(e).chain_err(|| "env var was very very very bork文字化ã"),
+        NotUnicode(_) => {
+            Err(e).chain_err(|| "env var was very very very bork文字化ã")
+        }
     });
 }
```
2019-06-17 08:53:17 +09:00
Seiichi Uchida
2244f326e6
Cargo update (#3559)
Update `rustc-ap-*` crates to 486.0.0.
2019-06-03 23:57:02 +09:00
Ruben Schmidmeister
618d092bf7
Enable unreachable_pub lint 2019-05-09 20:37:51 +02:00
topecongiro
b57e0e2279 Disallow putting a body with attributes on the same line 2019-04-14 20:13:54 +09:00
topecongiro
3d80678e24 Do not include body's attributes in arrow_span 2019-04-14 20:13:07 +09:00
Alexander Regueiro
7a3b7c9275 Various cosmetic improvements (#3403) 2019-02-19 11:56:42 +09:00
Hirokazu Hata
4bb90f5cc8 Fix rust_2018_idioms warnings 2019-02-09 16:14:30 +09:00
Evgenii
ece629b1cc transition to Rust 2018 2019-02-04 13:30:43 +03:00
Stéphane Campinas
e305262493
clarify the version-gate used for the #3229 change 2018-12-19 09:36:47 +01:00
Stéphane Campinas
b73a602d6e
version-gate the trailing semicolon change of return statements inside a match arm 2018-12-14 09:54:23 +01:00
Stéphane Campinas
d03d9a45ef
end expressions like return/continue/break with a semicolon
Close #3213
2018-11-29 20:39:07 +01:00
Stéphane Campinas
9467033a8e
fix the logic for retaining a comment before the arrow in a match 2018-11-07 15:00:33 +01:00