Commit Graph

2943 Commits

Author SHA1 Message Date
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
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
Jonathan Brouwer
8355006dd1 Rollup merge of #160592 - Diacod-I:if-let-chain-unclosed-delim-hint, r=estebank
Suggest if-let chain continuation on unclosed delimiter

Meant to fix rust-lang/rust#160550. When an unclosed brace-delimited block begins with && or ||, the "unclosed delimiter" error now points at that line, suggesting the user may have meant to continue an if-let chain.

- Records the leading `&&`/`||` span during lexing (in lex_token_tree_open_delim) and surfaces it in report_suspicious_mismatch_block.
- Adds a `tests/ui/parser` regression test.
2026-08-06 12:41:03 +02:00
advithkrishnan.eth
39b3ad8383 Suggest if-let chain continuation on unclosed delimiter 2026-08-06 07:22:43 +05:30
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
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
Jonathan Brouwer
d01433cf71 Rollup merge of #159849 - petrochenkov:estmt, r=JonathanBrouwer
rustc_parse: Stop returning `Option` from statement parsing

`parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes.

It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error.
So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
2026-07-26 15:47:19 +02:00
Jacob Pratt
0a72846a4d Rollup merge of #159695 - Dnreikronos:proc_macro/cfg_attr_file_mod_inner_attr, r=nnethercote,petrochenkov
proc_macro: Fix cfg_attr inner attrs in file modules

Fixes rust-lang/rust#159648

Inner proc-macro attrs produced by `cfg_attr` only carry the nested attr span. Splitting source around that span tries to lex two unmatched halves, so file modules fail with an unclosed delimiter.

Lex the complete module body first, then remove the expanded attr from its nested token stream. Sibling attrs stay in place, and empty `cfg_attr` wrappers use their trace span and disappear. imo this is cleaner than teaching source slicing about every nested shape.

Tests exercise sibling attrs on either side of the proc macro, then cover the single-attr case. fyi, denied lints make sibling preservation observable; ltm if another nested case should live here.
2026-07-26 00:21:54 -04:00
Joao Roberto
1f8b15fba1 Fix cfg_attr inner attributes in file modules
Return to pretty-printed token reconstruction when lexing source slices around an inner attribute produces unmatched delimiters.

Cover cfg_attr-expanded proc-macro attributes in an out-of-line module, including sibling attributes on both sides.
2026-07-25 12:08:44 -03: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
khyperia
e895ed8c90 unify the AST repr of type const and const RHS 2026-07-22 09:22:45 +02:00
Esteban Küber
1b7ae04e21 Tweak code and diagnostic formatting and messages 2026-07-21 16:11:09 +00:00
Esteban Küber
737220233d Make some parser structured suggestions verbose
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.
2026-07-21 15:50:58 +00:00
Jonathan Brouwer
ef3632338e Rollup merge of #159636 - nnethercote:some-comments, r=petrochenkov
Improve some comments (and an error message)

Details in individual commits.

r? @petrochenkov
2026-07-21 12:24:58 +02:00
Jonathan Brouwer
82d262fcc4 Rollup merge of #159590 - oli-obk:unsafe_attrs_old, r=petrochenkov
Remove some dead code

Leftover from a previous revision of `#[unsafe(no_mangle)]`. All call sites disallowed it anyway, and the real handling is in the parser.
2026-07-21 12:24:57 +02:00
Oli Scherer
4e2ebd6235 Remove some dead code 2026-07-21 11:34:36 +02:00
Nicholas Nethercote
efbdd60649 Add a comment about why we collect tokens
Non-obvious information that took me some time to work out.
2026-07-21 16:16:09 +10:00
Jacob Pratt
d2f94b7374 Rollup merge of #159601 - nnethercote:privatize-TokenTreeCursor, r=Kobzol
Make `TokenTreeCursor` private

And also the fields of `TokenCursor`.

It's good hygiene in general, and will allow larger changes to `TokenCursor` down the road (e.g. hopefully avoiding the flattening of token trees to a linear token stream).

r? @Kobzol
2026-07-20 23:38:07 -04:00
Jacob Pratt
18b6b903da Rollup merge of #159543 - chenyukang:yukang-fix-159542-remove-extra-semicolon, r=estebank
Remove extra semicolons in parsing item lists

Fixes rust-lang/rust#159542
2026-07-20 23:38:00 -04:00
Nicholas Nethercote
3f2624ea64 Make TokenTreeCursor private
And also the fields of `TokenCursor`.

It's good hygiene in general, and will allow larger changes to
`TokenCursor` down the road (e.g. hopefully avoiding the flattening of
token trees to a linear token stream).
2026-07-21 06:55:08 +10:00
Jonathan Brouwer
c905c76604 Rollup merge of #159603 - nnethercote:clarify-push_stream, r=Kobzol
Clarify `push_stream`/`push_tree`

More `TokenStream` cleanups. Details in individual commits.

r? @Kobzol
2026-07-20 18:06:17 +02:00
Jonathan Brouwer
152c269c8e Rollup merge of #159587 - nnethercote:AttrItem-span, r=petrochenkov
Improve `AttrItem::span`

It has some shortcomings. Details in individual commits.

r? @petrochenkov
2026-07-20 18:06:05 +02:00
Jonathan Brouwer
09e88c10af Rollup merge of #158046 - Dnreikronos:proc_macro/file_mod_inner_attr_spans, r=petrochenkov
proc_macro: preserve file module spans for inner attrs

fixes rust-lang/rust#157881

out-of-line mods with custom inner attrs were sending proc macros a pretty-printed module wrapper. the awkward bit: tokens inside the module picked up the span from the parent mod foo;, so later diags pointed at the decl instead of the file where the code actually came from.

this keeps the wrapper synthetic, but puts the loaded file body back into the token stream with its own spans. it also skips the attr currently being expanded, so we don't replay it by accident. added a small ui repro too, plus the older span-debug output changed because those spans are now real.

imo this is the least annoying fix for now. fwiw, it keeps the old fake-wrapper path instead of trying to make full token capture for file mods happen in this PR.
2026-07-20 18:06:01 +02:00