Commit Graph

2408 Commits

Author SHA1 Message Date
Jonathan Brouwer
0ae3fd93a3 Rollup merge of #161796 - fmease:rm-dead-underscore-recovery, r=mu001999
Remove dead parse error recovery (underscores in expressions)

Back in b7f7756566 (2019) the parser was extended to recover from `_`s as elements of tuple expressions (this was later extended to also cover call expressions). At the time, `_` obviously wasn't an expression yet.

Nowadays `parse_expr_res` will *always* successfully parse `_` as an `ExprKind::Underscore` (irrespective of the passed `Restrictions`). Consequently, we will never reach the special case in `parse_expr_catch_underscore`. Drop this entire wrapper function.

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
2026-08-26 08:01:00 +02:00
León Orell Valerian Liehr
8de399ac7b Remove dead parse error recovery (underscores in expressions) 2026-08-26 04:48:42 +02:00
Jonathan Brouwer
dda473214e Rollup merge of #161443 - khyperia:abbys-tests, r=BoxyUwU
add internal DSL for testing binders

implements https://github.com/rust-lang/project-assumptions-on-binders/issues/8

apologies to the inevitable swarm of people who get pinged for this...

basically the only interesting diff is `compiler/rustc_hir_analysis/src/check/wfcheck.rs`, which actually implements the test. there's probably still features we want to add to this DSL (e.g. `RegionConstraint::AliasTyOutlivesViaEnv`), and there might be some bugs lurking, but this is at least a base to work off of. It's perma-unstable and for internal use only, so support and quality doesn't have to be incredibly high. For example, parser recovery and whatnot is just, bad, but whatever.

r? BoxyUwU
2026-08-25 18:00:01 +02:00
Jacob Pratt
9f6bef7e24 Rollup merge of #161411 - im-lunex:fix_#161213, r=nnethercote
avoid overlapping const suggestions

Avoid emitting the optional `const-extraction` suggestion when its **component spans** overlap, this avoids the compiler panic while still emitting the normal error and keeping the suggestion for cases where it can be
generated correctly

Fixes rust-lang/rust#161213
2026-08-25 04:53:49 -04:00
cyrgani
9caab2652e remove box_patterns feature 2026-08-25 07:50:03 +00:00
Jonathan Brouwer
4410eba1c2 Rollup merge of #161637 - nnethercote:clarify-token-cursor, r=Kobzol
Clarify token cursor behaviour

The meaning of `TokenTreeCursor::index` is context-dependent: in the innermost (current) `TokenTreeCursor` it points to the next token tree, but in all the other (stack) `TokenTreeCursor`s it points to the current token tree. This makes the meanings of "current", "next", and "look_ahead" confusing for it and for `TokenCursor`.

This commit clarifies things by adjusting the stack `TokenTreeCursor`s to also point to the next token tree, and by improving various comments.

The commit also renames `TokenCursor::next` as
`TokenCursor::next_and_bump` for consistency with everything else: `next` means "get the next thing" and `bump` means "advance the cursor", and this operation does both.

r? @Kobzol
2026-08-24 15:06:59 +02:00
khyperia
210fd61779 add internal DSL for testing binders 2026-08-24 08:54:48 +02:00
Stuart Cook
9799322d5c Rollup merge of #155254 - scrabsha:push-qlmmuuwqnoqv, r=fmease
Recover on attribute in use tree
2026-08-24 14:21:48 +10:00
Nicholas Nethercote
1bc25c317b Clarify token cursor behaviour
The meaning of `TokenTreeCursor::index` is context-dependent: in the
innermost (current) `TokenTreeCursor` it points to the next token tree,
but in all the other (stack) `TokenTreeCursor`s it points to the current
token tree. This makes the meanings of "current", "next", and
"look_ahead" confusing for it and for `TokenCursor`.

This commit clarifies things by adjusting the stack `TokenTreeCursor`s
to also point to the next token tree, and by improving various comments.

The commit also renames `TokenCursor::next` as
`TokenCursor::next_and_bump` for consistency with everything else:
`next` means "get the next thing" and `bump` means "advance the cursor",
and this operation does both.
2026-08-24 14:07:37 +10:00
León Orell Valerian Liehr
1333ad790a Small tweaks to parse error recovery code 2026-08-23 14:39:15 +02:00
Sasha Pourcelot
e6e1f048cb Recover on attribute in use tree 2026-08-23 14:39:15 +02:00
Jacob Pratt
4e637b3c68 Rollup merge of #160279 - ArneshBanerjee:recover-tuple-type-ascription, r=fmease
Recover from tuple patterns with inline element types

If you write the element types inside a tuple pattern:

```rust
let (a: bool, b: u8) = (true, 1);
```

the error you get doesn't really explain the problem:

