Commit Graph

5492 Commits

Author SHA1 Message Date
Nicholas Nethercote
d165d4ad38 Remove MacDelimiter.
It's the same as `Delimiter`, minus the `Invisible` variant. I'm
generally in favour of using types to make impossible states
unrepresentable, but this one feels very low-value, and the conversions
between the two types are annoying and confusing.

Look at the change in `src/tools/rustfmt/src/expr.rs` for an example:
the old code converted from `MacDelimiter` to `Delimiter` and back
again, for no good reason. This suggests the author was confused about
the types.
2023-08-03 09:03:30 +10:00
Mu001999
e42bc9ec66 Fix rustfmt dep 2023-08-03 00:13:41 +08:00
Catherine
a72613be50 Add parenthesis around closure method call 2023-08-01 04:36:16 -04:00
Oli Scherer
f122a3328d Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
bors
4eeecaed1d Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnr
discard default auto trait impls if explicit ones exist (rebase of #85048)

Rebase of #85048
2023-07-28 10:41:00 +00:00
bors
1f369f8b6a Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkov
Less `TokenTree` cloning

`TokenTreeCursor` has this comment on it:
```
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
```
This PR completes that FIXME. It doesn't have much perf effect, but at least we now know that.

r? `@petrochenkov`
2023-07-28 01:21:27 +00: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
Nicholas Nethercote
e60a9e2c97 Avoid into_trees usage in rustfmt.
Token tree cloning is only needed in one place.
2023-07-27 11:58:42 +10:00
Trevor Gross
08fd1644d2 Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to
indicate that output should be blessed, but they use different variable names.
In order to improve consistency, this patch applies the following changes:

- Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always
  available
- Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS`
- Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS`
- Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS`
- Adjust the blessable test in `rustc_errors` to use this same
  convention
- Update documentation where applicable

Any tools that uses `RUSTC_BLESS` should check that it is set to any value
other than `"0"`.
2023-07-26 16:54:02 -04:00
Oli Scherer
c0ee8f5fea Make x test src/tools/rustfmt --bless format rustfmt with the freshly built in-tree version 2023-07-26 08:22:52 +00:00
Oli Scherer
a3dfd82559 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00: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
Esteban Küber
6013a8014b On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00: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
Oleksandr Babak
d0762f032b always emit consider AutoImplCandidates for them if they don't also have a ProjectionCandidate 2023-07-06 11:37:21 +02: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
78331eefaf Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt 2023-07-01 02:49:12 -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
Nilstrieb
80bf3ea542 Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Syntactically accept `become` expressions (explicit tail calls experiment)

This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature.

cc `@scottmcm`
2023-06-21 07:37:02 +02: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
ed3e96e3d1 Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync 2023-06-19 23:13:56 -05:00
Caleb Cartwright
3f7c366fc0 chore: release v1.5.3 2023-06-19 22:54:36 -05:00