about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
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).
2022-02-25Rollup merge of #94344 - notriddle:notriddle/suggest-parens-more, r=oli-obkMatthias Krüger-2/+16
diagnostic: suggest parens when users want logical ops, but get closures Fixes #93536
2022-02-24diagnostic: suggest parens when users want logical ops, but get closuresMichael Howell-2/+16
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-4/+7
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-9/+10
2022-02-23rustc_errors: remove `struct_dummy`.Eduard-Mihai Burtescu-3/+5
2022-02-23Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.Eduard-Mihai Burtescu-2/+2
2022-02-19Adopt let else in more placesest31-3/+2
2022-02-12Rollup merge of #93595 - compiler-errors:ice-on-lifetime-arg, r=jackh726Matthias Krüger-3/+3
fix ICE when parsing lifetime as function argument I don't really like this, but we basically need to emit an error instead of just delaying an bug, because there are too many places in the AST that aren't covered by my previous PRs... cc: https://github.com/rust-lang/rust/issues/93282#issuecomment-1028052945
2022-02-03clippy::perf fixesMatthias Krüger-3/+3
single_char_pattern and to_string_in_format_args
2022-02-02fix ICE when parsing lifetime as function argumentMichael Goulet-3/+3
2022-01-31Write UI tests, tweak message5225225-3/+2