Commit Graph

5437 Commits

Author SHA1 Message Date
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
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
Yacin Tmimi
641d4f5898 Build nightly rustfmt using --all-features in CI
Previously we were only building rustfmt with default features in CI. We
recently received a report that rustfmt was unable to compile with the
`generic-simd` feature, which is not enabled by default. To prevent a
similar situation in the future we'll start build nightly rustfmt with
all features enabled.
2023-08-13 13:49:06 -05:00
Yacin Tmimi
177ef66947 Fix building rustfmt with --features generic-simd
Bumping bytecount from `0.6.2` -> `0.6.3` allows rustfmt to properly
build when using the `generic-simd` feature.
2023-08-13 13:49:06 -05:00
Yacin Tmimi
0d4c1431f5 Improve formatting of empty macro_rules! definitions
Fixes 5882
2023-08-13 13:04:33 -05:00
Charles Lew
9f58224123 Update Unicode data to 15.0 2023-08-13 13:01:38 -05:00
Richard
36af403e6b
improve the --file-lines help (#5846)
* improve the file-lines example

* fix help order
2023-08-12 17:05:04 -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
Deadbeef
a9ae746267 misc code cleanup 2023-07-19 22:26:43 -05:00
Michael Goulet
2db13f448c Support non-lifetime binders 2023-07-19 22:18:51 -05:00
xxchan
c6d39a2259
doc: fix instruction about running Rustfmt from source code (#5838)
Update docs to include an example of running `rustfmt` built from src,
and show how users can set the `RUSTFMT` environment variable to test
`cargo-fmt` using the `rustfmt` they built from src.
2023-07-19 14:22:24 -04: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
fee1-dead
1842967542
automatically add pr-not-reviewed to new PRs (#5843) 2023-07-18 20:48:01 -05:00
Jordan McQueen
e0e633ef14
Use matches!() macro to improve readability (#5830)
* Use matches!() macro to improve readability

1. Use `matches!()` macro in `is_line_comment` and `is_block_comment` to
improve readability.
2. Very sightly improve the wording of the doc comment for these two functions.

* Update wording on doc comment on is_line_comment()
2023-07-17 17:51:51 -05:00
xxchan
e9dfb6f217 fix link in CHANGELOG.md 2023-07-17 11:14:49 -04:00
Yacin Tmimi
d698bf4e1b use the branch_name as the default for the optional commit hash
There was an issue with the script when passing optional rustfmt configs
without specifying a commit hash. Because these optional values are
passed via positional arguments the configs ($4)  would be used in place
of the commit hash ($3). Now that we set a default value for the
optional commit hash we avoid this problem.
2023-07-11 19:10:59 -05:00
Yacin Tmimi
e5c212b56f Improve error discovery in check_diff.sh
The `set -e` option is used to immediately exit if any command exits
with a non zero exit status. This will help us catch errors in the
script, for example, needing the `LD_LIBRARY_PATH` to be set.
2023-07-11 19:10:59 -05:00
Yacin Tmimi
89500fab0e Add LD_LIBRARY_PATH in check_diff.sh
There were some upstream changes made a while back that requires this to
be set when building rustfmt from source like we do in the
`check_diff.sh` script.

See issue 5675 for more details.
2023-07-11 19:10:59 -05:00
Deadbeef
5ed7f74d10 Actually use tracing for logging 2023-07-06 12:03:44 -04:00
Caleb Cartwright
f2bad9c7af fix: handle skip_macro_invocations from config file 2023-07-05 17:46:03 -04:00
Cosmic Horror
d9a09925d7 Switch ast::Stmt rewriting use to stmt::Stmt::from_simple_block 2023-07-03 12:06:25 -05:00
Cosmic Horror
8850854746 Don't skip semicolon if exprs follow 2023-07-03 12:06:25 -05: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
Deadbeef
326af2bd21 Switch to tracing for logging 2023-07-03 11:52:38 -05:00
Caleb Cartwright
9a86da98c0 docs: fix a few links 2023-07-02 19:37:58 -05:00
Caleb Cartwright
dca1cf90ad chore: prep v1.6.0 release 2023-07-01 02:40:21 -05:00
Caleb Cartwright
3045c03b22 deps: bump proc-macro2 in config 2023-07-01 02:05:29 -05:00
Caleb Cartwright
23f48d9bb3 deps: bump proc-macro2 and toolchain 2023-07-01 02:05:29 -05:00
Maybe Waffle
aa691480c0 Implement become expression formatting in rustfmt 2023-07-01 02:05:29 -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
7b4e8a6d31 update else_block_exceeds_width calculation in let-else rewrite
By reversing the logic I felt that the code became a clearer. Also,
added a comment to make it clear that we need to take the trailing
semicolon for the `let-else` statement into account.
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
521f86bae5 Prevent single-line let-else if it would exceed max_width 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
7a3e4fca40 Implement let-else rewriting in terms of rewrite_let_else_block
`rewrite_let_else_block` gives us more control over allowing the `else`
block to be formatted on a single line than
`<ast::Block as Rewrite>::rewrite`.
2023-06-20 08:26:11 -05:00
Yacin Tmimi
8be748dbb7 Allow callers to determine if blocks can be formatted on a single line
This will make it easier to format the divergent blocks of `let-else`
statements since it'll be easier to prevent the block from being
formatted on a single line if the preconditions aren't met.
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
3f7c366fc0 chore: release v1.5.3 2023-06-19 22:54:36 -05:00
Caleb Cartwright
ec8a4d41f1
Merge pull request #5788 from calebcartwright/subtree-sync-2023-06-19
sync subtree in prep for next release
2023-06-19 21:57:03 -05:00
Caleb Cartwright
0b17d7ea46 chore: address merge and bump toolchain 2023-06-19 21:29:15 -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