```
error: expected one of `)`, `,`, `@`, `if`, or `|`, found `:`
 --> src/main.rs:2:11
  |
2 |     let (a: bool, b: u8) = (true, 1);
  |           ^ expected one of `)`, `,`, `@`, `if`, or `|`
```

A let pattern can have a type after it, so now we point out what to do instead:

```
help: to annotate the types of a tuple's elements, write them as a tuple type after the pattern
  |
2 -     let (a: bool, b: u8) = (true, 1);
2 +     let (a, b): (bool, u8) = (true, 1);
  |
```

If an element doesn't have a type written, it just gets `_`, so `(a: bool, b)`
turns into `(a, b): (bool, _)`.

I kept this to let bindings only. That's the case where the pattern doesn't need
a type of its own, so once the types move into the suggestion the rest of the
statement parses fine and you get a single error instead of a pile of follow-up
ones. Match arms, nested patterns and function parameters are left alone.

Closes rust-lang/rust#149246
2026-08-23 05:59:33 -04:00
Arnesh Banerjee
aad8a5a7a3 Address review: recover in all pattern locations, drop extra allocation 2026-08-23 07:07:46 +05:30
Zalathar
83a13f64a6 Clean up a few _inner functions after ensure_sufficient_stack
After the removal of `ensure_sufficient_stack`, these inner and outer functions
no longer need to be separate.
2026-08-22 18:06:33 +10:00
mejrs
7cd9c920cd rustc_session; remove rustc_lint_defs rex-exports 2026-08-20 23:02:49 +02:00
im-lunex
08ec41ea3d avoid overlapping const suggestions 2026-08-20 22:45:47 +06:00
bors
eaa160c49d Auto merge of #161082 - nnethercote:overhaul-CoroutineMarker, r=mejrs
Overhaul `CoroutineKind`

Its structure is a bit weird. Details in individual commits.

r? @mejrs
2026-08-17 02:41:22 +00:00
Nicholas Nethercote
613e826eaa Overhaul CoroutineKind
It is an enum with three variant, and all the variants have identical
fields, which is silly. This commit does the following.

- Renames it as `CoroutineMarker`, because the `Kind` suffix is used for
  enums. (The existing doc comment already uses the word "marker".)

- Renames the existing `GenBlockKind` as `CoroutineKind`, uses it
  within `CoroutineMarker`, and adds `CoroutineKind::is_gen`.

This removes the need for the `span`, `closure_id` and `return_id`
methods; direct field access now suffices.
2026-08-17 12:29:59 +10:00
Makai
9126d55662 cleanup: rip out unnecessary iter().last() and iter().next() 2026-08-15 00:25:23 +08:00
Jacob Pratt
87f5f9b9e5 Rollup merge of #160861 - ravlynd:if-semi-before-block-suggestion, r=chenyukang
rustc_parse: suggest removing semicolon before `if` block

Closes rust-lang/rust#159812

Suggest removing semicolon before the block in an `if` expression
2026-08-12 20:17:32 -04:00
ravlyn
349eac6d92 rustc_parse: suggest removing semicolon before if block 2026-08-12 21:11:19 +07:00
Jonathan Brouwer
03c3d00ee3 Make inputs to ParenthesizedArgs a ThinVec<Param> in the compiler 2026-08-11 20:47:40 +02:00
bors
8a2fbe3ea8 Auto merge of #160830 - jhpratt:rollup-IMvXhX3, r=jhpratt
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#160675 (bootstrap: Remove `PATH_REMAP` from command-line selector handling )
 - rust-lang/rust#160807 (Update rustc crate rkyv to 0.8.18)
 - rust-lang/rust#159690 (Clarify `--remap-path-scope` impact on `rustc` metadata)
 - rust-lang/rust#160560 (Add nightly-only support for Cargo unremap trim-paths files in `rust-gdb`)
 - rust-lang/rust#160608 (normalization rework: clean up projection_ty_core)
 - rust-lang/rust#160785 (Get rid of LLM disclosure checkboxes)
 - rust-lang/rust#160804 (Change .expect message on net/parser to follow precondition style)
 - rust-lang/rust#160805 (`extern "custom"`: add tests)
 - rust-lang/rust#160816 (Mark const ptr methods and free functions as inline(always) to match *mut)
 - rust-lang/rust#160820 (Stabilize fs_set_times)
 - rust-lang/rust#160826 (Rename parse_delimited_token_tree in cfg_select)
2026-08-10 06:25:17 +00:00
Yukang
41e53faaf0 Rename parse_delimited_token_tree to parse_cfg_select_branch_rhs 2026-08-10 09:40:01 +08:00
Chris Denton
4641990929 Remove ensure_sufficient_stack 2026-08-09 19:58:29 +00:00
Jonathan Brouwer
c10876b8a1 Rollup merge of #160744 - mejrs:struct-diagnostics-privacy, r=JonathanBrouwer
make more diagnostic structs pub(crate)
2026-08-09 18:22:27 +02:00
Jacob Pratt
3820cc943d Rollup merge of #158517 - JonathanBrouwer:named_fn_trait_parameters, r=JohnTitor
Initial implementation of named `Fn` trait parameters

