about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
2022-08-01Use expr parse restrictions for let expr parsingMichael Goulet-39/+17
2022-07-29dont call type ascription 'cast'Michael Goulet-6/+7
2022-07-25Remove let-chain close brace check.Eric Huss-4/+1
2022-07-16Stabilize `let_chains`Caio-23/+7
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-26/+22
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-13Rollup merge of #99030 - rust-lang:notriddle/field-recovery, r=petrochenkovDylan DPC-0/+18
diagnostics: error messages when struct literals fail to parse If an expression is supplied where a field is expected, the parser can become convinced that it's a shorthand field syntax when it's not. This PR addresses it by explicitly recording the permitted `:` token immediately after the identifier, and also adds a suggestion to insert the name of the field if it looks like a complex expression. Fixes #98917
2022-07-12Update compiler/rustc_parse/src/parser/expr.rsMichael Howell-1/+1
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2022-07-12Parse closure bindersMaybe Waffle-26/+22
This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature
2022-07-08Fix last let_chains blockerCaio-8/+24
2022-07-07diagnostics: suggest naming a field after failing to parseMichael Howell-0/+13
2022-07-07diagnostics: mention the `:` token when struct fields fail to parseMichael Howell-0/+5
2022-06-25[rustc_parse] Forbid lets in certain placesCaio-3/+27
2022-06-13Improve parsing errors and suggestions for bad if statementsMichael Goulet-40/+66
2022-06-14Rollup merge of #95211 - terrarier2111:improve-parser, r=compiler-errorsYuki Okushi-4/+22
Improve parser diagnostics This pr fixes https://github.com/rust-lang/rust/issues/93867 and contains a couple of diagnostics related changes to the parser. Here is a short list with some of the changes: - don't suggest the same thing that is the current token - suggest removing the current token if the following token is one of the suggestions (maybe incorrect) - tell the user to put a type or lifetime after where if there is none (as a warning) - reduce the amount of tokens suggested (via the new eat_noexpect and check_noexpect methods) If any of these changes are undesirable, i can remove them, thanks!
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-29/+24
2022-06-12Improves parser diagnostics, fixes #93867threadexception-4/+22
2022-06-07Recover missing comma after match armMichael Goulet-13/+38
2022-06-06Add spaces before and after expr in add {} suggestionWaffle Maybe-2/+2
Co-authored-by: Michael Goulet <michael@errs.io>
2022-06-05Suggest removing label in `'label: non_block_expr`Maybe Waffle-3/+14
2022-06-05Do not suggest adding labeled block if there are no labeled breaksMaybe Waffle-0/+23
2022-06-05Suggest adding `{}` for `'label: non_block_expr`Maybe Waffle-2/+28
2022-06-02Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebankYuki Okushi-8/+8
Move conditions out of recover/report functions. `Parser` has six recover/report functions that are passed a boolean, and nothing is done if the boolean has a particular value. This PR moves the tests outside the functions. This has the following effects. - The number of lines of code goes down. - Some `use` items become shorter. - Avoids the strangeness whereby 11 out of 12 calls to `maybe_recover_from_bad_qpath` pass `true` as the second argument. - Makes it clear at the call site that only one of `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be run. r? `@estebank`
2022-05-24Minor improvement on else-no-if diagnosticMichael Goulet-8/+1
2022-05-23Parse expression after `else` as a condition if followed by `{`Michael Goulet-5/+57
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-2/+2
2022-05-19Move condition out of `maybe_recover_from_bad_qpath`.Nicholas Nethercote-8/+8
2022-04-30Add `do yeet` expressions to allow experimentation in nightlyScott McMurray-0/+21
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-3/+3
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-44/+46
2022-04-27Avoid producing `NoDelim` values in `TokenCursorFrame`.Nicholas Nethercote-1/+2
2022-04-07Shrink `Nonterminal`.Nicholas Nethercote-1/+1
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.
2022-04-05errors: implement fallback diagnostic translationDavid Wood-2/+2
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-04-03Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwcobors-0/+24
Suggest `i += 1` when we see `i++` or `++i` Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--` is tricky to handle). This is a continuation of #83536. r? `@estebank`
2022-04-01Rollup merge of #95293 - compiler-errors:braces, r=davidtwcoMatthias Krüger-11/+7
suggest wrapping single-expr blocks in square brackets Suggests a fix in cases like: ```diff - const A: [i32; 1] = { 1 }; + const A: [i32; 1] = [ 1 ]; ^ ^ ``` Also edit the message for the same suggestion in the parser (e.g. `{ 1, 2 }`). Fixes #95289
2022-03-30Addressed comments by @compiler-errors and @bjorn3Yuri Astrakhan-1/+1
2022-03-30Spellchecking compiler commentsYuri Astrakhan-1/+1
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-24suggest wrapping single-expr blocks in square bracketsMichael Goulet-11/+7
2022-03-23Add heuristic to avoid treating `x + +2` as incrementNoah Lev-0/+1
2022-03-23Improve function namesNoah Lev-2/+2
2022-03-23Emit both subexp and standalone sugg for postfixNoah Lev-3/+1
This solves the TODO.
2022-03-23Refactor, handle fields better, add field testsNoah Lev-8/+8
2022-03-23Move increment checks to improve errorsNoah Lev-0/+25
2022-03-18suggest removing type ascription in bad positionMichael Goulet-6/+35
2022-03-18use `self.create_snapshot_for_diagnostic` instead of `self.clone()`Takayuki Maeda-5/+6
2022-03-17Rollup merge of #94731 - TaKO8Ki:const-generic-expr-recovery, ↵Dylan DPC-11/+11
r=davidtwco,oli-obk Suggest adding `{ .. }` around a const function call with arguments closes #91020
2022-03-15use `format_args_capture` in some parts of rustc_parseTakayuki Maeda-18/+18
2022-03-10replace `self.clone()` with `self.create_snapshot_for_diagnostic()`Takayuki Maeda-11/+11
2022-03-07diagnostics: only talk about `Cargo.toml` if running under CargoMichael Howell-3/+1
Fixes #94646
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-3/+3
2022-02-28Tweak diagnosticsEsteban Kuber-10/+46
* Recover from invalid `'label: ` before block. * Make suggestion to enclose statements in a block multipart. * Point at `match`, `while`, `loop` and `unsafe` keywords when failing to parse their expression. * Do not suggest `{ ; }`. * Do not suggest `|` when very unlikely to be what was wanted (in `let` statements).