about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-17Make parse_seq_to_before_tokens take expected/nonexpected tokens, use in ↵Michael Goulet-3/+3
parse_precise_capturing_syntax
2024-06-07Rollup merge of #126052 - nnethercote:rustc_parse-more-cleanups, r=spastorinoMatthias Krüger-2/+6
More `rustc_parse` cleanups Following on from #125815. r? `@spastorino`
2024-06-06Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, ↵Rémy Rakic-19/+13
r=davidtwco" This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing changes made to 36316df9fe6c3e246153fe6e78967643cf08c148.
2024-06-06Reduce `pub` exposure.Nicholas Nethercote-2/+6
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_parse`.Nicholas Nethercote-0/+1
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-1/+1
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-1/+0
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-17Clarify that the diff_marker is talking about version control systemardi-1/+1
conflicts specifically and a few more improvements.
2024-05-14Remove `NtIdent` and `NtLifetime`.Nicholas Nethercote-1/+3
The extra span is now recorded in the new `TokenKind::NtIdent` and `TokenKind::NtLifetime`. These both consist of a single token, and so there's no operator precedence problems with inserting them directly into the token stream. The other way to do this would be to wrap the ident/lifetime in invisible delimiters, but there's a lot of code that assumes an interpolated ident/lifetime fits in a single token, and changing all that code to work with invisible delimiters would have been a pain. (Maybe it could be done in a follow-up.) This change might not seem like much of a win, but it's a first step toward the much bigger and long-desired removal of `Nonterminal` and `TokenKind::Interpolated`. That change is big and complex enough that it's worth doing this piece separately. (Indeed, this commit is based on part of a late commit in #114647, a prior attempt at that big and complex change.)
2024-05-13Remove a `Span` from `TokenKind::Interpolated`.Nicholas Nethercote-1/+1
This span records the declaration of the metavariable in the LHS of the macro. It's used in a couple of error messages. Unfortunately, it gets in the way of the long-term goal of removing `TokenKind::Interpolated`. So this commit removes it, which degrades a couple of (obscure) error messages but makes things simpler and enables the next commit.
2024-05-11Add classify::expr_is_completeDavid Tolnay-59/+3
2024-05-11Remove MacCall special case from recovery after missing 'if' after 'else'David Tolnay-6/+28
The change to the test is a little goofy because the compiler was guessing "correctly" before that `falsy! {}` is the condition as opposed to the else body. But I believe this change is fundamentally correct. Braced macro invocations in statement position are most often item-like (`thread_local! {...}`) as opposed to parenthesized macro invocations which are condition-like (`cfg!(...)`).
2024-05-11Document MacCall special case in Parser::parse_armDavid Tolnay-0/+11
2024-05-11Document MacCall special case in Parser::expr_is_completeDavid Tolnay-7/+44
2024-05-11Mark Parser::expr_is_complete call sitesDavid Tolnay-5/+7
2024-05-11Macro call with braces does not require semicolon to be statementDavid Tolnay-4/+12
This commit by itself is supposed to have no effect on behavior. All of the call sites are updated to preserve their previous behavior. The behavior changes are in the commits that follow.
2024-05-11Mark expr_requires_semi_to_be_stmt call sitesDavid Tolnay-3/+3
For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization.
2024-05-09Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.Nicholas Nethercote-18/+22
The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error.
2024-04-23Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwcoMatthias Krüger-13/+19
Disallow ambiguous attributes on expressions This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
2024-04-22Improve handling of expr->field errorsSasha Pourcelot-0/+6
The current message for "`->` used for field access" is the following: ```rust error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->` --> src/main.rs:2:6 | 2 | a->b; | ^^ expected one of 8 possible tokens ``` (playground link[1]) This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is: ``` error: `->` used for field access or method call --> ./tiny_test.rs:2:6 | 2 | a->b; | ^^ help: try using `.` instead | = help: the `.` operator will dereference the value if needed ``` (feel free to bikeshed it as much as necessary) [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-18Disallow ambiguous attributes on expressionsDominik Stolz-13/+19
2024-04-11remove some things that do not need to beMatthias Krüger-2/+1
2024-04-02Don't ICE for postfix match after asMichael Goulet-0/+1
2024-03-27chore: fix some commentsxiaoxiangxianzi-1/+1
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-25Clarify `parse_dot_suffix_expr`.Nicholas Nethercote-16/+19
For the `MiddleDot` case, current behaviour: - For a case like `1.2`, `sym1` is `1` and `sym2` is `2`, and `self.token` holds `1.2`. - It creates a new ident token from `sym1` that it puts into `self.token`. - Then it does `bump_with` with a new dot token, which moves the `sym1` token into `prev_token`. - Then it does `bump_with` with a new ident token from `sym2`, which moves the `dot` token into `prev_token` and discards the `sym1` token. - Then it does `bump`, which puts whatever is next into `self.token`, moves the `sym2` token into `prev_token`, and discards the `dot` token altogether. New behaviour: - Skips creating and inserting the `sym1` and dot tokens, because they are unnecessary. - This also demonstrates that the comment about `Spacing::Alone` is wrong -- that value is never used. That comment was added in #77250, and AFAICT it has always been incorrect. The commit also expands comments. I found this code hard to read previously, the examples in comments make it easier.
2024-03-25Change `parse_expr_tuple_field_access`.Nicholas Nethercote-10/+15
Pass in the span for the field rather than using `prev_token`. Also rename it `mk_expr_tuple_field_access`, because it doesn't do any actual parsing, it just creates an expression with what it's given. Not much of a clarity win by itself, but unlocks additional subsequent simplifications.
2024-03-25Remove `next_token` handling from `parse_expr_tuple_field_access`.Nicholas Nethercote-18/+10
It's clearer at the call site.
2024-03-25Inline and remove `Parser::parse_expr_tuple_field_access_float`.Nicholas Nethercote-36/+38
It has a single call site, and afterwards all the calls to `parse_expr_tuple_field_access` are in a single method, which is nice.
2024-03-22Rollup merge of #121619 - RossSmyth:pfix_match, r=petrochenkovMatthias Krüger-5/+24
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, #121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
2024-03-21Rollup merge of #122752 - nnethercote:Interpolated-cleanups, r=petrochenkovMatthias Krüger-10/+0
Interpolated cleanups Various cleanups I made while working on attempts to remove `Interpolated`, that are worth merging now. Best reviewed one commit at a time. r? `@petrochenkov`
2024-03-20Make type_ascribe! not a built-inMichael Goulet-5/+15
2024-03-21Remove non-useful code path.Nicholas Nethercote-10/+0
It has no effect on anything in the test suite.
2024-03-18Ensure stack before parsing dot-or-callJubilee Young-1/+4
There are many cases where, due to codegen or a massively unruly codebase, a deeply nested call(call(call(call(call(call(call(call(call(f()))))))))) can happen. This is a spot where it would be good to grow our stack, so that we can survive to tell the programmer their code is dubiously written.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-3/+3
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-06Add MatchKind member to the Match expr for pretty printing & fmtRoss Smyth-8/+10
2024-03-05Add postfix-match experimental featureRoss Smyth-1/+18
Co-authored-by: Josh Stone <jistone@redhat.com>
2024-03-05Use `ControlFlow` in AST visitors.Jason Newcomb-7/+9
2024-03-05Rename `BuiltinLintDiagnostics` as `BuiltinLintDiag`.Nicholas Nethercote-2/+2
Not the dropping of the trailing `s` -- this type describes a single diagnostic and its name should be singular.
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-30/+30
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2024-03-02Auto merge of #121657 - estebank:issue-119665, r=davidtwcobors-2/+2
Detect more cases of `=` to `:` typo When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`. ``` error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.` --> file.rs:2:32 | 2 | let _: std::env::temp_dir().join("foo"); | - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` | | | while parsing the type for `_` | help: use `=` if you meant to assign ``` Fix #119665.
2024-03-01Detect more cases of `=` to `:` typoEsteban Küber-2/+2
When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`. ``` error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.` --> file.rs:2:32 | 2 | let _: std::env::temp_dir().join("foo"); | - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` | | | while parsing the type for `_` | help: use `=` if you meant to assign ``` Fix #119665.
2024-02-29Overhaul how stashed diagnostics work, again.Nicholas Nethercote-14/+15
Stashed errors used to be counted as errors, but could then be cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed that, closing the soundness hole. But it introduced other difficulties because you sometimes have to account for pending stashed errors when making decisions about whether errors have occured/will occur and it's easy to overlook these. This commit aims for a middle ground. - Stashed errors (not warnings) are counted immediately as emitted errors, avoiding the possibility of forgetting to consider them. - The ability to cancel (or downgrade) stashed errors is eliminated, by disallowing the use of `steal_diagnostic` with errors, and introducing the more restrictive methods `try_steal_{modify,replace}_and_emit_err` that can be used instead. Other things: - `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both return `Option<ErrorGuaranteed>`, which enables the removal of two `delayed_bug` calls and one `Ty::new_error_with_message` call. This is possible because we store error guarantees in `DiagCtxt::stashed_diagnostics`. - Storing the guarantees also saves us having to maintain a counter. - Calls to the `stashed_err_count` method are no longer necessary alongside calls to `has_errors`, which is a nice simplification, and eliminates two more `span_delayed_bug` calls and one FIXME comment. - Tests are added for three of the four fixed PRs mentioned below. - `issue-121108.rs`'s output improved slightly, omitting a non-useful error message. Fixes #121451. Fixes #121477. Fixes #121504. Fixes #121508.
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-4/+4
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Refactor `take_for_recovery` call sites.Nicholas Nethercote-16/+13
To make them more concise and similar to each other.
2024-02-25Add `ErrorGuaranteed` to `ast::ExprKind::Err`Lieselotte-71/+94
2024-02-25Add `ast::ExprKind::Dummy`Lieselotte-1/+2
2024-02-25Rollup merge of #121060 - clubby789:bool-newtypes, r=cjgillotMatthias Krüger-23/+27
Add newtypes for bool fields/params/return types Fixed all the cases of this found with some simple searches for `*/ bool` and `bool /*`; probably many more
2024-02-20Add newtype for trailing in parserclubby789-2/+2
2024-02-20Add newtype for parser recoveryclubby789-4/+4