about summary refs log tree commit diff
path: root/src/tools/rustfmt/tests
AgeCommit message (Collapse)AuthorLines
2025-01-09Only treat plain literal patterns as shortOli Scherer-0/+18
2024-12-22Make sure we don't lose default struct value when formatting structMichael Goulet-0/+36
2024-12-12Fix toolsMichael Goulet-0/+20
2024-11-24Fix rustfmt according to reviewNadrieril-0/+12
2024-11-21Implement the unsafe-fields RFC.Luca Versari-0/+27
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
2024-11-02Do not format generic constsMichael Goulet-0/+25
2024-10-15Rewrite for<..> async correctlyMichael Goulet-0/+2
2024-10-15Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errorsMatthias Krüger-0/+19
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2024-10-07Add basic pin sugar support to rustfmtEric Holk-0/+19
2024-10-01Remove anon struct and union typesMichael Goulet-31/+0
2024-09-19Merge commit 'b23b69900eab1260be510b2bd8922f4b6de6cf1e' into sync-from-rustfmtYacin Tmimi-100/+877
2024-09-06Fix toolsMichael Goulet-0/+15
2024-08-07Stabilize `unsafe_attributes`carbotaniuman-1/+0
2024-08-02rustfmt: Remove `has_cpuid` from testJubilee Young-18/+0
2024-07-11Remove rustdoc tests which no longer parseMichael Goulet-10/+0
2024-06-28Implement RTN support in rustfmtMichael Goulet-0/+10
2024-06-23Implement use<> formatting in rustfmtMichael Goulet-0/+64
2024-06-22Merge commit 'e4944185ae09c99f59b460e358909f329010ea9c' into ↵Caleb Cartwright-10/+657
sync-from-rustfmt-24-06
2024-06-06Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, ↵Rémy Rakic-4/+4
r=davidtwco" This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing changes made to 36316df9fe6c3e246153fe6e78967643cf08c148.
2024-04-24Error on using `yield` without also using `#[coroutine]` on the closureOli Scherer-2/+4
And suggest adding the `#[coroutine]` to the closure
2024-04-18Disallow ambiguous attributes on expressionsDominik Stolz-4/+4
2024-03-27Add rustfmt test for mut ref mutJules Bertholet-0/+20
2024-03-06Add basic rustfmt implementation & testRoss Smyth-0/+40
2024-03-05errors: share `SilentEmitter` between rustc and rustfmtDavid Wood-1/+6
Signed-off-by: David Wood <david@davidtw.co>
2024-02-26Move `emit_stashed_diagnostic` call in rustfmt.Nicholas Nethercote-0/+3
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-23Explicitly call `emit_stashed_diagnostics`.Nicholas Nethercote-0/+3
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-14Rollup merge of #121035 - compiler-errors:rustfmt-asyncness, r=calebcartwrightGuillaume Gomez-0/+3
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-13Format async bounds in rustfmtMichael Goulet-0/+3
2024-02-12Add rustfmt test from #117942Frank King-0/+12
2024-01-22Check that a token can begin a nonterminal kind before parsing it as a macro ↵Michael Goulet-0/+4
arg in rustfmt
2023-12-10Remove edition umbrella features.Eric Huss-4/+4
2023-10-22Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-syncCaleb Cartwright-5/+1766
2023-10-20Rename lots of files that had `generator` in their nameOli Scherer-0/+0
2023-10-20s/generator/coroutine/Oli Scherer-3/+3
2023-08-24Parse unnamed fields and anonymous structs or unionsFrank King-0/+19
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-07-01Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmtCaleb Cartwright-2/+788
2023-06-19Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-syncCaleb Cartwright-4/+818
2023-05-02Rustfmt support for negative bounds, testMichael Goulet-0/+11
2023-05-01remove rustfmt testcase for type ascriptionyukang-23/+0
2023-05-01fix testsyukang-42/+27
2023-03-12Remove uses of `box_syntax` in rustc and toolsclubby789-37/+0
2023-01-24Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-from-rustfmtCaleb Cartwright-30/+1438
2023-01-11Change `src/test` to `tests` in source files, fix tidy and testsAlbert Larsan-4/+4
2023-01-05Detect closures assigned to binding in blockEsteban Küber-0/+1
Fix #58497.
2022-08-30Stabilize GATsJack Huey-12/+0
2022-08-23Stabilize `#![feature(label_break_value)]`Joshua Nelson-4/+0
# 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: - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs + Diagnostics: - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001 - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/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-07-12Add rustfmt test for formatting `for<>` before closuresMaybe Waffle-0/+16
2022-06-22Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmtCaleb Cartwright-11381/+184
2022-06-12Merge commit '7b73b60faca71d01d900e49831fcb84553e93019' into sync-rustfmtCaleb Cartwright-97/+12250
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-28/+2