2079 Commits

Author SHA1 Message Date
Guillaume Gomez
8408bca605
Rollup merge of #146094 - mohe2015:patch-2, r=lcnr
Make `Parser::parse_for_head` public for rustfmt usage

Similar to https://github.com/rust-lang/rust/pull/138511, I want to add [dioxus rsx](https://dioxuslabs.com/learn/0.6/reference/rsx) formatting to [my rustfmt fork](https://github.com/tucant/rustfmt) and it would be much easier if that method would be public. Thanks.
2025-09-02 17:08:57 +02:00
Guillaume Gomez
af315b0725
Rollup merge of #145783 - Erk-:et-cetera-span, r=compiler-errors
add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: https://github.com/rust-lang/rust-clippy/pull/15000#discussion_r2134145163

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
2025-09-02 17:08:52 +02:00
Moritz Hedtke
d8df6312d5 Make Parser::parse_for_head public for rustfmt usage 2025-09-01 17:30:47 +02:00
bors
64a99db105 Auto merge of #145582 - estebank:issue-107806, r=chenyukang
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-31 03:00:54 +00:00
Esteban Küber
3af81cf0b7 review comment: move Visitor 2025-08-30 18:42:07 +00:00
Jonathan Brouwer
f328709276
Improve error messages around invalid literals in attribute arguments
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-28 20:05:04 +02:00
Valdemar Erk
75d8687f2b add span to struct pattern rest (..) 2025-08-25 09:55:50 +02:00
Nicholas Nethercote
a06c3887bd Remove the lifetime from ExpTokenPair/SeqSep.
`TokenKind` now impls `Copy`, so we can store it directly rather than a
reference.
2025-08-25 08:02:52 +10:00
Jacob Pratt
2dbd411d22
Rollup merge of #144897 - fee1-dead-contrib:raw_lifetimes_printing, r=fmease
print raw lifetime idents with r#

This replaces rust-lang/rust#143185 and fixes rust-lang/rust#143150

cc ``@fmease``
2025-08-22 22:00:47 -04:00
Jacob Pratt
85c9af57f4
Rollup merge of #137396 - compiler-errors:param-default, r=fmease
Recover `param: Ty = EXPR`

Fixes #137310

