about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2025-08-31Auto merge of #145582 - estebank:issue-107806, r=chenyukangbors-0/+97
Detect missing `if let` or `let-else` During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`: ``` error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{` --> $DIR/missing-if-let-or-let-else.rs:14:25 | LL | let Some(x) = foo() { | ^ expected one of `.`, `;`, `?`, `else`, or an operator | help: you might have meant to use `if let` | LL | if let Some(x) = foo() { | ++ help: alternatively, you might have meant to use `let else` | LL | let Some(x) = foo() else { | ++++ ``` Fix rust-lang/rust#107806.
2025-08-30review comment: move `Visitor`Esteban Küber-27/+29
2025-08-28Improve error messages around invalid literals in attribute argumentsJonathan Brouwer-2/+2
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-25Remove the lifetime from `ExpTokenPair`/`SeqSep`.Nicholas Nethercote-49/+49
`TokenKind` now impls `Copy`, so we can store it directly rather than a reference.
2025-08-22Rollup merge of #145747 - joshtriplett:builtin-diag-dyn, r=jdonszelmannJacob Pratt-10/+84
Refactor lint buffering to avoid requiring a giant enum Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case. --- With the infrastructure in place, use it to migrate three of the enum variants to use `LintDiagnostic` directly, as a proof of concept and to demonstrate that the net result is a reduction in code size and a removal of a boilerplate-heavy layer of indirection. Also remove an unused `BuiltinLintDiag` variant.
2025-08-22Rollup merge of #144897 - fee1-dead-contrib:raw_lifetimes_printing, r=fmeaseJacob Pratt-6/+4
print raw lifetime idents with r# This replaces rust-lang/rust#143185 and fixes rust-lang/rust#143150 cc ``@fmease``
2025-08-22Rollup merge of #137396 - compiler-errors:param-default, r=fmeaseJacob Pratt-2/+25
Recover `param: Ty = EXPR` Fixes #137310 Pretty basic recovery here, but better than giving an unexpected token error.
2025-08-22Recover param: Ty = EXPRMichael Goulet-2/+25
2025-08-22Migrate `BuiltinLintDiag::HiddenUnicodeCodepoints` to use `LintDiagnostic` ↵Josh Triplett-10/+84
directly
2025-08-22Rewrite the new attribute parserJonathan Brouwer-11/+12
2025-08-22Move validate_attr to `rustc_attr_parsing`Jonathan Brouwer-395/+15
2025-08-22address review commentsDeadbeef-12/+4
2025-08-22don't print invalid labels with `r#`Deadbeef-2/+8
2025-08-21Rollup merge of #145604 - compiler-errors:static-closure, r=fmeaseJacob Pratt-2/+6
Gate static closures behind a parser feature I'd like to gate `static ||` closures behind a feature gate, since we shouldn't allow people to take advantage of this syntax if it's currently unstable. Right now, since it's only rejected after ast lowering, it's accessible to macros. Let's crater this to see if we can claw it back without breaking anyone's code.
2025-08-21Rollup merge of #145590 - nnethercote:ModKind-Inline, r=petrochenkovJacob Pratt-1/+1
Prevent impossible combinations in `ast::ModKind`. `ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`. r? ```@Urgau```
2025-08-20Detect missing `if let` or `let-else`Esteban Küber-0/+95
During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`: ``` error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{` --> $DIR/missing-if-let-or-let-else.rs:14:25 | LL | let Some(x) = foo() { | ^ expected one of `.`, `;`, `?`, `else`, or an operator | help: you might have meant to use `if let` | LL | if let Some(x) = foo() { | ++ help: alternatively, you might have meant to use `let else` | LL | let Some(x) = foo() else { | ++++ ```
2025-08-20Auto merge of #145348 - nnethercote:parse_token_tree-speedup-for-uom, ↵bors-6/+17
r=petrochenkov Sometimes skip over tokens in `parse_token_tree`. r? `@petrochenkov`
2025-08-19Auto merge of #145601 - jieyouxu:rollup-t5mbqhc, r=jieyouxubors-4/+15
Rollup of 10 pull requests Successful merges: - rust-lang/rust#145538 (bufreader::Buffer::backshift: don't move the uninit bytes) - rust-lang/rust#145542 (triagebot: Don't warn no-mentions on subtree updates) - rust-lang/rust#145549 (Update rust maintainers in openharmony.md) - rust-lang/rust#145550 (Avoid using `()` in `derive(From)` output.) - rust-lang/rust#145556 (Allow stability attributes on extern crates) - rust-lang/rust#145560 (Remove unused `PartialOrd`/`Ord` from bootstrap) - rust-lang/rust#145568 (ignore frontmatters in `TokenStream::new`) - rust-lang/rust#145571 (remove myself from some adhoc-groups and pings) - rust-lang/rust#145576 (Add change tracker entry for `--timings`) - rust-lang/rust#145578 (Add VEXos "linked files" support to `armv7a-vex-v5`) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-19Gate static coroutines behind a parser featureMichael Goulet-2/+6
2025-08-19Prevent impossible combinations in `ast::ModKind`.Nicholas Nethercote-1/+1
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-19Rollup merge of #145474 - fmease:paren-use-bounds-fix, r=fee1-dead许杰友 Jieyou Xu (Joe)-94/+89
Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups Fixes https://github.com/rust-lang/rust/issues/145470. First commit fixes the issue, second one performs some desperately needed cleanups. The fix shouldn't be a breaking change because IINM the parser always ensures that all brackets are balanced (via a buffer of brackets). Meaning even though we used to accept `(use<>` as a valid precise capturing list, it was guaranteed that we would fail in the end.
2025-08-18ignore frontmatters in `TokenStream::new`Deadbeef-4/+15
2025-08-16Clean up parsers related to generic boundsLeón Orell Valerian Liehr-94/+79
2025-08-16Properly recover from parenthesized use-bounds (precise capturing)León Orell Valerian Liehr-16/+26
2025-08-15Rollup merge of #145378 - xizheyin:144968, r=davidtwcoStuart Cook-34/+94
Add `FnContext` in parser for diagnostic Fixes rust-lang/rust#144968 Inspired by https://github.com/rust-lang/rust/issues/144968#issuecomment-3156094581, I implemented `FnContext` to indicate whether a function should have a self parameter, for example, whether the function is a trait method, whether it is in an impl block. And I removed the outdated note. I made two commits to show the difference. cc ``@estebank`` ``@djc`` r? compiler
2025-08-14Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxuJakub Beránek-11/+19
cfg_select: Support unbraced expressions Tracking issue for `cfg_select`: rust-lang/rust#115585 When operating on expressions, `cfg_select!` can now handle expressions without braces. (It still requires braces for other things, such as items.) Expand the test coverage and documentation accordingly. --- I'm not sure whether deciding to extend `cfg_select!` in this way is T-lang or T-libs-api. I've labeled for both, with the request that both teams don't block on each other. :)
2025-08-14Rollup merge of #137872 - estebank:extra-vert, r=compiler-errorsJakub Beránek-10/+25
Include whitespace in "remove |" suggestion and make it hidden Tweak error rendering of patterns with an extra `|` on either end. Built on #137409. Only last commit is relevant. ? ``@compiler-errors``
2025-08-14Add FnContext in parser for diagnosticxizheyin-34/+94
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-14Sometimes skip over tokens in `parse_token_tree`.Nicholas Nethercote-6/+17
This sometimes avoids a lot of `bump` calls.
2025-08-12Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmannStuart Cook-17/+24
Tweak invalid builtin attribute output - Add link to reference/docs when possible - More accurate suggestions by supporting multiple alternative suggestions ``` error: malformed `crate_type` attribute input --> $DIR/crate-type-macro-call.rs:1:1 | LL | #![crate_type = foo!()] | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> help: the following are the possible correct uses | LL - #![crate_type = foo!()] LL + #![crate_type = "bin"] | LL - #![crate_type = foo!()] LL + #![crate_type = "cdylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "dylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "lib"] | = and 4 other candidates ```
2025-08-11Extract ast TraitImplHeaderCameron Steffen-14/+13
2025-08-11Tweak trait modifier errorsCameron Steffen-24/+15
2025-08-11Move trait impl modifier errors to parsingCameron Steffen-1/+49
This is a technically a breaking change for what can be parsed in `#[cfg(false)]`.
2025-08-11Add link to docs on malformed attributesEsteban Küber-15/+18
2025-08-11Allow attr entries to declare list of alternatives for `List` and ↵Esteban Küber-2/+6
`NamedValueStr` Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles. Suggestions now provide more correct suggested code: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler)] | LL - #[used(compiler, linker)] LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler|linker)] | LL - #[used(compiler, linker)] LL + #[used] | ```
2025-08-10cfg_select: Support unbraced expressionsJosh Triplett-11/+19
When operating on expressions, `cfg_select!` can now handle expressions without braces. (It still requires braces for other things, such as items.) Expand the test coverage and documentation accordingly.
2025-08-09Auto merge of #145146 - fee1-dead-contrib:push-zmqrkurlzrxy, r=nnethercotebors-258/+269
remove `P` Previous work: rust-lang/rust#141603 MCP: https://github.com/rust-lang/compiler-team/issues/878 cc `@nnethercote`
2025-08-09remove `P`Deadbeef-258/+269
2025-08-08Recover for PAT = EXPR {}Michael Goulet-6/+7
2025-08-06Rollup merge of #144956 - fmease:gate-const-trait-syntax, r=BoxyUwUGuillaume Gomez-0/+3
Gate const trait syntax Missed this during my review of rust-lang/rust#143879, huge apologies! Fixes [after beta backport] https://github.com/rust-lang/rust/issues/144958. cc ``@fee1-dead`` r? ``@BoxyUwU`` or anyone
2025-08-06Rollup merge of #144195 - Kivooeo:bad-attr, r=fmease,compiler-errorsGuillaume Gomez-7/+80
Parser: Recover from attributes applied to types and generic args r? compiler Add clearer error messages for invalid attribute usage in types or generic types fixes rust-lang/rust#135017 fixes rust-lang/rust#144132
2025-08-05Gate const trait syntaxLeón Orell Valerian Liehr-0/+3
2025-08-05Added checks for attribute in type caseKivooeo-7/+80
2025-08-04Include whitespace in "remove `|`" suggestion and make it hiddenEsteban Küber-10/+25
2025-07-31Consider operator's span when computing binop expr spanMichael Goulet-6/+9
2025-07-29Rollup merge of #144589 - compiler-errors:postfix-yield-after-cast, ↵Stuart Cook-1/+5
r=petrochenkov Account for `.yield` in illegal postfix operator message Fixes rust-lang/rust#144527
2025-07-28feat: Right align line numbersScott Schafer-24/+24
2025-07-28Account for .yield in illegal postfix operator messageMichael Goulet-1/+5
2025-07-28Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLiibors-27/+25
Some `let chains` clean-up Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one r? compiler
2025-07-28use let chains in mir, resolve, targetKivooeo-27/+25