Commit Graph

2843 Commits

Author SHA1 Message Date
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
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
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
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
bors
17584a1819 Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
León Orell Valerian Liehr
fc2c72cb67 Make the expansion of guard metavars begin guard non-terminals 2026-04-12 03:18:56 +02:00
Jonathan Brouwer
e756d1607d Add eii_impls argument to StaticItem 2026-04-11 10:17:07 +02:00
bors
02c7f9bec0 Auto merge of #155115 - JonathanBrouwer:rollup-RePrRPQ, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#152901 (Introduce a `#[diagnostic::on_unknown]` attribute)
 - rust-lang/rust#155078 (Reject dangling attributes in where clauses)
 - rust-lang/rust#154449 (Invert dependency between `rustc_errors` and `rustc_abi`.)
 - rust-lang/rust#154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing)
 - rust-lang/rust#154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths)
 - rust-lang/rust#155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
2026-04-10 18:19:03 +00:00
cijiugechu
3c6cf27ae4 Reject dangling attributes in where clauses 2026-04-10 21:45:26 +08:00
Jonathan Brouwer
45223feeba Rollup merge of #153796 - GokhanKabar:fix-ice-missing-tokens-eii-attr-expansion, r=jdonszelmann
Fix ICE when combining #[eii] with #[core::contracts::ensures]

Fixes rust-lang/rust#153745

Builtin attribute macros like #[eii] generate AST items programmatically without collected tokens. When another attribute macro was present on the same item, the compiler would panic in TokenStream::from_ast() trying to tokenize the generated items during subsequent attribute expansion.

Generate fake token streams (via pretty-print and re-parse) for Item and ForeignItem nodes that lack collected tokens, following the existing pattern used for Crate and out-of-line modules.
2026-04-10 15:33:12 +02:00
bors
9004856428 Auto merge of #153838 - oli-obk:use-tree-span, r=davidtwco
Use fine grained component-wise span tracking in use trees

This often produces nicer spans and even doesn't need a Span field anymore (not that I expect the unused field to affect any perf, but still neat).
2026-04-08 20:09:27 +00:00
Jonathan Brouwer
404ee74367 Rollup merge of #154235 - bb1yd:simplify-delim-check, r=fmease
remove unnecessary variables and delimiter check

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/question.20about.20lex_token_tree_open_delim.20in.20rustc_parse/with/580552157

In `lex_token_tree_open_delim`, after calling `self.lex_token_trees(/* is_delimited */ true)`:
 - If the delimiters are well-balanced, the value  popped from the stack will always equal to `open_delim` and `pre_span`.
 - If the delimiters are not balanced, `self.lex_token_trees(/* is_delimited */ true)` will return an error so this branch will not be reached

Therefore `open_delimiter` and `open_delimiter_span` can be removed.

Test `tests/ui/parser` all passed
2026-04-08 14:22:00 +02:00
b1yd
6f033416f3 remove unnecessary variables and delimiter check 2026-04-08 13:02:39 +02:00