about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2024-07-05Remove some unnecessary integer conversions.Nicholas Nethercote-5/+3
These should have been removed in #127233 when the positions were changed from `usize` to `u32`.
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-29/+6
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-07-02Import `std::{iter,mem}`.Nicholas Nethercote-11/+10
2024-07-02Rename `make_token_stream`.Nicholas Nethercote-6/+6
And update the comment. Clearly the return type of this function was changed at some point in the past, but its name and comment weren't updated to match.
2024-07-02Shrink parser positions from `usize` to `u32`.Nicholas Nethercote-15/+12
The number of source code bytes can't exceed a `u32`'s range, so a token position also can't. This reduces the size of `Parser` and `LazyAttrTokenStreamImpl` by eight bytes each.
2024-07-02Move more things around in `collect_tokens_trailing_token`.Nicholas Nethercote-23/+18
To make things a little clearer, and to avoid some `mut` variables.
2024-07-02Move things around in `collect_tokens_trailing_token`.Nicholas Nethercote-7/+7
So that the `capturing` state is adjusted immediately before and after the call to `f`.
2024-07-02Flip an if/else in `AttrTokenStream::to_attr_token_stream`.Nicholas Nethercote-3/+3
To put the simple case first.
2024-07-02Fix comment.Nicholas Nethercote-3/+3
Both the indenting, and the missing `)`.
2024-07-02Fix a typo in a comment.Nicholas Nethercote-1/+1
2024-06-29Rollup merge of #127103 - compiler-errors:tighten-trait-bound-parsing, r=fmeaseMatthias Krüger-40/+62
Move binder and polarity parsing into `parse_generic_ty_bound` Let's pull out the parts of #127054 which just: 1. Make the parsing code less confusing 2. Fix `?use<>` (to correctly be denied) 3. Improve `T: for<'a> 'a` diagnostics This should have no user-facing effects on stable parsing. r? fmease
2024-06-28Move binder and polarity parsing into parse_generic_ty_boundMichael Goulet-40/+62
2024-06-28Change RTN to use .. againMichael Goulet-29/+6
2024-06-27Tighten spans for async blocksMichael Goulet-2/+3
2024-06-27Rollup merge of #126571 - nnethercote:less-maybe_whole-expr-2, r=petrochenkovJacob Pratt-32/+41
Less `maybe_whole_expr`, take 2 I first tried this in #107550. I now think it's worth doing again, as a precursor to #124141. r? ```@petrochenkov```
2024-06-26Fix a span in `parse_ty_bare_fn`.Nicholas Nethercote-1/+1
It currently goes one token too far. Example: line 259 of `tests/ui/abi/compatibility.rs`: ``` test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32); ``` This commit changes the span for the second element from `fn(),` to `fn()`, i.e. removes the extraneous comma.
2024-06-25Inline and remove `maybe_whole_expr!`.Nicholas Nethercote-32/+41
And remove the `NtPath` and `NtBlock` cases in `parse_literal_maybe_minus`, because they are unnecessary.
2024-06-24Rollup merge of #126682 - Zalathar:coverage-attr, r=lcnrMichael Goulet-3/+10
coverage: Overhaul validation of the `#[coverage(..)]` attribute This PR makes sweeping changes to how the (currently-unstable) coverage attribute is validated: - Multiple coverage attributes on the same item/expression are now treated as an error. - The attribute must always be `#[coverage(off)]` or `#[coverage(on)]`, and the error messages for this are more consistent. - A trailing comma is still allowed after off/on, since that's part of the normal attribute syntax. - Some places that silently ignored a coverage attribute now produce an error instead. - These cases were all clearly bugs. - Some places that ignored a coverage attribute (with a warning) now produce an error instead. - These were originally added as lints, but I don't think it makes much sense to knowingly allow new attributes to be used in meaningless places. - Some of these errors might soon disappear, if it's easy to extend recursive coverage attributes to things like modules and impl blocks. --- One of the goals of this PR is to lay a more solid foundation for making the coverage attribute recursive, so that it applies to all nested functions/closures instead of just the one it is directly attached to. Fixes #126658. This PR incorporates #126659, which adds more tests for validation of the coverage attribute. `@rustbot` label +A-code-coverage
2024-06-24Rollup merge of #126882 - estebank:multiline-order, r=WaffleLapkinMatthias Krüger-10/+7
Special case when a code line only has multiline span starts Minimize multline span overlap when there are multiple of them starting on the same line: ``` 3 | X0 Y0 Z0 | _____^ - - | | _______| | | || _________| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter ```
2024-06-24coverage: Tighten validation of `#[coverage(off)]` and `#[coverage(on)]`Zalathar-3/+10
2024-06-24Rollup merge of #126177 - carbotaniuman:unsafe_attr_errors, r=jieyouxuMatthias Krüger-6/+89
Add hard error and migration lint for unsafe attrs More implementation work for https://github.com/rust-lang/rust/issues/123757 This adds the migration lint for unsafe attributes, as well as making it a hard error in Rust 2024.
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-6/+89
2024-06-23Special case when a code line only has multiline span startsEsteban Küber-10/+7
``` 3 | X0 Y0 Z0 | _____^ - - | | _______| | | || _________| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter ```
2024-06-23Rework pattern and expression nonterminal kinds.Nicholas Nethercote-16/+12
Merge `PatParam`/`PatWithOr`, and `Expr`/`Expr2021`, for a few reasons. - It's conceptually nice, because the two pattern kinds and the two expression kinds are very similar. - With expressions in particular, there are several places where both expression kinds get the same treatment. - It removes one unreachable match arm. - Most importantly, for #124141 I will need to introduce a new type `MetaVarKind` that is very similar to `NonterminalKind`, but records a couple of extra fields for expression metavars. It's nicer to have a single `MetaVarKind::Expr` expression variant to hold those extra fields instead of duplicating them across two variants `MetaVarKind::{Expr,Expr2021}`. And then it makes sense for patterns to be treated the same way, and for `NonterminalKind` to also be treated the same way. I also clarified the comments, because I have long found them a little hard to understand.
2024-06-21Rollup merge of #126767 - compiler-errors:static-foreign-item, r=spastorinoMatthias Krüger-1/+1
`StaticForeignItem` and `StaticItem` are the same The struct `StaticItem` and `StaticForeignItem` are the same, so remove `StaticForeignItem`. Having them be separate is unique to `static` items -- unlike `ForeignItemKind::{Fn,TyAlias}`, which use the normal AST item. r? ``@spastorino`` or ``@oli-obk``
2024-06-21Rollup merge of #126700 - compiler-errors:fragment, r=fmeaseMatthias Krüger-3/+2
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo``` cc #123865 Tracking: - https://github.com/rust-lang/rust/issues/123742
2024-06-21Rollup merge of #126125 - dev-ardi:conflict-markers, r=estebankMatthias Krüger-16/+42
Improve conflict marker recovery <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> closes #113826 r? ```@estebank``` since you reviewed #115413 cc: ```@rben01``` since you opened up the issue in the first place
2024-06-21Auto merge of #126757 - compiler-errors:safe, r=spastorinobors-0/+3
Properly gate `safe` keyword in pre-expansion This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of https://github.com/rust-lang/rust/issues/126755, which is that `safe` is now usable on beta lol. r? `@spastorino` or `@oli-obk` cc #124482 tracking #123743
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/+106
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/+17
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