2596 Commits

Author SHA1 Message Date
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
d3c9908a8a
Rollup merge of #145747 - joshtriplett:builtin-diag-dyn, r=jdonszelmann
Refactor lint buffering to avoid requiring a giant enum

Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it.

Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate.

Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly.

Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.

---

With the infrastructure in place, use it to migrate three of the enum variants to use `LintDiagnostic` directly, as a proof of concept and to demonstrate that the net result is a reduction in code size and a removal of a boilerplate-heavy layer of indirection.

Also remove an unused `BuiltinLintDiag` variant.
2025-08-22 22:00:59 -04: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
Josh Triplett
52fadd8f96 Migrate BuiltinLintDiag::HiddenUnicodeCodepoints to use LintDiagnostic directly 2025-08-22 03:01:35 -07: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
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
bors
f605b57042 Auto merge of #145601 - jieyouxu:rollup-t5mbqhc, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#145538 (bufreader::Buffer::backshift: don't move the uninit bytes)
 - rust-lang/rust#145542 (triagebot: Don't warn no-mentions on subtree updates)
 - rust-lang/rust#145549 (Update rust maintainers in openharmony.md)
 - rust-lang/rust#145550 (Avoid using `()` in `derive(From)` output.)
 - rust-lang/rust#145556 (Allow stability attributes on extern crates)
 - rust-lang/rust#145560 (Remove unused `PartialOrd`/`Ord` from bootstrap)
 - rust-lang/rust#145568 (ignore frontmatters in `TokenStream::new`)
 - rust-lang/rust#145571 (remove myself from some adhoc-groups and pings)
 - rust-lang/rust#145576 (Add change tracker entry for `--timings`)
 - rust-lang/rust#145578 (Add VEXos "linked files" support to `armv7a-vex-v5`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-19 23:52:06 +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
Deadbeef
c335d5781d ignore frontmatters in TokenStream::new 2025-08-18 20:28:29 +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
Stuart Cook
d862ae2fce
Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmann
Tweak invalid builtin attribute output

 - Add link to reference/docs when possible
 - More accurate suggestions by supporting multiple alternative suggestions

```
error: malformed `crate_type` attribute input
  --> $DIR/crate-type-macro-call.rs:1:1
   |
LL | #![crate_type = foo!()]
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
   |
   = and 4 other candidates
```
2025-08-12 20:37:53 +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
Esteban Küber
625143bac3 Add link to docs on malformed attributes 2025-08-11 16:00:49 +00:00
Esteban Küber
189f264926 Allow attr entries to declare list of alternatives for List and NamedValueStr
Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles.

Suggestions now provide more correct suggested code:

```
error[E0805]: malformed `used` attribute input
  --> $DIR/used_with_multi_args.rs:3:1
   |
LL | #[used(compiler, linker)]
   | ^^^^^^------------------^
   |       |
   |       expected a single argument here
   |
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[used(compiler, linker)]
LL + #[used(compiler)]
   |
LL - #[used(compiler, linker)]
LL + #[used(linker)]
   |
LL - #[used(compiler, linker)]
LL + #[used]
   |
```

instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists:

```
error[E0805]: malformed `used` attribute input
  --> $DIR/used_with_multi_args.rs:3:1
   |
LL | #[used(compiler, linker)]
   | ^^^^^^------------------^
   |       |
   |       expected a single argument here
   |
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[used(compiler, linker)]
LL + #[used(compiler|linker)]
   |
LL - #[used(compiler, linker)]
LL + #[used]
   |
```
2025-08-11 16:00:49 +00: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
Jana Dönszelmann
5712d50648
Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease
Deduplicate `IntTy`/`UintTy`/`FloatTy`.

There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.

r? `@fmease`
2025-07-31 17:19:39 +02:00
Nicholas Nethercote
704f2ca172 Tidy up Cargo.toml files.
- Add some missing `tidy-alphabetical-*` markers.
- Remove some unnecessary blank lines.
2025-07-31 19:58:04 +10: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
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Jonathan Brouwer
a2b3d81034
Call is_parsed_attribute rather than keeping track of a list of parsed attributes manually 2025-07-24 22:53:09 +02:00
León Orell Valerian Liehr
6dc41520e9
Rollup merge of #144358 - JonathanBrouwer:fix-stability-malformed, r=oli-obk
Stop using the old `validate_attr` logic for stability attributes

I think this was accidentally missed when implementing the stability attributes?

r? `````@oli-obk`````
cc `````@jdonszelmann`````
2025-07-24 15:08:28 +02:00