Pretty basic recovery here, but better than giving an unexpected token error.
2025-08-22 22:00:44 -04:00
Michael Goulet
6caa586f57
Recover param: Ty = EXPR 2025-08-22 21:45:28 +02:00
Jonathan Brouwer
549314bdb7
Rewrite the new attribute parser 2025-08-22 08:38:37 +02:00
Jonathan Brouwer
21d3189779
Move validate_attr to rustc_attr_parsing 2025-08-22 08:37:19 +02:00
Deadbeef
4970127c33 address review comments 2025-08-22 13:16:44 +08:00
Deadbeef
30bb7045d6 don't print invalid labels with r# 2025-08-22 12:58:37 +08:00
Jacob Pratt
f49d69093e
Rollup merge of #145604 - compiler-errors:static-closure, r=fmease
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-21 17:57:52 -04:00
Jacob Pratt
25b81bf5ad
Rollup merge of #145590 - nnethercote:ModKind-Inline, r=petrochenkov
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-21 01:12:19 -04:00
Esteban Küber
d216ca0506 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 {
   |                         ++++
```
2025-08-20 18:26:04 +00:00
bors
bec747418c Auto merge of #145348 - nnethercote:parse_token_tree-speedup-for-uom, r=petrochenkov
Sometimes skip over tokens in `parse_token_tree`.

r? `@petrochenkov`
2025-08-20 09:01:41 +00:00
Michael Goulet
db0c825d2c Gate static coroutines behind a parser feature 2025-08-19 13:12:31 +00:00
Nicholas Nethercote
bfd5d59f97 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(_)`.
2025-08-19 21:57:31 +10:00
许杰友 Jieyou Xu (Joe)
b638266f23
Rollup merge of #145474 - fmease:paren-use-bounds-fix, r=fee1-dead
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-19 19:45:33 +08:00
León Orell Valerian Liehr
f8f7c27d4f
Clean up parsers related to generic bounds 2025-08-16 16:15:58 +02:00
León Orell Valerian Liehr
eb3e0d4c8a
Properly recover from parenthesized use-bounds (precise capturing) 2025-08-16 01:21:35 +02:00
Stuart Cook
dc047f1385
Rollup merge of #145378 - xizheyin:144968, r=davidtwco
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-15 16:16:41 +10:00
Jakub Beránek
01bd889098
Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxu
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-14 21:48:42 +02:00
Jakub Beránek
18afb69767
Rollup merge of #137872 - estebank:extra-vert, r=compiler-errors
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-14 21:48:41 +02:00
xizheyin
3ce555f631 Add FnContext in parser for diagnostic
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-14 21:31:47 +08:00
Nicholas Nethercote
145b84721a Sometimes skip over tokens in parse_token_tree.
This sometimes avoids a lot of `bump` calls.
2025-08-14 15:31:29 +10:00
Cameron Steffen
5bc23ce255 Extract ast TraitImplHeader 2025-08-11 17:05:36 -05:00
Cameron Steffen
3aa0ac0a8a Tweak trait modifier errors 2025-08-11 16:58:21 -05:00
Cameron Steffen
fa733909ed Move trait impl modifier errors to parsing
This is a technically a breaking change for what can be parsed in
`#[cfg(false)]`.
2025-08-11 16:58:21 -05:00
Josh Triplett
38df15805b cfg_select: Support unbraced expressions
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-10 16:18:01 -07:00
bors
41ede7bd9b Auto merge of #145146 - fee1-dead-contrib:push-zmqrkurlzrxy, r=nnethercote
remove `P`

Previous work: rust-lang/rust#141603
MCP: https://github.com/rust-lang/compiler-team/issues/878

cc `@nnethercote`
2025-08-09 23:27:55 +00:00
Deadbeef
ad1113f87e remove P 2025-08-09 15:47:01 +08:00
Michael Goulet
b2d524c43d Recover for PAT = EXPR {} 2025-08-08 18:46:09 +00:00
Guillaume Gomez
48d57564cf
Rollup merge of #144956 - fmease:gate-const-trait-syntax, r=BoxyUwU
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-06 21:29:30 +02:00
Guillaume Gomez
d180873be8
Rollup merge of #144195 - Kivooeo:bad-attr, r=fmease,compiler-errors
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-06 21:29:26 +02:00
León Orell Valerian Liehr
092c6f3a18
Gate const trait syntax 2025-08-05 14:52:02 +02:00
Kivooeo
d09cf616f7 Added checks for attribute in type case 2025-08-05 07:10:31 +05:00
Esteban Küber
2db126d651 Include whitespace in "remove |" suggestion and make it hidden 2025-08-04 18:06:18 +00:00
Michael Goulet
51cd9b564f Consider operator's span when computing binop expr span 2025-07-31 02:28:11 +00:00
Stuart Cook
b76cb79e79
Rollup merge of #144589 - compiler-errors:postfix-yield-after-cast, r=petrochenkov
Account for `.yield` in illegal postfix operator message

Fixes rust-lang/rust#144527
2025-07-29 23:50:37 +10:00
Scott Schafer
aa9767290e
feat: Right align line numbers 2025-07-28 16:32:11 -06:00
Michael Goulet
2db97b2f7d Account for .yield in illegal postfix operator message 2025-07-28 16:09:59 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Deadbeef
69326878ee parse const trait Trait 2025-07-17 18:06:26 +08:00
Samuel Tardieu
010e3ef113
Rollup merge of #143941 - folkertdev:cfg-select-docs, r=traviscross
update `cfg_select!` documentation

tracking issue: https://github.com/rust-lang/rust/issues/115585

After rust-lang/rust#143461, and with an eye on a soon(ish) stabilization, I think the docs need some work.

The existing text read more like a motivation for the feature existing to me, so I've tried to now be a bit more descriptive. Still, suggestions are very welcome.

I also added a test for an empty `select! {}` because it's just the sort of thing that might break.

r? ``@traviscross``
2025-07-15 12:52:44 +02:00
Samuel Tardieu
281990eb16
Rollup merge of #143905 - xizheyin:143828, r=compiler-errors
Recover and suggest to use `;` to construct array type

Fixes rust-lang/rust#143828

r? compiler
2025-07-15 12:52:40 +02:00
xizheyin
ed88af2163
Recover and suggest use ; to construct array type
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-15 12:00:46 +08:00