This is an initial implementation of the feature `named_fn_trait_parameters`.
This implementation is incomplete (and also marked as such) , and needs significant further changes to be implemented correctly. To keep the size of this PR managable, I propose we do this in follow-up PRs.
I've added a test that shows the current behaviour, with `FIXME` comments where the test output is currently incorrect.

Tracking issue: https://github.com/rust-lang/rust/issues/158499
Accepted RFC: https://github.com/rust-lang/rfcs/pull/3955
2026-08-08 23:51:55 -04:00
Arnesh Banerjee
0790e9d398 Address review: drop parser snapshot, keep path-separator suggestion
Rework the recovery to happen in a single parse instead of parsing the
tuple pattern, resetting on failure, and parsing again. The element
closure now eats an optional `: <ty>` directly, so there's no parser
snapshot on the happy path.

Only treat the colon as a type annotation when it is followed by
whitespace, so `(m:C,)` keeps the existing "maybe write a path separator
here" suggestion for `m::C` and only `(m: C,)` gets the tuple-type
suggestion.
2026-08-08 19:30:37 +05:30
mejrs
d8ecbe7c01 Move ExprParenthesesNeeded diagnostic struct out of rustc_session
It was never used in that crate, so rustc_parse is the next obvious place to go. It's also used by rustc_hir_typeck, but sharing diagnostics between crates makes it easy for such things to become dead, so duplicate it.
2026-08-08 12:13:25 +02:00
Jacob Pratt
3c50d990c9 Rollup merge of #160303 - petrochenkov:ambattr3, r=chenyukang
rustc_parse: A few cleanups to expression parsing next to attributes

- The `_with` suffix is removed from `parse_expr_assoc_with` and `parse_expr_assoc_rest_with`. There's no version with `with`, the precedence is always specified.
- `parse_expr_res` and `parse_expr_assoc` are split into two versions taking pre-parsed attributes and not taking pre-parsed attributes. The latter versions are more common and can have simpler return type.
- "Dead" `parse_outer_attributes` is removed from `parse_expr_prefix_range`, it can never parse anything because the current token is a range separator.
- `bump` is moved out of `parse_expr_prefix_common`, it allows reusing `parse_expr_prefix_common` in one more place.
- A test covering some previously uncovered attribute parsing cases is added.
2026-08-08 03:10:08 -04:00
bjorn3
1a3d919258 Deny multiple EII impls on a single item
This allows implementing EIIs that don't have a default impl without the
involvement of symbol aliases by simply changing the mangled symbol name
of the implementation, which would make them trivially compatible with
all backends and targets. This change will be left to a followup PR.
2026-08-03 11:04:23 +02:00
Jacob Pratt
bf297d5274 Rollup merge of #160282 - JonathanBrouwer:arg-pattern, r=petrochenkov
Improve diagnostic for patterns in function pointer types

In preparation for some work for https://github.com/rust-lang/rust/issues/158499

Diagnostic before:
```
error[E0642]: patterns aren't allowed in methods without bodies
  --> $DIR/fn-ptr-pattern.rs:4:14
   |
LL |     pat2: fn(1..3: bool),
   |              ^^^^
   |
help: give this argument a name or use an underscore to ignore it
   |
LL -     pat2: fn(1..3: bool),
LL +     pat2: fn(_: bool),
   |
```
Diagnostic after:
```
error[E0642]: patterns aren't allowed in function pointer types
  --> $DIR/fn-ptr-pattern.rs:4:14
   |
LL |     pat2: fn(1..3: bool),
   |              ^^^^
   |
help: give this argument a name or use an underscore to ignore it
   |
LL -     pat2: fn(1..3: bool),
LL +     pat2: fn(_: bool),
   |
```
2026-07-31 22:25:14 -04:00
Vadim Petrochenkov
7894a438a7 rustc_parse: A few cleanups to expression parsing next to attributes 2026-07-31 22:44:48 +03:00
Jonathan Brouwer
239ab02029 Rollup merge of #160233 - estebank:issue-92685, r=JohnTitor
Bubble bad path error while parsing field to avoid unecessary second error

Noticed while looking at rust-lang/rust#92685. Add test for the case in that ticket.
2026-07-31 16:02:25 +02:00
Jonathan Brouwer
c1bcbb45a6 Improve diagnostic for patterns in function pointer types 2026-07-31 15:37:08 +02:00
Arnesh Banerjee
2cf68c55a9 Recover from tuple patterns with inline element types
Writing the type of each element inside a tuple pattern like
`let (a: bool, b: u8) = ...` isn't valid, but the current error doesn't
really tell you that. It just says "expected one of `)`, `,`, `@`, `if`,
or `|`, found `:`" and leaves you to work it out.

