Commit Graph

2852 Commits

Author SHA1 Message Date
Guillaume Gomez
c25ed44cb0 Rollup merge of #158009 - oli-obk:impl-const-impl-Trait, r=fee1-dead
Reject `impl const Trait` since the right syntax is `const impl Trait` now

I also let some smaller rustfmting of ui tests through, as rustfmt immediately formats `impl const Trait` to `const impl Trait`. This is also the reason I expect that this change will break very little nightly users, so we don't even need to add some helpful diagnostic.

r? @fee1-dead
2026-06-18 20:30:26 +02:00
Oli Scherer
a88521a6f6 Reject impl const Trait since the right syntax is const impl Trait now 2026-06-17 17:42:48 +02:00
Haoran Wang
0ab14caeaf Don't suggest adding in to a for loop that already has one
When a `for` loop is missing its `in`, the parser suggested inserting one
based only on the token after the pattern. A malformed binding such as
`for i i in 0..10` was therefore "corrected" to `for i in i in 0..10`,
which does not parse. Only suggest inserting `in` when the loop header
does not already contain one before the body.
2026-06-15 20:38:53 +08:00
Takayuki Maeda
33d143607d avoid raw ref call recovery in nested delimiters 2026-06-14 22:39:09 +09:00
Jonathan Brouwer
3f0676c213 Rollup merge of #157079 - qaijuang:raw-expr-list-recovery, r=Kivooeo
Don't recover `&raw EXPR` as a missing comma

The parser already has a targeted suggestion for `&raw EXPR`, added in rust-lang/rust#139392, telling the user that `&raw` must be followed by `const` or `mut`.

In comma-separated expression lists, the generic missing-comma recovery would then treat the expression after `raw` as the next list element. That produced follow-up diagnostics like:

- `help: missing ','`
- `cannot find value raw in this scope`
- an arity error for calls such as `takes_raw_ptr(&raw x)`

This PR avoids that comma recovery when we are already in the `&raw` missing-`const`/`mut` diagnostic path. For function calls, it preserves the call expression with a single error argument, so useful later diagnostics such as `cannot find function f` are still emitted.

