Commit Graph

5578 Commits

Author SHA1 Message Date
Camille GILLOT
96e583fd52 Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
Robert Sammelson
b6367235eb Improve tests for #5852 2023-08-30 23:55:13 -04:00
David Bar-On
c7c57f8a16 Fix issue with extra semicolon when import comment preceeds semicolon 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
John Kåre Alsaker
eb349e35aa Use conditional synchronization for Lock 2023-08-30 06:10:02 +02:00
John Kåre Alsaker
9c25fbfa06 Use conditional synchronization for Lock 2023-08-30 06:10:02 +02: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
Viktor Lazarev
df2471bf4c
Fix typos in index.html (#5896) 2023-08-27 14:46:09 -05:00
Collin Styles
0439486ff7
Fix link in CHANGELOG.md (#5894) 2023-08-26 13:01:08 -05: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
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
Kevin Ji
16db2a4be2 Use OR operator in Cargo.toml license field
The use of `/` is deprecated, per the Cargo reference:
https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields
2023-08-18 09:31:27 -04: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
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
bors
327903e669 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00:00
bors
00b60cdd46 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00:00
Matthias Krüger
6e87f866ec Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

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.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Matthias Krüger
af72b88a20 Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

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.

r? compiler-errors
2023-08-04 21:31:57 +02:00
bors
e3d6bf8daa Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00
bors
e6c4606bfe Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00: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
Matthias Krüger
4cc22af56c Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
Suggests turbofish in patterns

Fixes #114112

r? ```@estebank```
2023-08-03 17:29:07 +02:00
Matthias Krüger
2c8cc96ac3 Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
Suggests turbofish in patterns

Fixes #114112

r? ```@estebank```
2023-08-03 17:29:07 +02:00
Nicholas Nethercote
14101ed5a5 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
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
35d875a3a0 Fix rustfmt dep 2023-08-03 00:13:41 +08: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
aac383e3ea Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00: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