A let pattern can be followed by a type, so we can suggest the fix: move
the types out into a tuple type after the pattern, so `(a: bool, b: u8)`
becomes `(a, b): (bool, u8)`. Elements without a type just get `_`.
Parsing then keeps going with the types dropped, so you only get the one
error.
2026-07-31 17:44:24 +05:30
Jonathan Brouwer
858e064041 Implement named fn trait parameters 2026-07-31 13:27:22 +02:00
Jonathan Brouwer
d7f1ae627d Rollup merge of #160192 - chenyukang:yukang-fix-160171-pub-before-close-brace, r=petrochenkov
Fix ICE for parsing issue with a closing brace

Fixes rust-lang/rust#160171

r? @petrochenkov
2026-07-31 00:06:41 +02:00
Jonathan Brouwer
0b4f6fcf51 Rollup merge of #160175 - estebank:issue-88416, r=jieyouxu
Try to recover less from incorrectly parsed const arg

The error recovery can cause a cascade of irrelevant errors, so instead return the `PResult::Err` and let the parser fail further up in the logic.

Fix rust-lang/rust#88416.
2026-07-31 00:06:38 +02:00
Jonathan Brouwer
bafc9b3206 Rollup merge of #160040 - kpreid:parse-fn, r=TaKO8Ki
Split function parsing out of `item.rs` to a new module.

`item.rs` is approaching the tidy-enforced length limit, and this will make room for new additions.

I have split this change out of PR rust-lang/rust#159044 to reduce its complexity (and because this large code move quickly becomes stale).
2026-07-31 00:06:35 +02:00
Esteban Küber
791e56a931 Bubble bad path error while parsing field to avoid unecessary second error 2026-07-30 19:41:56 +00:00
Yukang
b60abe4fbf Fix ICE for parsing issue with unexpected closing brace 2026-07-30 10:28:14 +08:00
Esteban Küber
5d78eab4dd Try to recover less from incorrectly parsed const arg 2026-07-29 18:23:20 +00:00
Jonathan Brouwer
9e4d2e62c7 Rollup merge of #160008 - TaKO8Ki:fix-stale-closure-recovery, r=mati865
Avoid stale closure recovery state across statements

Fixes rust-lang/rust#159989

`current_closure` was cleared when starting a new expression through `parse_expr`, but statement expressions call `parse_expr_res` directly. This allowed closure recovery state from one statement to remain active while parsing the next statement.

This pr clears `current_closure` when entering `parse_stmt_without_recovery`, matching the behavior of `parse_expr`.

da2697d1d8/compiler/rustc_parse/src/parser/expr.rs (L55-L56)

da2697d1d8/compiler/rustc_parse/src/parser/expr.rs (L63-L64)
2026-07-28 21:07:59 +02:00
Kevin Reid
0c1fefd9de Split function parsing out of item.rs to a new module.
`item.rs` is approaching the tidy-enforced length limit, and this will
make room for new additions.
2026-07-27 21:17:47 -07:00
Takayuki Maeda
da2697d1d8 reset closure recovery state before parsing a statement 2026-07-27 20:19:58 +09:00
Esteban Küber
0ad2a3b3c2 Detect when a macro without exclamation mark uses square brackets
```
error: expected one of `.`, `?`, `]`, or an operator, found `,`
  --> $DIR/do-not-suggest-semicolon-between-macro-without-exclamation-mark-and-array.rs:2:19
   |
LL |     let _x = vec[1, 2, 3];
   |                   ^ expected one of `.`, `?`, `]`, or an operator
   |
help: you might have meant to call a macro
   |
LL |     let _x = vec![1, 2, 3];
   |                 +
```
2026-07-27 07:52:45 +00:00
Vadim Petrochenkov
75529d4b8e rustc_parse: Stop returning Option from statement parsing 2026-07-24 18:35:36 +03:00
Jacob Pratt
625d5f9fc9 Rollup merge of #159667 - estebank:verbose-parse-suggestions, r=TaKO8Ki
Make some parser structured suggestions verbose and tweak their wording

Replace most of the `.span_suggestion(` in `rustc_parse` with `.span_suggestion_verbose(`, as they are more readabale, if more verbose. Verbose suggestions also tend to highlight off-by-one `Span` errors better.

Tweak some of the touched diagnostics to bring them more in-line with our house style.

CC https://github.com/rust-lang/rust/issues/141973
2026-07-24 01:59:27 -04:00
panstromek
283ec3aa54 Make FieldDef smaller 2026-07-23 14:43:52 +02:00