Fixes rust-lang/rust#157015.
2026-06-12 20:40:56 +02:00
Jacob Pratt
0bd32c0e96 Rollup merge of #157577 - i-like-ICEs:fix-dyn-2015-parser, r=fmease
Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`

Fixes: rust-lang/rust#157565

### Description
A diagnostics improvement rust-lang/rust#84896 in 2015 edition caused errors when `dyn + dyn` was used, even though `dyn` is a contextual keyword in the 2015 edition.

### Solution
A check was added in `rustc_parse/src/parser/ty.rs:1095`:
```rust
            if self.token.is_keyword(kw::Dyn) && self.token.span.edition().at_least_rust_2018() {
```
This checks that the version is not 2015 before throwing an error.
A regression test was also added, in `tests/ui/parser/dyn-2015-identifier.rs`
2026-06-11 00:34:16 -04:00
qaijuang
68381b1bd8 address clean code suggestion 2026-06-10 06:21:57 -04:00
William Zeng
5bc21b1f58 Fix parser error recovery for 'dyn' in Rust 2015 2026-06-09 18:03:46 -04:00
León Orell Valerian Liehr
ddbf3b9ec6 Syntactically reject equality predicates 2026-06-07 19:00:21 +02:00
aerooneqq
31e358824f Do not always generate first delegation argument 2026-06-05 08:30:38 +03:00
qaijuang
5fde1fdac9 preserve arg count in call recovery 2026-06-04 04:03:33 -04:00
qaijuang
3d697650f2 refactor: delegate raw ref mut checks to a new helper method 2026-06-04 03:44:31 -04:00
bors
0cf9681261 Auto merge of #157274 - kupiakos:open-enums-feature-gate, r=Kivooeo
Add experimental `unnamed_enum_variants` feature gate

This parses the basic syntax and defines a feature gate for the unnamed enum variants lang experiment, tracking issue rust-lang/rust#156628.

cc @joshtriplett, @scottmcm, @tmandry
2026-06-04 07:23:40 +00:00
Jonathan Brouwer
1aabc75ca9 Rollup merge of #157235 - bb1yd:improve-colon-suggestion, r=mejrs
additional changes for issue-144595

- add spaces between the braces @ada4a
- remove `:` in the help message.
I learn this from estebank ("In the text we don't include a trailing :, unless we have a very specific reason. These messages can render in the terminal, in different ways, or in IDEs. Having a : can look out of place in some cases, specifically in rust-analyzer in VSCode is one of them.")
- suggest to use `::` for any colon encountered in tuple struct.
  So it now display help message for `std::string:String`. The same logic also appears in `parse_block_tail`, it suggest the user to use `::` when `parse_full_stmt` stops at a colon. So I think it's okay to make this change.

r? mejrs
2026-06-02 21:16:55 +02:00
Guillaume Gomez
5521a56ea1 Remove skip_arg attribute from Diagnostic and Subdiagnostic proc-macros, skipping fields based on whether or not they are used in error messages 2026-06-02 17:43:01 +02:00
b1yd
381cea98cb fix 2026-06-02 23:00:47 +08:00
Alyssa Haroldsen
e6b4102fa6 Add experimental unnamed_enum_variants feature gate 2026-06-01 14:58:25 -07:00
qaijuang
b459cfcf43 don't recover &raw EXPR as a missing comma 2026-05-28 15:39:23 -04:00
b1yd
92194469a0 fix issue-144595 2026-05-26 21:35:25 +08:00
CoCo-Japan-pan
c43fa7a8bb Parse mut restrictions 2026-05-24 17:33:46 +09:00
Jacob Pratt
9a88f9f74f Rollup merge of #156664 - ManiSalahmand:fix-doc-comment-generic-tuple, r=petrochenkov
Avoid const generic recovery after doc comment in type

Fixes rust-lang/rust#122463.

When parsing a generic argument, rustc may snapshot the parser state and retry a failed type parse as an unbraced const generic argument. For `Vec<(/// doc
f32, f32)>`, that recovery produces a misleading follow-up E0747 after the useful “expected type, found doc comment” diagnostic.

This skips that const-generic recovery path when type parsing stopped at a doc comment, and adds a regression test for the compiler diagnostic.
2026-05-18 13:52:56 +02:00
Jonathan Brouwer
4cce8bcdc8 Rollup merge of #156635 - bb1yd:rename_unexpected_try_recover, r=JohnTitor
rename unexpected_try_recover function

While reading the code, the doc comment and the name of the function `unexpected_try_recover` confused me. The doc said it tries to recover if it is a closing delimiter but I see no recovering code and the function always return an error.

So I change the name of the function to `unexpected_err` and change the return value to `Diag<'a>`. I also update the doc comment.
2026-05-17 15:52:42 +02:00
Jonathan Brouwer
4bb85516e8 Rollup merge of #156376 - euclio:foreign-escapes, r=mu001999
suggest hex escapes for C-style escapes

Fixes rust-lang/rust#148884.
2026-05-17 15:52:38 +02:00
Mani Salahmand
0564168895 Avoid const generic recovery after doc comment in type 2026-05-17 14:32:47 +02:00
Andy Russell
e5998316eb suggest hex escapes for C-style escapes 2026-05-16 20:23:53 -04:00
b1yd
6d91f14af9 fix 2026-05-16 16:03:00 +08:00
Esteban Küber
31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
Jonathan Brouwer
4ce7ac120c Rollup merge of #156287 - cyrgani:unbox-2, r=petrochenkov
move more compiler crates away from `box_patterns`

Part of https://github.com/rust-lang/rust/issues/156110.
2026-05-12 18:53:35 +02:00
Jonathan Brouwer
1db77ea560 Rollup merge of #155023 - TaKO8Ki:move-expr-1, r=nikomatsakis
Introduce move expressions (`move($expr)`)

This is an experimental first version of move expressions.

This first version implements it just in plain closures. A support for coroutine closures will be added in follow up pull requests.

RFC: will be added later
Tracking issue: https://github.com/rust-lang/rust/issues/155050
Project goal:
- https://github.com/rust-lang/rust-project-goals/issues/107
- https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html

r? @nikomatsakis
2026-05-11 23:03:03 +02:00
cyrgani
74c4e77de7 use deref_patterns in rustc_parse 2026-05-10 21:05:36 +00:00
Matthias Krüger
eabe4620e5 Rollup merge of #156333 - TaKO8Ki:fix-dotdotdot-rest-pattern-unicode-span, r=Urgau
Avoid invalid spans in dotdotdot rest pattern suggestions

Fixes rust-lang/rust#156316

The parser recovers Unicode confusables such as `···` as `...`, while keeping the original source span over the multibyte characters.

`recover_dotdotdot_rest_pat` built its suggestion by subtracting `BytePos(1)` from the end of that recovered token span. For multibyte characters, that can create a span boundary inside a UTF-8, causing diagnostic emission to ICE.

This changes the suggestion to replace the whole recovered token span with `..` instead of slicing off one byte.
2026-05-08 20:39:27 +02:00
Takayuki Maeda
431017bb55 avoid byte slicing in dotdotdot rest pattern suggestion 2026-05-09 01:27:40 +09:00
Jonathan Brouwer
6133b7e062 Rollup merge of #155734 - qaijuang:cfg-select-doc-comment, r=JonathanBrouwer
Reject outer attributes on `cfg_select` branches

Fixes rust-lang/rust#155701.
2026-05-08 11:35:31 +02:00
Qai Juang
d42a92b18d Reject outer attributes on cfg_select branches
* Lint doc comments in cfg_select branches
* test with multi-line doc comment

Co-authored-by: Copilot <copilot@github.com>
* Reject outer attributes on `cfg_select` branches
* address nits and gotchas

Co-authored-by: Copilot <copilot@github.com>
* one more test

Co-authored-by: Copilot <copilot@github.com>
* avoid snapshotting and classify recovered doc comments directly
2026-05-08 09:14:09 +00:00
Takayuki Maeda
98348de63a add move(expr) syntax 2026-05-07 22:22:56 +09:00
Jonathan Brouwer
47e6437af4 Rollup merge of #156031 - nnethercote:lex_token_trees, r=chenyukang
Return a single diagnostic from `lex_token_trees`.

It currently returns a `Vec` but in practice it always has one diagnostic in it.

LLM disclosure: Claude Code identified this when I asked it to review `tokentrees.rs`. I made the change by hand and tested it myself.

r? @chenyukang
2026-05-01 13:10:38 +02:00
Nicholas Nethercote
c9d0bdccb2 Return a single diagnostic from lex_token_trees.
It currently returns a `Vec` but in practice it always has one
diagnostic in it.

LLM disclosure: Claude Code identified this when I asked it to review
`tokentrees.rs`. I made the change by hand and tested it myself.
2026-05-01 15:10:46 +10:00
Jacob Pratt
f7b1e7d892 Rollup merge of #155939 - scrabsha:view-types/feature-gate, r=nikomatsakis
Add feature gate for view_types experiment
2026-04-30 22:28:26 -04:00
Nicholas Nethercote
9454be304f Invert dependency between rustc_error_messages and rustc_ast*.
`rustc_error_messages` currently depends on
`rustc_ast`/`rustc_ast_pretty`. This is odd, because
`rustc_error_messages` feels like a very low-level module but
`rustc_ast`/`rustc_ast_pretty` do not.

The reason is that a few AST types impl `IntoDiagArg` via
pretty-printing. `rustc_error_messages` can define `IntoDiagArg` and
then impl it for the AST types. But if we invert the dependency we hit
a problem with the orphan rule: `rustc_ast` must impl `IntoDiagArg`
for the AST types, but that requires calling pretty-printing code which
is in `rustc_ast_pretty`, a downstream crate.

This commit avoids this problem by just removing the `IntoDiagArg` impls
for these AST types. There aren't that many of them, and we can just use
`String` in the relevant error structs and use the pretty printer in the
downstream crates that construct the error structs. There are plenty of
existing examples where `String` is used in error structs.

There is now no dependency between `rustc_ast*` and
`rustc_error_messages`.
2026-05-01 10:58:14 +10:00
Sasha Pourcelot
77fb8d1d5c Parse view type syntax, mark it as unstable 2026-04-29 18:11:02 +00:00
Zalathar
9ceed255b5 Avoid improper spans when ... or ..= is recovered from non-ASCII
This avoids an ICE due to indexing into the middle of a multi-byte character.
2026-04-26 21:41:46 +10:00
Jacob Pratt
1230f74ad5 Rollup merge of #155698 - fmease:no-struct-pat-tuple-index-shorthand, r=mu001999
Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression

Split out of PR rust-lang/rust#154492. This fixes a correctness regression introduced in PR rust-lang/rust#81235 from 2021. Crater was run in my other PR and didn't report any real regressions (https://github.com/rust-lang/rust/pull/154492#issuecomment-4187544786); a rerun has been issued for a few spurious builds (https://github.com/rust-lang/rust/pull/154492#issuecomment-4237077272) but I'm certain it won't find anything either.

This is a theoretical breaking change that doesn't need any T-lang input IMHO since it's such a minute, niche and crystal clear bug that's not worth bothering them with (such a decision is not unprecedented). I'm adding it to the compatibility section of the release notes as is customary.

The Reference doesn't need updating since it didn't adopt this bug and thus accurately describes this part of the grammar as it used to be before 2021-02-23 and as it's meant to be.

The majority of the diff is doc comment additions & necessary UI test restructurings.
2026-04-24 02:42:52 -04:00
León Orell Valerian Liehr
07d015e566 Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression 2026-04-23 22:28:00 +02:00
Guillaume Gomez
abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
CoCo-Japan-pan
cbba81e0e2 Add early returns in check_trait_front_matter 2026-04-21 22:55:35 +09:00
CoCo-Japan-pan
470e4623db Rule out const unsafe impl from FnHeader to
correctly parse `const unsafe trait` implementations.
2026-04-21 22:17:23 +09:00
cijiugechu
f6294883f8 Make reparsed guard metavars collect tokens 2026-04-20 13:36:27 +08:00
CoCo-Japan-pan
a0b8e89456 Update AST pretty printing 2026-04-19 15:58:02 +09:00
CoCo-Japan-pan
56211738ea Reorder keywords to place restrictions next to visibility 2026-04-19 15:57:54 +09:00
Vadim Petrochenkov
7114404a26 ast: Preserve the star symbol span in glob delegation items 2026-04-14 11:32:33 +03:00