Michael Goulet
d6d9e76240
Add tests showing how comments are handled
2024-09-12 10:27:02 -05:00
Michael Goulet
df06d7eb09
Format trailing where clauses in rustfmt
2024-09-12 10:27:02 -05:00
rufevean
14d5165960
refactor - show file path in error message when parsing config from toml
...
fixes 6302
Display the path to the toml config file that rustfmt failed to parse
configurations from.
2024-09-12 10:57:14 -04:00
Yacin Tmimi
348a499e8b
Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2024-09-10
2024-09-10 01:15:02 -04:00
Michael Goulet
e1712ea92f
Fix tools
2024-09-06 10:32:48 -04:00
Yacin Tmimi
06e16449d2
Add test cases for issue 4381
...
This was one of the original issues filed against rustfmt that discussed
using a natural sort order instead of a lexicographical order. At the
time it was closed, but now that we're supporting version-sorting in
`style_edition=2024` I thought it would be good to add a test case.
2024-09-03 15:21:36 -04:00
Caleb Cartwright
46cb7d3220
refactor: improve mapping of legacy 'version' to 'style_edition'
2024-08-27 20:49:15 -05:00
Caleb Cartwright
065258659d
feat: implement 2024 Style Edition for expr overflows
2024-08-27 20:49:15 -05:00
Yacin Tmimi
6bcadd6aa4
Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2024-08-17
2024-08-17 14:36:42 -04:00
carbotaniuman
87949d7dde
Stabilize unsafe_attributes
2024-08-07 03:12:13 -05:00
Jubilee Young
6159460963
rustfmt: Remove has_cpuid
from test
2024-08-02 02:12:29 -07:00
Caleb Cartwright
d66ab31b53
tests: add new load_config tests
2024-07-28 19:37:36 -05:00
Caleb Cartwright
aa8a53f687
refactor: switch idempotence/system tests to style_edition
...
Updates all the various files utilized in the system and
idempotence tests to directly use the corresponding
'style_edition' configuration as opposed to keeping
the original 'version' values and relying on the mapping.
2024-07-28 19:37:36 -05:00
Caleb Cartwright
e04e411852
tests: validate style_edition derivation
...
Adds a few tests that validate the various scenarios
of precendence, overrides, and defaults to ensure the
correct 'style_edition' value is selected even when
other options like 'edition' and/or 'version' are included.
2024-07-28 19:37:36 -05:00
Michael Goulet
163d26ea9d
Remove rustdoc tests which no longer parse
2024-07-11 21:59:28 -04:00
Giordanno Castro
c8290a5fb7
ensure parse errors aren't emitted when formatting doc comments ( #6232 )
...
This adds a test case to validate behavior when using
`format_code_in_doc_comments=true`
2024-07-07 20:52:33 -04:00
Michael Goulet
88f98c2929
Implement RTN support in rustfmt
2024-06-28 14:20:44 -04:00
Michael Goulet
10277c97c2
Implement use<> formatting in rustfmt
2024-06-23 10:57:10 -04:00
Caleb Cartwright
ebce054347
Merge commit 'e4944185ae09c99f59b460e358909f329010ea9c' into sync-from-rustfmt-24-06
2024-06-22 15:33:45 -05: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
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
Jules Bertholet
31a4eae7ea
Add rustfmt test for mut ref mut
2024-03-27 16:38:56 -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
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
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
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
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
Eric Huss
b9ad02421a
Remove edition umbrella features.
2023-12-10 13:03:28 -08:00
Caleb Cartwright
04bd7201a9
Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-sync
2023-10-22 20:21:44 -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
1b9dd4b4ad
s/generator/coroutine/
2023-10-20 21:14:01 +00: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
Caleb Cartwright
78331eefaf
Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt
2023-07-01 02:49:12 -05:00
Caleb Cartwright
ed3e96e3d1
Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync
2023-06-19 23:13:56 -05:00
Michael Goulet
8ed5d5de3d
Rustfmt support for negative bounds, test
2023-05-02 22:36:25 +00:00
yukang
9d20134a78
remove rustfmt testcase for type ascription
2023-05-01 16:15:17 +08:00
yukang
a74d2d7440
fix tests
2023-05-01 16:15:17 +08:00
clubby789
a5ba6e025f
Remove uses of box_syntax
in rustc and tools
2023-03-12 13:19:46 +00:00
Caleb Cartwright
094b7f599c
Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-from-rustfmt
2023-01-24 14:16:03 -06:00
Albert Larsan
8c8aa3873f
Change src/test
to tests
in source files, fix tidy and tests
2023-01-11 09:32:13 +00:00
Esteban Küber
664c60a18e
Detect closures assigned to binding in block
...
Fix #58497 .
2023-01-05 21:29:36 +00:00
Jack Huey
748b031056
Stabilize GATs
2022-08-30 23:06:24 -04:00
Joshua Nelson
7852b8808b
Stabilize #![feature(label_break_value)]
...
# Stabilization proposal
The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.
There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630
Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251 . This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006
Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249
nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983 ) but there are no open RFCs,
and the design space seems rather speculative.
joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804
withoutboats has regrettably left the language team.
joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353
[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+
## Report
+ Feature gate:
- d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
- 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
- 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs
## Interactions with other features
Labels follow the hygiene of local variables.
label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
'foo: {
Err(())?;
break 'foo;
}
};
```
label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
|| break 'a
//~^ ERROR use of unreachable label `'a`
//~| ERROR `break` inside of a closure
}
```
label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
match false 'b: { //~ ERROR block label not supported here
_ => {}
}
}
macro_rules! m {
($b:block) => {
'lab: $b; //~ ERROR cannot use a `block` macro fragment here
unsafe $b; //~ ERROR cannot use a `block` macro fragment here
|x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
}
}
fn foo() {
m!({});
}
```
[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
Maybe Waffle
f026688c2a
Add rustfmt test for formatting for<>
before closures
2022-07-12 21:00:13 +04:00
Caleb Cartwright
ac595dd57a
Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt
2022-06-22 22:14:32 -05:00
Caleb Cartwright
d03a547cad
Merge commit '7b73b60faca71d01d900e49831fcb84553e93019' into sync-rustfmt
2022-06-12 22:03:05 -05:00