about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2024-06-20StaticForeignItem and StaticItem are the sameMichael Goulet-1/+1
2024-06-20Properly gate `safe` keyword in pre-expansionMichael Goulet-0/+3
2024-06-20Rollup merge of #126717 - nnethercote:rustfmt-use-pre-cleanups, r=jieyouxuMatthias Krüger-0/+1
Clean up some comments near `use` declarations #125443 will reformat all `use` declarations in the repository. There are a few edge cases involving comments on `use` declarations that require care. This PR cleans up some clumsy comment cases, taking us a step closer to #125443 being able to merge. r? ``@lqd``
2024-06-20Add blank lines after module-level `//` comments.Nicholas Nethercote-0/+1
Similar to the previous commit.
2024-06-20Introduce `can_begin_string_literal`.Nicholas Nethercote-2/+2
We currently use `can_begin_literal_maybe_minus` in a couple of places where only string literals are allowed. This commit introduces a more specific function, which makes things clearer. It doesn't change behaviour because the two functions affected (`is_unsafe_foreign_mod` and `check_keyword_case`) are always followed by a call to `parse_abi`, which checks again for a string literal.
2024-06-20Inline `can_begin_literal_maybe_minus` call into two places.Nicholas Nethercote-1/+2
It's clearer this way, because the `Interpolated` cases in `can_begin_const_arg` and `is_pat_range_end_start` are more permissive than the `Interpolated` cases in `can_begin_literal_maybe_minus`.
2024-06-19Allow naming expr_2021 in all editionsMichael Goulet-3/+2
2024-06-19Auto merge of #126678 - nnethercote:fix-duplicated-attrs-on-nt-expr, ↵bors-111/+108
r=petrochenkov Fix duplicated attributes on nonterminal expressions This PR fixes a long-standing bug (#86055) whereby expression attributes can be duplicated when expanded through declarative macros. First, consider how items are parsed in declarative macros: ``` Items: - parse_nonterminal - parse_item(ForceCollect::Yes) - parse_item_ - attrs = parse_outer_attributes - parse_item_common(attrs) - maybe_whole! - collect_tokens_trailing_token ``` The important thing is that the parsing of outer attributes is outside token collection, so the item's tokens don't include the attributes. This is how it's supposed to be. Now consider how expression are parsed in declarative macros: ``` Exprs: - parse_nonterminal - parse_expr_force_collect - collect_tokens_no_attrs - collect_tokens_trailing_token - parse_expr - parse_expr_res(None) - parse_expr_assoc_with - parse_expr_prefix - parse_or_use_outer_attributes - parse_expr_dot_or_call ``` The important thing is that the parsing of outer attributes is inside token collection, so the the expr's tokens do include the attributes, i.e. in `AttributesData::tokens`. This PR fixes the bug by rearranging expression parsing to that outer attribute parsing happens outside of token collection. This requires a number of small refactorings because expression parsing is somewhat complicated. While doing so the PR makes the code a bit cleaner and simpler, by eliminating `parse_or_use_outer_attributes` and `Option<AttrWrapper>` arguments (in favour of the simpler `parse_outer_attributes` and `AttrWrapper` arguments), and simplifying `LhsExpr`. r? `@petrochenkov`
2024-06-19Change how `parse_expr_force_collect` works.Nicholas Nethercote-2/+5
It now parses outer attributes before collecting tokens. This avoids the problem where the outer attribute tokens were being stored twice -- for the attribute tokesn, and also for the expression tokens. Fixes #86055.
2024-06-19Refactor `parse_expr_res`.Nicholas Nethercote-28/+33
This removes the final `Option<AttrWrapper>` argument.
2024-06-19Simplify `LhsExpr::Unparsed`.Nicholas Nethercote-10/+11
By making the `AttrWrapper` non-optional.
2024-06-19Move `parse_or_use_outer_attributes` out of `parse_expr_prefix_range`.Nicholas Nethercote-9/+19
This eliminates another `Option<AttrWrapper>` argument and changes one obscure error message.
2024-06-19Move `parse_or_use_outer_attributes` out of `parse_expr_prefix`.Nicholas Nethercote-5/+8
This eliminates one `Option<AttrWrapper>` argument.
2024-06-19Inline and remove `parse_expr_assoc`.Nicholas Nethercote-10/+1
It has a single call site.
2024-06-19Refactor `LhsExpr`.Nicholas Nethercote-42/+38
Combine `NotYetParsed` and `AttributesParsed` into a single variant, because (a) that reflects the structure of the code that consumes `LhsExpr`, and (b) because that variant will have the `Option` removed in a later commit.
2024-06-19Remove `From` impls for `LhsExpr`.Nicholas Nethercote-25/+10
The `Option<AttrWrapper>` one maps to the first two variants, and the `P<Expr>` one maps to the third. Weird. The code is shorter and clearer without them.
2024-06-19Simplify `Parser::parse_expr_dot_or_call`.Nicholas Nethercote-4/+3
The call in `parse_expr_prefix` for the `++` case passes an empty `attrs`, but it doesn' need to. This commit changes it to pass the parsed `attrs`, which doesn't change any behaviour. As a result, `parse_expr_dot_or_call` no longer needs an `Option` argument, and no longer needs to call `parse_or_use_outer_attributes`.
2024-06-19Expand another comment.Nicholas Nethercote-1/+5
2024-06-19Rollup merge of #124135 - petrochenkov:deleglob, r=fmease许杰友 Jieyou Xu (Joe)-6/+21
delegation: Implement glob delegation Support delegating to all trait methods in one go. Overriding globs with explicit definitions is also supported. The implementation is generally based on the design from https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2020869823, but unlike with list delegation in https://github.com/rust-lang/rust/pull/123413 we cannot expand glob delegation eagerly. We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob. Glob delegation is only allowed in impls, and can only point to traits. Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity. Part of https://github.com/rust-lang/rust/issues/118212.
2024-06-19make this comment correctardi-3/+4
2024-06-19Improve conflict marker recoveryardi-13/+38
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-12/+9
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-12/+12
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18Prefer `dcx` methods over fields or fields' methodsOli Scherer-19/+18
2024-06-17Rework precise capturing syntaxMichael Goulet-17/+14
2024-06-17Make parse_seq_to_before_tokens take expected/nonexpected tokens, use in ↵Michael Goulet-35/+31
parse_precise_capturing_syntax
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-6/+21
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-0/+2
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-07Rollup merge of #126052 - nnethercote:rustc_parse-more-cleanups, r=spastorinoMatthias Krüger-72/+67
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/+33
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/+33
2024-06-06Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, ↵Rémy Rakic-30/+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-06Inline and remove `check_builtin_attribute`.Nicholas Nethercote-19/+11
It's small and has a single call site. Also change the second `parse_meta` call to use a simple `match`, like the first `parse_meta` call, instead of a confusing `map_err`+`ok` combination.
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-42/+51
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-29/+47
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-05Inline and remove `source_file_to_stream`.Nicholas Nethercote-9/+1
It has a single call site.
2024-06-05Reorder `source_str_to_stream` arguments.Nicholas Nethercote-4/+4
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-30/+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-05Rename `maybe_source_file_to_parser` as `maybe_new_parser_from_source_file`.Nicholas Nethercote-3/+3
For consistency with `new_parser_from_{file,source_str}` and `maybe_new_parser_from_source_str`.
2024-06-05Remove low-value comments.Nicholas Nethercote-7/+0
The first one is out-of-date -- there are no longer functions expr, item, stmt. And I don't know what a "HOF" is. The second one doesn't really tell you anything.
2024-06-05Improve `panictry_buffer!`.Nicholas Nethercote-15/+12
- Convert it from a macro to a function, which is nicer. - Rename it as `unwrap_or_emit_fatal`, which is clearer. - Fix the comment. In particular, `panictry!` no longer exists. - Remove the unnecessary `use` declaration.
2024-06-05Remove `stream_to_parser`.Nicholas Nethercote-11/+3
It's a zero-value wrapper of `Parser::new`.
2024-06-05Rename `maybe_file_to_stream` as `maybe_source_file_to_stream`.Nicholas Nethercote-3/+3
Because it takes an `Lrc<SourceFile>`, and for consistency with `source_file_to_stream`.
2024-06-05Inline and remove `error_malformed_cfg_attr_missing`.Nicholas Nethercote-10/+10
It has a single call site. This also means `CFG_ATTR_{GRAMMAR_HELP,NOTE_REF}` can be moved into `parse_cfg_attr`, now that it's the only function that uses them. And the commit removes the line break in the URL.