about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
2024-06-07Rollup merge of #126052 - nnethercote:rustc_parse-more-cleanups, r=spastorinoMatthias Krüger-51/+54
More `rustc_parse` cleanups Following on from #125815. r? `@spastorino`
2024-06-07Rollup merge of #124214 - carbotaniuman:parse_unsafe_attrs, r=michaelwoeristerMatthias Krüger-3/+32
Parse unsafe attributes Initial parse implementation for #123757 This is the initial work to parse unsafe attributes, which is represented as an extra `unsafety` field in `MetaItem` and `AttrItem`. There's two areas in the code where it appears that parsing is done manually and not using the parser stuff, and I'm not sure how I'm supposed to thread the change there.
2024-06-07Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errorsbors-5/+8
Revert: create const block bodies in typeck via query feeding as per the discussion in https://github.com/rust-lang/rust/pull/125806#discussion_r1622563948 It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile. reverts the const-block-specific parts of https://github.com/rust-lang/rust/pull/124650 `@bors` rollup=never had a small perf impact previously fixes https://github.com/rust-lang/rust/issues/125846 r? `@compiler-errors`
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-5/+8
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-06Fix buildcarbotaniuman-4/+4
2024-06-06Parse unsafe attributescarbotaniuman-3/+32
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-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-7/+34
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-06Specialize `assert_pred`.Nicholas Nethercote-12/+6
It has only two uses, and both use `matches_codepattern`. So just change it to `assert_matches_codepattern`.
2024-06-06Reduce `pub` exposure.Nicholas Nethercote-39/+48
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-5/+17
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
2024-06-05Reorder `source_str_to_stream` arguments.Nicholas Nethercote-1/+1
It's the only one of these functions where `psess` isn't the first argument.
2024-06-05Inline and remove `parse_crate{,_attrs}_from_{file,source_str}`.Nicholas Nethercote-1/+1
All four functions are simple and have a single call site. This requires making `Parser::parse_inner_attributes` public, which is no big deal.
2024-06-05Use `source_str_to_stream` in a test file.Nicholas Nethercote-6/+2
It does exactly what is required.
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-5/+13
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-2/+21
2024-06-02Avoid checking the edition as much as possibleVincenzo Palazzo-1/+1
Inside #123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. We realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. Link: https://github.com/rust-lang/rust/pull/123865 Co-Developed-by: @eholk Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-06-01Auto merge of #125863 - fmease:rej-CVarArgs-in-parse_ty_for_where_clause, ↵bors-2/+3
r=compiler-errors Reject `CVarArgs` in `parse_ty_for_where_clause` Fixes #125847. This regressed in #77035 where the `parse_ty` inside `parse_ty_where_predicate` was replaced with the at the time new `parse_ty_for_where_clause` which incorrectly stated it would permit CVarArgs (maybe a copy/paste error). r? parser
2024-06-01Reject CVarArgs in parse_ty_for_where_clauseLeón Orell Valerian Liehr-2/+3
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-18/+15
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-18/+15
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-8/+5
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_parse`.Nicholas Nethercote-0/+3
2024-05-22Rollup merge of #125049 - dtolnay:castbrace, r=compiler-errorsLeón Orell Valerian Liehr-11/+17
Disallow cast with trailing braced macro in let-else This fixes an edge case I noticed while porting #118880 and #119062 to syn. Previously, rustc incorrectly accepted code such as: ```rust let foo = &std::ptr::null as &'static dyn std::ops::Fn() -> *const primitive! { 8 } else { return; }; ``` even though a right curl brace `}` directly before `else` in a `let...else` statement is not supposed to be valid syntax.
2024-05-21Auto merge of #124417 - Xiretza:translate-early-lints, r=fmeasebors-2/+1
Make early lints translatable <del>Requires https://github.com/projectfluent/fluent-rs/pull/353.</del> https://github.com/rust-lang/rust/commit/5134a04eaa32b168cf5998a6ec13199356e2e017 r? diagnostics
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-20Fix parsing of erroneously placed semicolonsardi-3/+9
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-30/+30
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18Rollup merge of #125117 - dev-ardi:improve-parser, r=wesleywiser,fmeaseMatthias Krüger-66/+72
Improve parser Fixes #124935. - Add a few more help diagnostics to incorrect semicolons - Overall improved that function - Addded a few comments - Renamed diff_marker fns to git_diff_marker
2024-05-17Auto merge of #123865 - eholk:expr_2021, r=fmeasebors-2/+10
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks. Joint work with `@vincenzopalazzo.` Issue #123742
2024-05-17Rename Unsafe to SafetySantiago Pastorino-30/+30
2024-05-17Update compiler/rustc_parse/src/parser/nonterminal.rsEric Holk-2/+1
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-05-17use signature name for argardi-2/+2
2024-05-17s/(Ident, ItemKind)/ItemInfo/ardi-2/+2
2024-05-17Clarify that the diff_marker is talking about version control systemardi-37/+46
conflicts specifically and a few more improvements.
2024-05-15delegation: Implement list delegationVadim Petrochenkov-10/+28
```rust reuse prefix::{a, b, c} ```
2024-05-14improve maybe_consume_incorrect_semicolonardi-25/+22
2024-05-13Warn against redundant use<...>Michael Goulet-28/+30
2024-05-14Remove `NtIdent` and `NtLifetime`.Nicholas Nethercote-27/+36
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-13Macros: match const { ... } with expr nonterminal in edition 2024Vincenzo Palazzo-1/+8
Co-authored-by: Eric Holk <eric@theincredibleholk.org> Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-13Add expr_2021 nonterminal and feature flagEric Holk-2/+4
This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. For now, `expr` and `expr_2021` are treated the same, but in future PRs we will update `expr` to match to new grammar. Co-authored-by: Vincezo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-12Disallow cast with trailing braced macro in let-elseDavid Tolnay-11/+17
2024-05-13Remove a `Span` from `TokenKind::Interpolated`.Nicholas Nethercote-50/+29
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 cases from Parser::parse_full_stmtDavid Tolnay-9/+3
It is impossible for expr here to be a braced macro call. Expr comes from `parse_stmt_without_recovery`, in which macro calls are parsed by `parse_stmt_mac`. See this part: let kind = if (style == MacStmtStyle::Braces && self.token != token::Dot && self.token != token::Question) || self.token == token::Semi || self.token == token::Eof { StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) } else { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.maybe_recover_from_bad_qpath(e)?; let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; let e = self.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr: e, starts_statement: false }, )?; StmtKind::Expr(e) }; A braced macro call at the head of a statement is always either extended into ExprKind::Field / MethodCall / Await / Try / Binary, or else returned as StmtKind::MacCall. We can never get a StmtKind::Expr containing ExprKind::MacCall containing brace delimiter.
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